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 ...
随机推荐
- Dagger2
一.理解Dagger2原理 原文链接 二.Dagger2例子实战 原文链接 Demo地址 注:关于错误:IncompleteAnnotationException: dagger.Provides m ...
- mybat使用注解的方式如@Select写sql
package com.polymer.app.mapper; import org.apache.ibatis.annotations.Mapper; import org.apache.ibati ...
- Python- - -基础目录
一.Python.pycharm的介绍与安装. 二.变量.整数.字符串.列表.字典.集合. 三.运算符.格式化输出.流程控制语句. 四.break和continue. 五.range.enumerat ...
- windows下《Go Web编程》之Go开发工具
Go开发工具很多,比较喜欢的使用作者列出的第一个工具,LiteIDE.它是一款专门为Go语言开发的跨平台轻量级集成开发环境. 一.LiteIDE下载安装 下载地址:https://sourceforg ...
- bzoj1452
题解: 二位树状数组 然后我开了300*300*300就T了 代码: #include<bits/stdc++.h> using namespace std; ; ],q; int fin ...
- day36-多进程多线程一
多进程 概念:进程是程序在计算机上的一次执行活动.当你运行一个程序,你就启动了一个进程.显然,程序是死的(静态的),进程是活的(动态的).进程可以分为系统进程和用户进程.凡是用于完成操作系统的各种功能 ...
- centos7下zabbix4.0配置磁盘IO监控
一:准备 1.1:安装sysstat yum -y install sysstat 1.2:安装zabbix-get yum install -y zabbix-get.x86_64 1.3:iost ...
- bootstrap之编译CSS和Javascript-0基础安装grunt教程
昨天晚上看到 bootstrap 全局CSS样式中 使用Less 章节中提到的通过grunt重新编译CSS和Javascript文件,对于我这样从未接触过windows cmd node控制台 npm ...
- error: checker javascript/jshint: can’t parse version string (abnormal termination?)”
vim 安装插件(k-vim方法 )好后 编辑js文件提示错误 可能是nodejs环境没搭建好 或者版本有误 用nvm安装node 后 需要 source ~/.bashrc 或者重新开一个终端 再运 ...
- CT ubuntu 16.04安装 adobe flash player
sudo apt-get install flashplugin-installer chrome 升级 chrome://chrome-urls/ chrome://components/ 找到A ...