springboot与通用mapper的整合
找到springboot工程下的pom.xml文件,导入如下的依赖jar包
<!--配置通用Mapper start-->
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper-spring-boot-starter</artifactId>
<version>2.1.5</version>
</dependency>
<!--通用Mapper end-->
配置UserDao接口,继承通用mapper,注意泛型
@Repository
public interface UserDao extends Mapper<User> { }
Service的实现层
@Service("userService")
public calss UserServiceImpl implements UserService{
@Autowired
private UserDao userDao;
@Override
public List<User> list(){
return userDao.selectALL();
}
}
User实体类配置通用文件mapper的主键和主键返回策略
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id; public class User { @Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
private String name;
private Integer age; public Integer getId() {
return id;
} public void setId(Integer id) {
this.id = id;
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public Integer getAge() {
return age;
} public void setAge(Integer age) {
this.age = age;
} }
配置入口类Application
import tk.mybatis.spring.annotation.MapperScan;//把MapperScan的导入路径换成tk.mybatis.spring.annotation.MapperScan
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.transaction.annotation.EnableTransactionManagement; @SpringBootApplication
@EnableTransactionManagement //开启书屋管理注解模式 最新的版本可以省略
@MapperScan("com.xz.springboot.mapper") //扫描该包下所有的接口并为该接口生成实现类
public class Springboot01Application { public static void main(String[] args) {
SpringApplication.run(Springboot01Application.class, args);
} }
在application.properties中
#开启mybatis驼峰命名自动转换
mybatis.configuration.map-underscore-to-camel-case=true
springboot与通用mapper的整合的更多相关文章
- springboot搭建通用mapper
对于搭建一个小项目自己测试玩如果采用传统的SSM框架配置起来太过于繁琐,使用springboot简化配置再搭配通用mapper简直不要太方便,话不多说,直接上代码. 首先是pom文件,直接去sprin ...
- springboot学习笔记:9.springboot+mybatis+通用mapper+多数据源
本文承接上一篇文章:springboot学习笔记:8. springboot+druid+mysql+mybatis+通用mapper+pagehelper+mybatis-generator+fre ...
- springboot集成通用mapper详细配置
通常,我们利用mybatis写持久层方法.要么按照传统定义mapper方法,定义xml文件的方式,全部手写.要么需要通过mybatis-generator逆向工程插件生成大量的xxxExample文件 ...
- springboot中通用mapper结合mybatis generator的使用
通用mapper就是指的是 tk.mybatis 包下的.这个是通用mapper就是说自动生成的dao层需要继承这个框架提供的mapper类.而我们之前用的org.mybatis这个最开始是普通的 ...
- springboot+mybatis+通用mapper+多数据源(转载)
1.数据库准备 数据库表我们在springboot-mybatis数据之外,新建数据库springboot-mybatis2: springboot-mybatis数据库中有t_class表: spr ...
- SpringBoot 3.SpringBoot 整合 MyBatis 逆向工程以及 MyBatis 通用 Mapper
一.添加所需依赖,当前完整的pom文件如下: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi=&qu ...
- SpringBoot第六篇:整合通用Mapper
作者:追梦1819 原文:https://www.cnblogs.com/yanfei1819/p/10876339.html 版权声明:本文为博主原创文章,转载请附上博文链接! 引言 在以往的项 ...
- springboot整合mybatis通用Mapper
参考: https://blog.csdn.net/x18707731829/article/details/82814095 https://www.jianshu.com/p/6d2103451d ...
- 通用mapper版+SpringBoot+MyBatis框架+mysql数据库的整合
转:https://blog.csdn.net/qq_35153200/article/details/79538440 开发环境: 开发工具:Intellij IDEA 2017.2.3 JDK : ...
随机推荐
- SHELL 变量引用
shell变量的引用非常重要,运用技巧灵活多变 变量的引用主要包含四类:双引号引用.单引号引用.反引号引用.反斜线引用 " " 双引号 屏蔽除美元符号$.反引号( ` )和反斜线( ...
- C语言:基本数据类型及表示范围
类型名称 标识符 printf()标志 占据 范围 无符号 unsigned 范围 类型名称 类型标识符 printf标志 占字节数 表示范围 ...
- C语言:获取汉字的编码
#include <stdio.h> #include <locale.h> #include <wchar.h> int main() { setlocale(L ...
- spring pom文件报错:提示no declaration can be found for element 'dubbo:service'.
转自:http://blog.csdn.net/happylife_haha/article/details/52755425 pom文件报错:The matching wildcard is str ...
- 从源码构建Vim
从源码构建Vim 引言 事情是介样滴,因为我是个Vim 重度使用者了差不多.. 但在大部分系统上能安装到的或者自带的都是比较老的版本,可能是7.x 之类的.也或者是你需要使用到Vim 的某些特性或者功 ...
- 【知识详解】Https详解
Https详解 1.什么是Https Http + SSL = Https 一句话说:Https是身披SSL的Http,当使用了SSL后,Http先和SSL通信,再由SSL和TCP通信, 2.为什么需 ...
- C++第四十一篇 -- 安装成功的第一个驱动文件
参考链接:https://blog.csdn.net/LEON1741/article/details/87291839 一.新建工程 二.写一个Driver.c #include <ntddk ...
- python虚拟环境之Pyenv
一.windows下安装 1.使用命令安装 pip install pyenv-win --target %USERPROFILE%/.pyenv %USERPROFILE%/是具体的路径,例如 ## ...
- 【LeetCode】204.计数质数
问题描述: 统计所有小于非负整数 n 的质数的数量. 示例: 输入: 10 输出: 4 解释: 小于 10 的质数一共有 4 个, 它们是 2, 3, 5, 7 . 这是一道简单题,但是却并没有那么直 ...
- Python小白的数学建模课-16.最短路径算法
最短路径问题是图论研究中的经典算法问题,用于计算图中一个顶点到另一个顶点的最短路径. 在图论中,最短路径长度与最短路径距离却是不同的概念和问题,经常会被混淆. 求最短路径长度的常用算法是 Dijkst ...