thymeleaf 您所在的位置:网站首页 java前端页面模板 thymeleaf

thymeleaf

#thymeleaf| 来源: 网络整理| 查看: 265

thymeleaf - java web页面模板引擎介绍(下篇)阿凡达2018-07-20 14:08修改

--thymeleaf提交form表单

    Getting Started: Handling Form Submission            Form    Id:     Message:       @PostMapping("/greeting") public String greetingSubmit(@ModelAttribute Greeting greeting) { return "result"; } thymeleaf对form表单做了很好的支持,GreetingController方法中的post参数为Greeting对象,form中action=“#”表示为根路径, th:action="@{/greeting}"代表post请求的地址, th:object="${greeting}"为定义的一个对象值,method=“post”指定为post协议。form表单中的 th:field="*{id}"或 th:text="*{id}"方法表示引用对象的值。这样就完成了一个form表单的提交。 --thymeleaf for循环遍历list集合 上面例子中Attribute中返回allDbsource对应的为一个List数组,前端遍历对象并显示在select框中。首先使用th:each="dbsource,dbsourceStat : allDbsource"语法获取到allDbsource数组并定义取到的数组中单个对象为dbsource名,后面th:text="{dbsource.name}+ dbsource.ip+′:′+{dbsource.port}"则引用单个对象中的属性并赋值为text属性,这样展示的结果便为: 对于thymeleaf的标签使用可以在网上找到中文api做参照联系。最后再介绍一个比较常用的场景thymeleaf的分页查询的实现。 四、thymeleaf、 pagehelper与mybatis实现分页查询功能 1、首先需要pom引入pagehelper的依赖             com.github.pagehelper            pagehelper            5.1.2                                    tk.mybatis            mapper            3.3.9        2、控制器实现pageInfo构造,需要返回pageInfo对象。对象默认配置可以更改 @GetMapping("/showAllDb") public String showParams(Model model,@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "5")Integer pageSize) { PageInfo pageInfo = mserverDbserverService.findAll(pageNum, pageSize); //获得当前页 model.addAttribute("pageNum", pageInfo.getPageNum()); //获得一页显示的条数 model.addAttribute("pageSize", pageInfo.getPageSize()); //是否是第一页 model.addAttribute("isFirstPage", pageInfo.isIsFirstPage()); //获得总页数 model.addAttribute("totalPages", pageInfo.getPages()); //是否是最后一页 model.addAttribute("isLastPage", pageInfo.isIsLastPage()); model.addAttribute("mserverDbserverList", pageInfo.getList()); return "dbshow"; }3、html支持分页功能, th:href="@{${'/showAllDb'}为数据源的请求url,这样即实现了显示共多少页数据,以及点击展示确定页数的数据功能。 « Previous Previous Next Next »

相关阅读:thymeleaf - java web页面模板引擎介绍(上篇)

本文来自网易实践者社区,经作者王海鹏授权发布。

分享至:



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有