Springboot整合通用mapper过程解析
作者:&天涯海角& 时间:2023-08-24 09:32:25
这篇文章主要介绍了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);
}
}
来源:https://www.cnblogs.com/sitian2050/p/11824825.html
标签:spring,boot,整合,通用,mapper
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
java 获取当前路径下的所有xml文档的方法
2021-08-08 13:54:29
Servlet的5种方式实现表单提交(注册小功能),后台获取表单数据实例
2022-08-19 20:58:06
![](https://img.aspxhome.com/file/2023/3/76323_0s.png)
java实现马踏棋盘算法(骑士周游问题)
2022-03-17 20:29:46
![](https://img.aspxhome.com/file/2023/1/94361_0s.jpg)
Thymeleaf 3.0 自定义标签方言属性的实例讲解
2023-03-24 20:40:23
Android studio实现画板功能
2022-08-04 21:30:39
![](https://img.aspxhome.com/file/2023/2/137172_0s.png)
jdk15的安装与配置全过程记录
2023-01-06 05:45:10
![](https://img.aspxhome.com/file/2023/6/85516_0s.jpg)
教你使用springSecurity+jwt实现互踢功能
2023-05-24 19:45:10
![](https://img.aspxhome.com/file/2023/9/122019_0s.png)
Struts2相关的面试题整理分享
2022-04-06 08:02:20
Java毕业设计实战之健身器材商城系统的实现
2022-12-18 01:39:56
![](https://img.aspxhome.com/file/2023/5/100355_0s.jpg)
Android权限管理之Permission权限机制及使用详解
2023-04-07 09:12:45
maven profile动态选择配置文件详解
2023-11-05 22:05:20
![](https://img.aspxhome.com/file/2023/4/64514_0s.png)
Mybatis一对一延迟加载实现过程解析
2022-09-07 12:45:43
java代理模式(静态代理、动态代理、cglib代理)
2022-11-22 16:12:49
![](https://img.aspxhome.com/file/2023/7/103827_0s.png)
java设计模式之适配器模式
2021-08-28 09:08:09
![](https://img.aspxhome.com/file/2023/4/59854_0s.jpg)
Java读取TXT文件内容的方法
2023-11-23 22:33:41
C#中is,as,using关键字的使用说明
2023-07-01 22:54:42
![](https://img.aspxhome.com/file/2023/4/76394_0s.jpg)
关于报错IDEA Terminated with exit code 1的解决方法
2021-06-03 08:33:12
![](https://img.aspxhome.com/file/2023/4/116834_0s.png)
Java 设计模式中的策略模式详情
2023-08-06 03:45:11
![](https://img.aspxhome.com/file/2023/1/57731_0s.png)
C#中的高效IO库System.IO.Pipelines
2022-11-16 03:43:06
Java执行SQL脚本文件到数据库详解
2023-08-08 08:30:00