更新时间 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 分页配置的更多相关文章

  1. spring boot(8)-mybatis三种动态sql

    脚本sql XML配置方式的动态SQL我就不讲了,有兴趣可以自己了解,下面是用<script>的方式把它照搬过来,用注解来实现.适用于xml配置转换到注解配置 @Select(" ...

  2. Spring Boot (10) mybatis三种动态sql

    脚本SQL xml配置方式见mybatis讲解,下面是用<script>的方式把它照搬过来,用注解来实现.适于xml配置转换到注解配置 @Select("<script&g ...

  3. spring boot集成mybatis(2) - 使用pagehelper实现分页

    Spring Boot 集成教程 Spring Boot 介绍 Spring Boot 开发环境搭建(Eclipse) Spring Boot Hello World (restful接口)例子 sp ...

  4. Spring Boot 实战 —— MyBatis(注解版)使用方法

    原文链接: Spring Boot 实战 -- MyBatis(注解版)使用方法 简介 MyBatis 官网 是这么介绍它自己的: MyBatis 是一款优秀的持久层框架,它支持定制化 SQL.存储过 ...

  5. spring boot集成mybatis(3) - mybatis generator 配置

    Spring Boot 集成教程 Spring Boot 介绍 Spring Boot 开发环境搭建(Eclipse) Spring Boot Hello World (restful接口)例子 sp ...

  6. spring boot集成mybatis(1)

    Spring Boot 集成教程 Spring Boot 介绍 Spring Boot 开发环境搭建(Eclipse) Spring Boot Hello World (restful接口)例子 sp ...

  7. spring boot + druid + mybatis + atomikos 多数据源配置 并支持分布式事务

    文章目录 一.综述 1.1 项目说明 1.2 项目结构 二.配置多数据源并支持分布式事务 2.1 导入基本依赖 2.2 在yml中配置多数据源信息 2.3 进行多数据源的配置 三.整合结果测试 3.1 ...

  8. Spring Boot 集成 MyBatis和 SQL Server实践

    概 述 Spring Boot工程集成 MyBatis来实现 MySQL访问的示例我们见过很多,而最近用到了微软的 SQL Server数据库,于是本文则给出一个完整的 Spring Boot + M ...

  9. 太妙了!Spring boot 整合 Mybatis Druid,还能配置监控?

    Spring boot 整合 Mybatis Druid并配置监控 添加依赖 <!--druid--> <dependency> <groupId>com.alib ...

随机推荐

  1. SWUST OJ(961)

    进制转换问题 #include<stdio.h> #include<stdlib.h> #define STACK_SIZE 100 #define STCK_INCREMEN ...

  2. Vue调用百度接口做百度搜索

    这两天由于学习需要,需要用vue来调用api接口,但是以前没怎么接触过用vue来调用接口,不会没关系,发挥我们强大的学习能力,都不是事,学习了半天基本也就可以初级上手了,写篇随笔记录下来,方便以后回顾 ...

  3. Oracle获取当前年、月、日的方法

    Oracle获取当前年.月.日的方法 Oracle 获取当前年.月.日 1.//oracle中extract()函数从oracle 9i中引入,用于从一个date或者interval类型中截取到特定的 ...

  4. redis主从简单配置

    网上有好多复杂的配置,这里我用的是windows版的redis,简单配置了下,试验了下主从,能正常使用. 1.redis-master文件夹(里面是redis),redis-slave文件夹(里面是r ...

  5. idea:打包jar(原文by曲高终和寡)

    idea打包java可执行jar包   1,在项目上鼠标右键 --> Open Module Settings 2, Artifacts --> + --> JAR --> F ...

  6. Vue 学习Day001

    入门 基本使用 安装Vue 直接引入本地或者cdn Vue地址 使用npm 使用cli 示例 <!DOCTYPE html> <html lang="en"> ...

  7. cocos2d-x学习笔记(斗地主代码)

    满足百度百科上的出牌规则,电脑可以随着玩家出牌. 百度网盘地址:链接: https://pan.baidu.com/s/1eRLpvJ8 提取密码: tf8w

  8. mysql 在 win 安装 最全攻略(附转载的乱码终极解决方案)以及解决data too long for column 'name' at row 1, 一种可能就是因为编码一致性问题.

    [博客园cnblogs笔者m-yb原创,转载请加链接,公众号aandb7, github.com/mayangbo666,QQ群927113708] https://www.cnblogs.com/m ...

  9. Angular4.0.0正式发布,附新特性及升级指南

    本文首发地址:Angular4.0.0正式发布,附新特性及升级指南 作者|孙薇 编辑|尾尾 经历了6个RC版本之后,Angular项目组终于发布了新版,即正式版 Angular 4.0.0.新版的 A ...

  10. [python] 使用Jieba工具中文分词及文本聚类概念

    声明:由于担心CSDN博客丢失,在博客园简单对其进行备份,以后两个地方都会写文章的~感谢CSDN和博客园提供的平台.        前面讲述了很多关于Python爬取本体Ontology.消息盒Inf ...