1.导入依赖
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.3.1</version>
</dependency>
2.编写配置文件
spring:
application:
name: keep-learning-business
datasource:
url: jdbc:mysql://localhost:3306/keep_learning?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai
username: root
password: 123456
driver-class-name: com.mysql.jdbc.Driver
mybatis-plus:
mapper-locations: classpath*:/mapper/**/*.xml
global-config:
db-config:
id-type: auto
3.在启动类添加注解扫描 @MapperScan(“com.keep.learning.business.mapper”)
4.编写service与mapper
public interface StudentService extends IService<StudentEntity> {
}
@Service
public class StudentServiceImpl extends ServiceImpl<StudentMapper, StudentEntity> implements StudentService {
}
public interface StudentMapper extends BaseMapper<StudentEntity> {
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.keep.learning.business.mapper.StudentMapper">
</mapper>
|