Spring boot 配置 mybatis xml和动态SQL 分页配置
更新时间 2018年4月30日23:27:07
1.pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.imooc</groupId>
<artifactId>sell</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>sell</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.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-test</artifactId>
<scope>test</scope>
</dependency>
<!-- mybatis配置 -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2</version>
</dependency>
<!--数据库链接-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!--热启动-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<!--分页-->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.5</version>
<exclusions>
<exclusion>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<!-- 热部署 -->
<configuration>
<fork>true</fork>
</configuration>
</plugin>
</plugins>
</build>
</project>
2.配置 application.yml
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
username: root
password: 123456
url: jdbc:mysql://127.0.0.1/tpshop2.5.0?characterEncoding=utf-8&useSSL=false
jpa:
show-sql: true
mybatis:
config-locations: classpath:mybatis/mybatis-config.xml
mapper-locations: classpath:mapper/*.xml
configuration:
call-setters-on-nulls: true
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
pagehelper:
helperDialect: mysql
reasonable: true
supportMethodsArguments: true
params: count=countSql
3.配置Application.java 启动
@SpringBootApplication
@MapperScan("com.smartom.dao") //扫描dao层
public class MyApp {
public static void main(String[] args) throws Exception{
SpringApplication.run(MyApp.class,args);
}
}
4. Controller层
@GetMapping("/list")
public PageInfo<ProductListVO> getList(
@RequestParam(value="current",defaultValue = "1") Integer current,
@RequestParam(value="pageSize",defaultValue = "10")Integer pageSize
){
PageInfo<ProductListVO> productList = iProductService.getProductList(current,pageSize);
return productList;
}
5.service层
@Override
public PageInfo<ProductListVO> getProductList(Integer current, Integer pageSize) {
PageHelper.startPage(current,pageSize);
Page<ProductListVO> ProductListVO = productsMapper.getProductList();
Integer total = productsMapper.productsTotal();
PageInfo<ProductListVO> pageInfo = new PageInfo(current,pageSize,total,ProductListVO);
return pageInfo;
}
6.dao层
public interface ProductsMapper {
@Select("select product_name from product_info where goods_id = #{goods_id}")
public ProductVO getProductInfo(@Param("goods_id") int goods_id);
public Page<ProductListVO> getProductList();
@Select("select count(*) total from tp_goods")
Integer productsTotal();
}
7.mapper
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.smartom.dao.ProductsMapper">
<select id="getProductList" resultType="com.smartom.VO.ProductListVO">
select goods_id,goods_name,goods_sn,cat_id,price_ladder,is_recommend,is_new,is_hot,is_on_sale,store_count,sort from
tp_goods
</select>
</mapper>
···
Spring boot 配置 mybatis xml和动态SQL 分页配置的更多相关文章
- spring boot(8)-mybatis三种动态sql
脚本sql XML配置方式的动态SQL我就不讲了,有兴趣可以自己了解,下面是用<script>的方式把它照搬过来,用注解来实现.适用于xml配置转换到注解配置 @Select(" ...
- Spring Boot (10) mybatis三种动态sql
脚本SQL xml配置方式见mybatis讲解,下面是用<script>的方式把它照搬过来,用注解来实现.适于xml配置转换到注解配置 @Select("<script&g ...
- spring boot集成mybatis(2) - 使用pagehelper实现分页
Spring Boot 集成教程 Spring Boot 介绍 Spring Boot 开发环境搭建(Eclipse) Spring Boot Hello World (restful接口)例子 sp ...
- Spring Boot 实战 —— MyBatis(注解版)使用方法
原文链接: Spring Boot 实战 -- MyBatis(注解版)使用方法 简介 MyBatis 官网 是这么介绍它自己的: MyBatis 是一款优秀的持久层框架,它支持定制化 SQL.存储过 ...
- spring boot集成mybatis(3) - mybatis generator 配置
Spring Boot 集成教程 Spring Boot 介绍 Spring Boot 开发环境搭建(Eclipse) Spring Boot Hello World (restful接口)例子 sp ...
- spring boot集成mybatis(1)
Spring Boot 集成教程 Spring Boot 介绍 Spring Boot 开发环境搭建(Eclipse) Spring Boot Hello World (restful接口)例子 sp ...
- spring boot + druid + mybatis + atomikos 多数据源配置 并支持分布式事务
文章目录 一.综述 1.1 项目说明 1.2 项目结构 二.配置多数据源并支持分布式事务 2.1 导入基本依赖 2.2 在yml中配置多数据源信息 2.3 进行多数据源的配置 三.整合结果测试 3.1 ...
- Spring Boot 集成 MyBatis和 SQL Server实践
概 述 Spring Boot工程集成 MyBatis来实现 MySQL访问的示例我们见过很多,而最近用到了微软的 SQL Server数据库,于是本文则给出一个完整的 Spring Boot + M ...
- 太妙了!Spring boot 整合 Mybatis Druid,还能配置监控?
Spring boot 整合 Mybatis Druid并配置监控 添加依赖 <!--druid--> <dependency> <groupId>com.alib ...
随机推荐
- pip freeze 命令迁移模块
问题描述:现有一个测试环境安装了脚本相关的各类模块,现需要不通过联网下载,在另一个环境配置安装相同的模块 解决方案: 在安装了python脚本相关的各类模块的测试环境里,进入到任意目录下,导出pyth ...
- yii中通过HTTP post接收
创建一个CURL.php的文件然后引用 1 <?php namespace frontend\models; class Curl { public function getCurl($url, ...
- Luffy之注册认证(容联云通讯短信验证)
用户的注册认证 前端显示注册页面并调整首页头部和登陆页面的注册按钮的链接. 注册页面Register,主要是通过登录页面进行改成而成. 先构造前端页面 <template> <div ...
- PAT 1069 The Black Hole of Numbers
1069 The Black Hole of Numbers (20 分) For any 4-digit integer except the ones with all the digits ...
- Makefile 宏定义 -D
一.GCC编译器中使用: -D macro=string,等价于在头文件中定义:#define macro string. 例如:-D TRUE=true,等价于:#define ...
- C# 远程传输File文件
/// <summary> /// 向论坛传图片文件 /// </summary> /// <param name="filePath">< ...
- Spring Boot + Jpa + Thymeleaf 增删改查示例
快速上手 配置文件 pom 包配置 pom 包里面添加 Jpa 和 Thymeleaf 的相关包引用 <dependency> <groupId>org.springframe ...
- Samba服务与Nginx服务
Samba服务: 1 准备环境 =====>part1: iptables -F 清楚防火墙配置 #systemctl disable firewalld #开机默认关闭 #systemctl ...
- noj二分查找
二分查找: 要么左边,要么右边,哈哈哈哈 描述 给定一个单调递增的整数序列,问某个整数是否在序列中. 输入 第一行为一个整数n,表示序列中整数的个数:第二行为n(n不超过10000)个整数:第三行 ...
- vue-cli 安装过程出现错误
如果是这样得错误,那是你在安装sass得问题,需要安装python2,安装好就行了