spring boot 整合thyemleaf基本使用 條件判斷(四)
阿新 • • 發佈:2018-11-11
thyemleaf基本使用 條件判斷 <!--用if來判斷--> <span th:if="${sex}=='男'"> 性別:男 </span> <span th:if="${sex}=='女'"> 性別:女 </span> <!--用switch來判斷--> <div th:switch="${id}"> <span th:case="1">ID為1</span> <span th:case="2">ID為2</span> <span th:case="3">ID為3</span> </div> 看html網頁裡面的語法: <!DOCTYPE html> <html lang="en" xmlns:th="http://www.w3.org/1999/xhtml"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <!--用if來判斷--> <span th:if="${sex}=='男'"> 性別:男 </span> <span th:if="${sex}=='女'"> 性別:女 </span> <!--用switch來判斷--> <div th:switch="${id}"> <span th:case="1">ID為1</span> <span th:case="2">ID為2</span> <span th:case="3">ID為3</span> </div> </body> </html>
再看Controller
@RequestMapping("show2") public String showInfo2(Model model){ model.addAttribute("sex","女"); model.addAttribute("id","2"); return "index2"; }