RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
Springboot整合通用mapper过程解析

这篇文章主要介绍了springboot整合通用mapper过程解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下

成都创新互联专注于栾川网站建设服务及定制,我们拥有丰富的企业做网站经验。 热诚为您提供栾川营销型网站建设,栾川网站制作、栾川网页设计、栾川网站官网定制、微信小程序开发服务,打造栾川网络公司原创品牌,更为您提供栾川网站排名全网营销落地服务。

找到springboot工程下的pom.xml文件,导入如下的依赖jar包


    
      tk.mybatis
      mapper-spring-boot-starter
      2.1.5
    
    

配置UserDao接口,继承通用mapper,注意泛型

@Repository
public interface UserDao extends Mapper {
}

Service的实现层

@Service("userService")
public calss UserServiceImpl implements UserService{
  @Autowired
  private UserDao userDao;
  @Override
  public List 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);
  }
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持创新互联。


文章标题:Springboot整合通用mapper过程解析
标题URL:http://sczitong.cn/article/gsejhg.html