spring boot 1.4.2.RELEASE+Thymeleaf+mybatis 集成通用maper,与分页插件:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.2.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<java.version>1.8</java.version>
<!-- 依赖版本 -->
<mybatis.version>3.4.0</mybatis.version>
<mybatis.spring.version>1.3.0</mybatis.spring.version>
<mapper.version>3.3.9</mapper.version>
<pagehelper.version>4.1.6</pagehelper.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-joda</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-parameter-names</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.0.11</version>
</dependency>
<!--Mybatis -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>${mybatis.version}</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>${mybatis.spring.version}</version>
</dependency>
<!-- Mybatis Generator -->
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.2</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<!--分页插件 -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>${pagehelper.version}</version>
</dependency>
<!--通用Mapper -->
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper</artifactId>
<version>${mapper.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>springloaded</artifactId>
<version>1.2.5.RELEASE</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
UserPojo
@Table(name="user")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String username;
private Date birthday;
private String email;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public Date getBirthday() {
return birthday;
}
public void setBirthday(Date birthday) {
this.birthday = birthday;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
UserService
@Service
@Transactional
public class UserService {
@Autowired
private UserMapper userMapper;
@Transactional(readOnly = true)
public PageInfo<User> findAll(String username, Date birthday, Integer page, Integer pageSize) {
PageHelper.startPage(page, pageSize);
Example example = new Example(User.class);
if (!StringUtils.isEmpty(username)) {
example.createCriteria().andEqualTo("username", username);
}
if (birthday != null) {
example.createCriteria().andEqualTo("birthday", birthday);
}
List<User> users = userMapper.selectByExample(example);
return new PageInfo<>(users);
}
}
UserController
@Controller
public class UserController {
@Autowired
private UserService userService;
@RequestMapping("/user")
public String index(Model model, @RequestParam(required = false) String username,@RequestParam(required = false) Date birthday, @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "3") Integer pageSize) {
PageInfo<User> pageInfo = userService.findAll(username, birthday, 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("users", pageInfo.getList());
return "index";
}
}
前台模板页
<table class="table table-hover" style="border-collapse: 0"
width="50%">
<thead>
<tr>
<th>id</th>
<th>username</th>
<th>birthday</th>
<th>email</th>
</tr>
</thead>
<tr th:each="user : ${users}">
<th th:text="${user.id}"></th>
<th th:text="${user.username}"></th>
<th th:text="${#dates.format(user.birthday, 'yyyy-MM-dd')}"></th>
<th th:text="${user.email}"></th>
</tr>
</table>
<nav>
<ul class="pagination">
<li><a href="">«</a></li>
<li>
<a th:if="${not isFirstPage}" th:href="@{${'/user'}(pageNum=${pageNum-1},pageSize=${pageSize})}">Previous</a>
<a th:if="${isFirstPagee}" href="javascript:void(0);">Previous</a>
</li>
<li th:each="pageNo : ${#numbers.sequence(1, totalPages)}">
<a th:if="${pageNum eq pageNo}" href="javascript:void(0);">
<span th:text="${pageNo}"></span>
</a>
<a th:if="${not (pageNum eq pageNo)}" th:href="@{${'/user'}(pageNum=${pageNo},size=${pageSize})}">
<span th:text="${pageNo}"></span>
</a>
</li>
<li>
<a th:if="${not isLastPage}" th:href="@{${'/user'}(pageNum=${pageNum+1},size=${pageSize})}">Next</a>
<a th:if="${isLastPage}" href="javascript:void(0);">Next</a>
</li>
<li><a href="#">»</a></li>
</ul>
</nav>
转自:http://blog.csdn.net/gdhuyufei/article/details/53712805
spring boot 1.4.2.RELEASE+Thymeleaf+mybatis 集成通用maper,与分页插件:的更多相关文章
- Spring Boot学习笔记(二二) - 与Mybatis集成
Mybatis集成 Spring Boot中的JPA部分默认是使用的hibernate,而如果想使用Mybatis的话就需要自己做一些配置.使用方式有两种,第一种是Mybatis官方提供的 mybat ...
- spring boot +Thymeleaf+mybatis 集成通用PageHelper,做分页
controller: /** * 分页查询用户 * @param request * @param response * @return * @throws Exception */ @ ...
- spring cloud: 升级到spring boot 2.x/Finchley.RELEASE遇到的坑
spring boot2.x已经出来好一阵了,而且spring cloud 的最新Release版本Finchley.RELEASE,默认集成的就是spring boot 2.x,这几天将一个旧项目尝 ...
- Java Spring Boot VS .NetCore (五)MyBatis vs EFCore
Java Spring Boot VS .NetCore (一)来一个简单的 Hello World Java Spring Boot VS .NetCore (二)实现一个过滤器Filter Jav ...
- Spring Boot 2.2.2.RELEASE 版本中文参考文档【3.2 - 3.10】
Spring Boot 2.2.2.RELEASE版本中文文档持续更新中~如有需要获取参考文档文件,关注公众号JavaSo,回复“参考文档”即可. 3.2 结构化代码 Spring Boot不需要任何 ...
- 001-Spring Cloud Edgware.SR3 升级最新 Finchley.SR1,spring boot 1.5.9.RELEASE 升级2.0.4.RELEASE注意问题点
一.前提 升级前 => 升级后 Spring Boot 1.5.x => Spring Boot 2.0.4.RELEASE Spring Cloud Edgware SR3 => ...
- 解决Spring Boot(2.1.3.RELEASE)整合spring-data-elasticsearch3.1.5.RELEASE报NoNodeAvailableException[None of the configured nodes are available
Spring Boot(2.1.3.RELEASE)整合spring-data-elasticsearch3.1.5.RELEASE报NoNodeAvailableException[None of ...
- Spring Boot 2.2.2.RELEASE 版本中文参考文档【3.1】
使用Spring Boot 本节将详细介绍如何使用Spring Boot.它涵盖了诸如构建系统,自动配置以及如何运行应用程序之类的主题.我们还将介绍一些Spring Boot最佳实践.尽管Spring ...
- Spring Boot 2.2.2.RELEASE 版本中文参考文档
写在前面 在我初次接触MongoDB的时候,是为了做一个监控系统和日志分析系统.当时在用Java操作MongoDB数据里的数据的时候,都是在网上查找Demo示例然后完成的功能,相信大家也同样的体会,网 ...
随机推荐
- 12-01Js对象##正则表达式##
正则表达式:是一个字符一个字符的验证,通过量词验证字符串: 1.什么是RegExp?RegExp是正则表达式的缩写.RegExp 对象用于规定在文本中检索的内容. 2.定义RegExp:var +变量 ...
- 推荐一款GIF录制工具
LICEcap 是一款屏幕录制工具,支持导出 GIF 动画图片格式,轻量级.使用简单,录制过程中可以随意改变录屏范围 下载 http://www.cockos.com/licecap/
- C语言学习笔记--函数
1. C 语言中的函数 (1)函数的由来: 程序 = 数据 + 算法→C 程序 = 数据 + 函数 (2)模块化程序设计 (3)C 语言中的模块 2. 面向过程的程序设计 (1)面向过程是一种以过程为 ...
- c#.net常用字符串函数 字符串常用方法 string
RegionsStr = RegionsStr.Remove(RegionsStr.LastIndexOf(","), 1); //去掉最后一个逗号 string html = ...
- TCP/IP 笔记 6 netstat -s 命令查看每个协议统计数据
netstat -s 命令,查看每个协议统计数据的常用方法 lenovo-myc@lenovomyc-Lenovo-Product:~$ netstat -s Ip: total packets re ...
- Python单例模式剖析
在聊这之前我们首先要明确的是,单例模式在实际中的意义以及在python中具有实现的价值? 当前,相信有很多人支持单例模式,也有不少人反对,尤其是在python中,目前依旧具有很大的争议性.我们要在评论 ...
- sharepoint 2013创建网站集,域帐户无法访问,只有administrator可以访问
解决方法: 1.创建WEB应用程序时,可配置帐户必须为域帐户 2.确定关闭防火墙(这是重点) 我在测试时发现80端口和30714端口在其它同事的电脑上(域帐户)都可以访问,除这两个端口以后都无法访问, ...
- SVN资源库报错:Could not create the view: org.tigris.subversion.subclipse.ui.repository.RepositoriesView
解决方法: 关闭正在运行的myeclipse,然后打开myeclipse安装路径(我的安装在c盘): c:\ProgramFiles\MyEclipse\MyEclipse Professional ...
- opencv 基本数据结构
转自:http://www.cnblogs.com/guoqiaojin/p/3176692.html opencv 基本数据结构 DataType : 将C++数据类型转换为对应的opencv数 ...
- 高性能MySQL笔记-第5章Indexing for High Performance-001B-Tree indexes(B+Tree)
一. 1.什么是B-Tree indexes? The general idea of a B-Tree is that all the values are stored in order, and ...