• thymeleaf的日常使用


    th:each

     <tr th:each="shop,shopstat :${myShop}">
            <td th:text="${shop.bookvo.bname}">td>
            <td th:text="${shop.bookvo.bprice}">价格td>
            <td >
                <form action="addShop" method="post">
                    <input type="hidden" name="sid" th:value="${shop.sid}">
                    购买数量:<input type="button" value="-">
                    <input type="text"  th:value="${shop.snum}" th:id="'snum'+${shopstat.index}">
                    <input type="button" value="+" onclick="add()">  <br/>
                form>
            td>
        tr>
    
    ${shopstat.odd}
    ${shopstat.even}
    ${shopstat.last}
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    <select name="btid">
        <option th:each="d :${allType}" th:text="${d.tname}" th:value="${d.tid}">option>
    select>
    
    • 1
    • 2
    • 3

    th:href

    
     @RequestMapping("del")
        public String add1(int uid,String uname){
            System.out.println(uid+"..."+uname);
            return "index";
        }
    
        @RequestMapping("del1/{uid}")
        public String add11(@PathVariable("uid") int uid){
            System.out.println("del1...."+uid);
            return "redirect:../index2";
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    <a th:href="@{/byidBook(bid=${book.bid})}" th:text="${book.bname}">a>
    
    • 1
     <a th:href="@{del(uid=${item.did},uname='zhang')}">删除a>
     <a th:href="${'/del1/'+ item.did}">删除1a>
    
    • 1
    • 2

    th:src

    <img th:src="@{'imgs/'+${book.bimg}}" width="20" height="20"/>
    
    • 1

    th:object

    model.addAttribute("dept",new Dept(11,"呵呵呵",true,new Date()));
    
    
    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public class Dept {
        private int did;
        private String dname;
        private boolean gender;
        @DateTimeFormat(pattern = "yyyy-MM-dd")
        private Date birth;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    <form action="add" method="post" th:object="${dept}">
        id:<input type="text" name="did" th:value="*{did}"/> <br/>
        姓名:<input type="text" name="dname" th:value="*{dname}"/><br/>
        性别:<input type="radio" name="gender" th:value="*{gender}" th:checked="*{gender}"/><input type="radio" name="gender" th:value="*{gender}" th:checked="*{not gender}"/><br/>
        出生年月日:<input type="date" name="birth" th:value="*{#dates.format(birth,'yyyy-MM-dd')}" /><br/>
    
        <input type="submit" value="提交">
    form>
    
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    session的使用

     @RequestMapping("loginui")
        public String loginui(){
            return "login";
        }
    
        @RequestMapping("loginout")
        public String loginout(HttpSession session){
            session.removeAttribute("loginemp");
            return "login";
        }
    
        @RequestMapping("login")
        public String xx(String uname,String upwd,HttpSession session){
            if(uname.equals("admin")&& upwd.equals("123")){
                User user = new User(uname,upwd);
                session.setAttribute("loginemp",user);
                return "redirect:index2";
            }else{
                return "login";
            }
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    <a href="loginui" th:if="${session.loginemp==null}">登录a>
      <div th:unless="${session.loginemp==null}">
          用户名:<span th:text="${session.loginemp.uname}">span>
          <a href="loginout" > 注销登录a>
      div>
    
    • 1
    • 2
    • 3
    • 4
    • 5

    th:if

     <p th:if="${dept.did>=12}">符合p>
       <p th:unless="${dept.did>=12}">不符合p>
    
    • 1
    • 2
  • 相关阅读:
    能涨薪3k的jmeter接口测试 接口自动化测试全套教程
    NUWA论文阅读
    MySQL高级——引擎
    基于大数据的高校生源可视化分析系统
    【Leetcode Sheet】Weekly Practice 15
    DPU — 功能特性 — 安全系统的硬件卸载
    从案例中详解go-errgroup-源码
    Linux操作系统 - 从概念上认识进程
    自动驾驶学习笔记(十)——Cyber通信
    用爬虫保存文章到TXT文件丨Python爬虫实战系列(7)
  • 原文地址:https://blog.csdn.net/zhangting123123/article/details/133783265