springboot+thymeleaf+mybatis-plus完整项目模型练习

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页面跳转

最近使用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>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值