Thymeleaf的应用

弹窗以及图片显示: 

<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>&nbsp;&nbsp;<span th:text="${emp.name}"></span><br/>
    <span th:text="${emp.address}"></span>&nbsp;&nbsp;<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>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值