在上一篇中我已经讲解如何创建springBoot项目这里就不在重复了,不会创建项目的可以看上一篇博文 https://blog.csdn.net/weixin_38171468/article/details/103406074,接下来讲解springBoot整合mybatis的入门
**
1.新建项目的目录结构
**项目中缺少咱们平时使用的controller,entity,mapper,service,service实现类等,下图是我上一篇博文的测试目录结构,里面的controller是测试使用的,以后相关controller都可以在此目录下创建
以下是我创建好的目录结构,但是在整合mybatis的是还需要在resources文件中创建mapper/UserMapper.xml配置文件,到此为止我们要用的文件已经创建好
2.编写实体类,接口,实现类
2.1编写实体类com.springboot.springbootproject.entity.UserEntity
package com.springboot.springbootproject.entity;
/**
* `用户表
*/
public class UserEntity {
private Integer id;
private String userName;
private String passWord;
private String realName;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassWord() {
return passWord;
}
public void setPassWord(String passWord) {
this.passWord = passWord;
}
public String getRealName() {
return realName;
}
public void setRealName(String realName) {
this.realName = realName;
}
}
2.2编写接口com.springboot.springbootproject.mapper.UserMapper
注意:需要使用@Mapper注解,不然SpringBoot无法扫描
package com.springboot.springbootproject.mapper;
import com.springboot.springbootproject.entity.UserEntity;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
import java.util.Map;
@Mapper
public interface UserMapper {
public List<UserEntity> findByList(Map<String,Object> ma