Springboot整合通用mapper过程解析
作者:&天涯海角& 发布时间:2023-08-24 09:32:25
标签:spring,boot,整合,通用,mapper
这篇文章主要介绍了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
0
投稿
猜你喜欢
- try catch finally组合:检测异常,并传递给catch处理,并在finally中进行资源释放。try catch组合 : 对代
- 通过VideoView播放视频的步骤:1、在界面布局文件中定义VideoView组件,或在程序中创建VideoView组件2、调用Video
- 1. web.xml中配置了CharacterEncodingFilter,配置这个是拦截所有的资源并设置好编号格式。encoding设置成
- 去年买了本数字图像处理算法,一直都没有看,前几个星期都一直忙着工作上的活,趁这阶段悠闲点,玩一玩图片处理,这玩意还是非常有意思的。以前我们在
- 何为系统APP何为三方APP?位于system分区内的是系统软件,位于data分区得的是第三方后安装的软件系统软件是指控制和协调计算机及外部
- 今天用NewtonSoft.JSon解析一个天气数据,数据格式如:{"status":1,"detail&qu
- 利用Java连接MySQL做登陆界面,供大家参考,具体内容如下1、首先需要建立一个类,在这里,我命名为newLoginnewLogin类的代
- Java 反射机制介绍Java 反射机制。通俗来讲呢,就是在运行状态中,我们可以根据“类的部分已经的信息”来还原“类的全部的信息”。这里“类
- 1.简单介绍一下NDK和JNINDK:NDK是Native Development Kit的缩写,是Google提供的一套工具集
- 本文根据一个简单的user表为例,展示 springboot集成mybatis,再到前端分页完整代码(新手自学,不足之处欢迎纠正);先看ja
- Android的闹钟实现机制, 需要调用AlarmManager.set()将闹铃时间记录到系统中,当闹铃时间到后,系统会给应用程序发送广播
- 本文实例讲述了android打开本地图像的方法。分享给大家供大家参考。具体如下:方法一,调用手机安装的图像浏览工具浏览:Intent int
- 在开发过程中,我们经常需要将数据库查询到的值放入jsp页面进行显示,在springmvc的controller中,我们采用request将数
- 本文实例讲述了C#实现的JS操作类。分享给大家供大家参考。具体如下:这个C#类封装了常用的JS客户端代码操作,包括弹出对话框、返回上一页,通
- 这篇文章memo一下Jvm中关于时区设定的基础操作。Java的时区设定这里列出如下三种方式方式说明TimeZone.setDefault方式
- 1、背景本系统调用外围系统接口(http+json),但是发现有时外围系统服务不太稳定,有时候会出现返回一串xml或者gateway bad
- 一、缓存的基本概念缓存 。这是一个简单但非常有效的概念,这个想法的核心是记录过程数据,重用操作结果。当执行繁重的操作时,我们会将结果保存在我
- 这几天用winform做了一个设置壁纸的小工具, 为图片添加当月的日历并设为壁纸,可以手动设置壁纸,也可以定时设置壁纸,最主要的特点是在图片
- 1.创建线程 在Java中创建线程有两种方法:使用Thread类和使用Runnable接口。在使用Runnable接口时需要建立
- 对象POJO和JSON互转public class JsonUtil { /** * JSON 转 POJO &n