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}
<select name="btid">
    <option th:each="d :${allType}" th:text="${d.tname}" th:value="${d.tid}">option>
select>

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";
    }
<a th:href="@{/byidBook(bid=${book.bid})}" th:text="${book.bname}">a>
 <a th:href="@{del(uid=${item.did},uname='zhang')}">删除a>
 <a th:href="${'/del1/'+ item.did}">删除1a>

th:src

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

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;
}
<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>


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";
        }
    }
<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>

th:if

 <p th:if="${dept.did>=12}">符合p>
   <p th:unless="${dept.did>=12}">不符合p>

你可能感兴趣的:(前端,开发语言)