springboot+thymeleaf+mybatis-plus完整项目模型练习
[thymeleaf如何实现前后端数据交换](https://www.yisu.com/zixun/723498.html)
1.环境准备
1.1 参考博客
配置thymeleaf热部署
在springboot中使用thymeleaf循环(list,array,map)
Mybatis-Plus配置自动更新时间使用Mybatis-plus实现自动填充创建时间、更新时间
虽然使用并不完美,只有插入的时候可以,更新时间没有自动填充,需要改进,初步怀疑是mp版本适配问题。
thymeleaf如何实现前后端数据交换
SpringBoot+MyBatisPlus操作Oracle数据库
thymeleaf+element+vue
MyBatis-Plus 多表查询
Java Springboot学习(三) Thymeleaf 、mybatis-plus
最近使用SpringBoot整合thymeleaf,写了一个小demo,说起来,真的很坑,好多thymeleaf的标签属性必须要用th:打头,而且使用方法还比较繁琐,下面就是我总结我采坑的一些不太蝉蛹的thymeleaf属性
th:id="${goods.id}"给id赋值
th:each="goods,goodsStat:${pageInfo.records}"遍历
th:οnclick="|edit(${goods.id})|"函数传参
th:href="@{’/goods/pagelist/’+${pageInfo.current+1}+’/10’}"超链接
th:value="${#dates.format(goods.exDate, ‘yyyy-MM-dd’)}"日期转换、给value赋值
注意!! th:xxx 这个只能作为属性,不能作为标签使用!!
<div class="block">
<span class="demonstration">带快捷选项</span>
<el-date-picker
v-model="value2"
name="datePicker"
align="right"
type="date"
placeholder="选择日期"
:picker-options="pickerOptions">
</el-date-picker>
</div>
用name属性写在组件标签里,用表单来传值到后端。
配置Spring-Boot整合MyBatis plus并且连接Oracle数据库
后端传来的是Date数据,thymeleaf格式化时间
<td th:text="${#dates.format(hero.joinTime,'yyyy-MM-dd')}"></td>
package com.nndx.its.config;
import com.github.pagehelper.PageHelper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.Properties;
//配置PageHelper
@Configuration
public class PageHelperConfig {
@Bean
public PageHelper pageHelper(){
PageHelper pageHelper = new PageHelper();
Properties properties = new Properties();
properties.setProperty("offsetAsPageNum","true"); //会将 RowBounds 中的 offset 参数当成 pageNum 使用,可以用页码和页面大小两个参数进行分页。
properties.setProperty("rowBoundsWithCount","true"); //使用 RowBounds 分页会进行 count 查询。
properties.setProperty("reasonable","true"); //配置分页的合理化数据 true表示 pageNum<=0 时会查询第一页, pageNum>pages (超过总数时),会查询最后一页。
properties.setProperty("dialect","mysql"); //配置数据库方言为mysql
pageHelper.setProperties(properties);
return pageHelper;
}
}
<table class="table">
<thead>
<tr>
<th>序号</th>
<th>用户名</th>
<th>年龄</th>
<th>邮箱</th>
<th>创建时间</th>
</tr>
</thead>
<tbody>
<tr th:each="user,infoStat : ${pageInfo.list}">
<th th:text="${infoStat.count}"></th>
<td th:text="${user.name}"></td>
<td th:text="${user.age}"></td>
<td th:text="${user.email}"></td>
<!-- <td th:text="${user.createTime}"></td> -->
<td th:text="${#dates.format(user.createTime,'yyyy-MM-dd HH:mm:ss')}"></td>
</tr>
</tbody>
<tfoot>
<tr>
<th colspan="6" >
<div class="">
<a th:href="@{/pageindex/(pn=${pageInfo.list.pageNum}-1)}" class=" item" th:unless="${pageInfo.list.pageNum == 1}">上一页</a>
<a th:href="@{/pageindex/(pn=${pageInfo.list.pageNum}+1)}" class=" item" th:unless="${pageInfo.list.pageNum == pageInfo.list.pages}">下一页</a>
</div>
</th>
</tr>
</tfoot>
</table>
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)