工程结构

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">
<parent>
<artifactId>springboot-demo</artifactId>
<groupId>cn.xiaojf</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties> <artifactId>springboot-mybatis-plus</artifactId> <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency> <dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus</artifactId>
<version>2.1.7</version>
</dependency> <dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatisplus-spring-boot-starter</artifactId>
<version>1.0.5</version>
</dependency> <dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.45</version>
</dependency>
</dependencies>
</project>

application.properties

#应用端口号
server.port=8010
#freemarker 默认文件后缀
spring.freemarker.suffix=.html #数据库设置
spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8
spring.datasource.username=root
spring.datasource.password=root #mybatis plus 设置
mybatis-plus.mapper-locations=classpath:/mapper/*Mapper.xml
#实体扫描,多个package用逗号或者分号分隔
mybatis-plus.typeAliasesPackage=cn.xiaojf.springboot.mybatisplus.entity
#主键类型 0:"数据库ID自增", 1:"用户输入ID",2:"全局唯一ID (数字类型唯一ID)", 3:"全局唯一ID UUID";
mybatis-plus.global-config.id-type=2
#字段策略 0:"忽略判断",1:"非 NULL 判断"),2:"非空判断"
mybatis-plus.global-config.field-strategy=2
#驼峰下划线转换
mybatis-plus.global-config.db-column-underline=true
#刷新mapper 调试神器
mybatis-plus.global-config.refresh-mapper=true
#数据库大写下划线转换
#mybatis-plus.global-config.capital-mode=true
#序列接口实现类配置
#mybatis-plus.global-config.key-generator=com.baomidou.springboot.xxx
#逻辑删除配置
mybatis-plus.global-config.logic-delete-value=0
mybatis-plus.global-config.logic-not-delete-value=1
#自定义填充策略接口实现
#mybatis-plus.global-config.meta-object-handler=com.baomidou.springboot.xxx
#自定义SQL注入器
#mybatis-plus.global-config.sql-injector=com.baomidou.springboot.xxx
mybatis-plus.configuration.map-underscore-to-camel-case=true
mybatis-plus.configuration.cache-enabled=false

MybatisPlusConfig.java

package cn.xiaojf.springboot.mybatisplus.configure;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Configuration; @Configuration
@MapperScan("cn.xiaojf.springboot.mybatisplus.mapper*")
public class MybatisPlusConfig { }

UserMapper.java

package cn.xiaojf.springboot.mybatisplus.mapper;

import cn.xiaojf.springboot.mybatisplus.SuperMapper;
import cn.xiaojf.springboot.mybatisplus.entity.User; import java.util.List; public interface UserMapper extends SuperMapper<User> {
List<User> findByUserName(String name); User findUserAddrByName(String name);
}

UserMapper.xml

<?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="cn.xiaojf.springboot.mybatisplus.mapper.UserMapper">
<resultMap id="userAddr" type="cn.xiaojf.springboot.mybatisplus.entity.User">
<id column="user_id" property="id"></id>
<result column="user_name" property="name"></result>
<result column="user_age" property="age"></result>
<collection property="userAddrList" ofType="cn.xiaojf.springboot.mybatisplus.entity.UserAddr">
<id column="addr_id" property="id"></id>
<result column="addr_name" property="name"></result>
<result column="user_id" property="userId"></result>
</collection>
</resultMap> <select id="findByUserName" resultType="cn.xiaojf.springboot.mybatisplus.entity.User">
SELECT * FROM sys_user
</select> <select id="findUserAddrByName" resultMap="userAddr">
SELECT
u.id AS user_id,u.`name` AS user_name ,u.age AS user_age,addr.`name` AS addr_name,addr.id AS addr_id
FROM
sys_user u
LEFT JOIN sys_user_addr addr ON u.id = addr.user_id
WHERE
u.name = #{name}
</select> </mapper>

源码

https://gitee.com/xiaojf/springboot-demo/tree/master/springboot-mybatis-plus

springboot 零xml集成mybatis-plus的更多相关文章

  1. springboot 零xml集成mybatis

    maven依赖 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="htt ...

  2. SpringBoot系列之集成Mybatis教程

    SpringBoot系列之集成Mybatis教程 环境准备:IDEA + maven 本博客通过例子的方式,介绍Springboot集成Mybatis的两种方法,一种是通过注解实现,一种是通过xml的 ...

  3. SpringBoot零XML配置的Spring Boot Application

    Spring Boot 提供了一种统一的方式来管理应用的配置,允许开发人员使用属性properties文件.YAML 文件.环境变量和命令行参数来定义优先级不同的配置值.零XML配置的Spring B ...

  4. SpringBoot学习之集成mybatis

    一.spring boot集成Mybatis gradle配置: //gradle配置: compile("org.springframework.boot:spring-boot-star ...

  5. SpringBoot(九)_springboot集成 MyBatis

    MyBatis 是一款标准的 ORM 框架,被广泛的应用于各企业开发中.具体细节这里就不在叙述,大家自行查找资料进行学习下. 加载依赖 <dependency> <groupId&g ...

  6. SpringBoot集成Mybatis实现多表查询的两种方式(基于xml)

     下面将在用户和账户进行一对一查询的基础上进行介绍SpringBoot集成Mybatis实现多表查询的基于xml的两种方式.   首先我们先创建两个数据库表,分别是user用户表和account账户表 ...

  7. springboot集成mybatis(二)

    上篇文章<springboot集成mybatis(一)>介绍了SpringBoot集成MyBatis注解版.本文还是使用上篇中的案例,咱们换个姿势来一遍^_^ 二.MyBatis配置版(X ...

  8. springboot之集成mybatis mongo shiro druid redis jsp

    闲来无事,研究一下spingboot  发现好多地方都不一样了,第一个就是官方默认不支持jsp  于是开始狂找资料  终于让我找到了 首先引入依赖如下: <!-- tomcat的支持.--> ...

  9. springboot集成mybatis(一)

    MyBatis简介 MyBatis本是apache的一个开源项目iBatis, 2010年这个项目由apache software foundation迁移到了google code,并且改名为MyB ...

随机推荐

  1. IOS TableView滑动不灵敏问题

    TableView的默认的不常用的属性,我们尽量不要去改,如下面标注的几个

  2. python---web微信开发

    一:轮询,长轮询,WebSocket了解 轮询: 在前端,设置时间内,一直向后端发送请求.例如:使用setInterval方法设置定时器,一秒向后端发送一次请求,去主动获取数据,进行更新由于前端一直请 ...

  3. 转:String StringBuffer StringBuilder区别

    转自:http://www.iteye.com/topic/522167 作者:每次上网冲杯Java时,都能看到关于String无休无止的争论.还是觉得有必要让这个讨厌又很可爱的String美眉,赤裸 ...

  4. 微信 js-sdk

    使用方法 http://mp.weixin.qq.com/wiki/11/74ad127cc054f6b80759c40f77ec03db.html Demo http://203.195.235.7 ...

  5. [问题]SqlServer创建数据库出错

    SqlServer 2008 “Msg 1807, Level 16, State 3, Line 1Could not obtain exclusive lock on database ‘mode ...

  6. 实现asp.net的文件压缩、解压、下载

    很早前就想做文件的解压.压缩.下载 了,不过一直没时间,现在项目做完了,今天弄了下.不过解压,压缩的方法还是看的网上的,嘻嘻~~不过我把它们综合了一下哦.呵呵~~ 1.先要从网上下载一个icsharp ...

  7. UNIX环境高级编程 第10章 信号

    SIGSTOP和SIGKILL区别是:前者是使进程暂时停止,即中止,也就是说使进程暂停,将进程挂起,比如你在终端里面执行一个脚本或者程序,执行到一半,你想暂停一下,你按下ctrl+z,就会导致终端发送 ...

  8. C/S模式和B/S模式

    C/S模式和B/S模式 1.C/S模式(Client/Server,客户机/服务器模式) 如QQ 暴风影音,PPlive等应用软件都是C/S模式 是一种软件系统结构的一种,C/S模式是基于企业内部网络 ...

  9. 转载-SVN常用命令

    SVN(Subversion)是一个自由.开源的项目源代码版本控制工具.目前,绝大多数开源软件和企业代码管理,都使用SVN作为代码版本管理软件. Subversion将文件存放在中心版本库里,这个版本 ...

  10. 【读书笔记::深入理解linux内核】内存寻址【转】

    转自:http://www.cnblogs.com/likeyiyy/p/3837272.html 我对linux高端内存的错误理解都是从这篇文章得来的,这篇文章里讲的 物理地址 = 逻辑地址 – 0 ...