弹窗以及图片显示:
<script type="text/javascript" th:src="@{js/jquery.js}"></script>
<script type="text/javascript">
$(function (){
alert("要进入吗?");
})
</script>
<body>
对了hhh
<img alt="" th:src="@{img/abc.png}" width="400" height="400">
</body>
<script type="text/javascript">
/*内置对象*/
</script>
<body>
**********<input type="text" name="da" th:value="${emp.name}"/>*************
<p th:text="${wel}"></p>
******************************************************<br/>
<div>
<span th:text="${emp.id}"></span> <span th:text="${emp.name}"></span><br/>
<span th:text="${emp.address}"></span> <span th:text="${emp.salary}"></span><br/>
</div>
******************************************************<br/>
<span th:text="'welcome to'+${emp.name}+'!!!'"></span>
<span th:text="|welcome to ${emp.name}|+'@@@'"></span><br/>
******************************************************<br/>
数字:<span th:text="${emp.id *3}"></span><br/>
******************************************************<br/>
<p th:text="${emp.name}" th:if="${emp.id>20}"></p>
<p th:if="${emp.id<=20}"> welcome to zhongshan</p>
******************************************************<br/>
<p th:text="${emp.name}" th:if="${emp.id>20}"></p>
<p th:unless="${emp.id>20}"> welcome to zhongshan</p>
******************************************************<br/>
<p th:text="${emp.name}" th:if="${username!=null}"></p>
<p th:unless="${username!=null}"> welcome to zhongshan</p>
******************************************************<br/>
******************************************************<br/>
员工名字长度:<span th:text="${#strings.length(emp.name)}"></span>
员工薪资:<span th:text="${#numbers.formatDecimal(emp.salary,0,2)}"></span>
</body>
@RequestMapping("/show")
public String test01(){
//转发到show.html
return "show";
}
@Autowired
EmpService empService;
@RequestMapping("/findOne")
//如:http://localhost:8080/find?id=41
public String selectEmpById(int id, Model model) {
Emp emp= empService.findEmpById(id);
model.addAttribute("emp",emp);
model.addAttribute("wel","welcome to baijin");
model.addAttribute("username","null");
return "show";
}
显示列表:
@RequestMapping("/findAll")
public String findAll(Model model){
List<Emp2> emps= empService.findAll();
model.addAttribute("emps",emps);
return "list";
}
@RequestMapping("/del")
public String deleteEmpById(int id) {
empService.deleteEmpById(id);
return "forward:/findAll";
}
<body>
<table border=1>
<tr>
<td>序号</td><td>姓名</td><td>地址</td><td>工资</td><td>操作</td>
</tr>
<tr th:each="emp,stat:${emps}">
<td th:text="${stat.count}"></td><td th:text="${emp.name}"></td><td th:text="${emp.address}"></td><td th:text="${emp.money}"></td>
<td><a th:href="@{/del(id=${emp.id})}">删除</a></td>
</tr>
</table>
</body>
角色展示:
@RequestMapping("/role/{role}")
public String getRole(@PathVariable("role") String role, HttpServletRequest request){
request.setAttribute("role",role);
return "role";
}
<body>
******************************************************<br/>
<div th:switch="${role}">
<p th:case="aa">管理员</p>
<p th:case="bb">教师</p>
<p th:case="cc">学生</p>
<p th:case="*">游客</p>
</div>
</body>