SpringBoot+Mybatis+thymeleaf实现增删改查
一.今天用SpringBoot整合thymeleaf做一套增删改查
1.导入依赖
<dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>2.1.4</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-thymeleaf</artifactId></dependency><!-- springboot分页插件 --><dependency><groupId>com.github.pagehelper</groupId><artifactId>pagehelper-spring-boot-starter</artifactId><version>1.2.5</version></dependency>
导入Mybatis,Thymeleaf依赖,分页插件
二:声明thymeleaf名称空间
<html lang="en" xmlns:th="http://www.thymeleaf.org">
在使用 Thymeleaf 之前,首先要在页面的 html 标签中声明名称空间,示例代码如上。
三.配置Springboot配置文件
spring:thymeleaf:cache: falsesuffix=: .htmlprefix: classpath:/templates/datasource:url: jdbc:mysql://localhost:3306/mybaby?serverTimezone=GMT-8driver-class-name: com.mysql.cj.jdbc.Driverusername: rootpassword: root
mybatis:mapper-locations: classpath:/mapper/*.xml
pagehelper:helperDialect: mysqlreasonable: truesupportMethodsArguments: falseparams: count=countSql
同时配置Mybatis数据源
四.编写实体类pagebean
public class pagebean {private int totalCount; //总条数private int totalPage;//总页数 总条数/每页条数private int sizePage=5;//每页显示数 默认private int pageCode;//第几页 默认private List rows;//查询返回的结果集
}
pagebean对分页信息进行封装
五.Controller实现对数据的展示
//分页查询方法@RequestMapping("/pageInfo")public String getPageInfo(Integer pageCode,Integer sizePage,@RequestParam(defaultValue = "") String name,@RequestParam(defaultValue = "0") Integer id,Model model){List<Clubs> type = clubsService.getType();model.addAttribute("type",type);pagebean info = playerService.getPageInfo(pageCode, sizePage, name, id);model.addAttribute("page",info);model.addAttribute("name",name);model.addAttribute("id",id);return "one";}
六.用Thymeleaf对数据进行便利展示
<table class="table table-hover table-bordered table-striped" style="overflow: auto;"><tr><th>#</th><th width="7%">球员编号</th><th width="10%">球员名称</th><th width="20%">出生日期</th><th width="10%">升高</th><th width="10%">体重</th><th width="15%">球员位置</th><th width="10%">所属球队</th><th width="10%">操作</th></tr><th:block><tr th:each="a:${page.rows}" style="height:70px"><th></th><th th:text="${a.pid}"></th><th th:text="${a.pname}"></th><th th:text="${a.birthday}"></th><th th:text="${a.height}"></th><th th:text="${a.weight}"></th><th th:text="${a.position}"></th><th th:text="${a.cname}"></th><th><button class="btn btn-primary"><span class="glyphicon glyphicon-pencil btn-sm" aria-hidden="true"></span><a class="active" style="color: black" href="/play/del/${a.pid}">删除</a></button></th></tr></th:block></table>
SpringBoot+Mybatis+thymeleaf实现增删改查相关推荐
- SpringBoot + MyBatis + MySQL +IDEA2021 增删改查 2021-06-04
SpringBoot + MyBatis + MySQL +IDEA2021 增删改查 1.环境介绍 Windows 10 JDK 1.8 MySQL 8 IDEA 2021.1.2 2.开始操作.新 ...
- SpringBoot+MyBatisPlus+Thymeleaf+AdminLTE增删改查实战
说明 AdminLTE是网络上比较流行的一款Bootstrap模板,包含丰富的样式.组件和插件,非常适用于后端开发人员做后台管理系统. 因为最近又做了个后台管理系统,这次就选的是AdminLTE做主题 ...
- springboot+mybatis+mysql(增删改查xml入门编程)
jdk1.8 idea 2017.2.6 springboot 2.x 项目搭建省略,直接上代码: 项目结构: application.properties配置 server.port=8086#加载 ...
- neo4j图数据库安装(mac)+neo4j集成springboot实现基础的增删改查
目录 第一部分 mac安装neo4j 第二部分 neo4j集成springboot实现基础的增删改查 一.图数据库相关配置 二.业务逻辑 实体类 持久层 业务层 表现层 启动类 三.测试 附录: 第一 ...
- Mybatis基础:增删改查、模糊查询、多条件查询
Mybatis基础:增删改查.模糊查询.多条件查询http://www.bieryun.com/3132.html 1.新建测试数据库,根据实体类属性创建 2.实体类 [java] view plai ...
- SpringBoot操作MongoDB实现增删改查
本篇博客主讲如何使用SpringBoot操作MongoDB. SpringBoot操作MongoDB实现增删改查 (1)pom.xml引入依赖 <dependency> <group ...
- springboot对于redis的增删改查
springboot对于redis的增删改查 1.下载redis,安装之后,打开redis服务器.不过有绿色版的,直接打开redis服务器可执行文件,启动redis服务器. 2.在pom.xml配置文 ...
- myBatis 简单的增删改查
myBatis 简单的增删改查 前面已经讲到用接口的方式编程.这种方式,要注意的一个地方就是.在User.xml 的配置文件中, mapper namespace="com.fjh.inte ...
- springBoot加layui和mybatis后台管理系统增删改查分页登录注销修改密码功能
超市订单管理系统 1 登录页面 1.1 登录 点击提交按钮提交form表单使用post请求把(String name, String password)数据传到后台loginController 路径 ...
最新文章
- 扁平化职能管理三部曲
- android 设置textview中划线效果
- iOS架构-cocoaPods之自制私有库及管理(17)
- 【源码品读】深入了解FeignContract协议解析过程
- P4770-[NOI2018]你的名字【SAM,线段树合并】
- HTML文件属于void值吗,使用HTML :: TreeBuilder查找html文件中的值
- Cent OS home下中文目录改成英文目录
- poj3276(Face The Right Way)反转(开关问题)
- 通用版工业制程SPC管理系统,源代码分享
- 开发S2B2C商城系统需要多少钱
- 维普c语言代码查重原理,维普查重太假了?面对变态查重方式,如何修正才能通过考核?...
- REST Assured——断言实现
- 自制Alfred/Wox插件推荐
- java制作小鱼吃大鱼_大鱼吃小鱼游戏(Java编写)
- 大家好,我是数学家!来抢诺贝尔奖了!
- 用计算机绘制函数图像数学大师,什么手机app可以画函数图像 能画函数图像的app推荐...
- 可以真正实现免驱的WinUSB设备
- [YOLOv7/YOLOv5系列算法改进NO.20]Involution新神经网络算子引入网络
- Echarts英文版地图——强大的高德地图
- 软考A计划-试题模拟含答案解析-卷十七
热门文章
- 优漫动游初学者如何学习UI设计?
- 2021多校补题(10)
- 大家一起来讨论:Filecoin 经济模型和商业启示
- 戴森在中国独家发售红金限量版吹风机;今年底5G将覆盖全球超10亿人口 | 美通企业日报...
- 史上最简单OpenWRT教程!三分钟三步搞定!碉堡了
- docker-compose 配置 容器 访问本地网络
- js 倒计时 php,JS如何实现分钟倒计时(十分钟倒计时实例)
- html5 文字滑动特效代码,三种网页状态栏文字滚动特效代码
- MySQL高可用和读写分离
- 【CTO讲堂】互动,让直播更有价值