1.maven依赖
com.baomidou mybatis-plus-boot-starter 3.4.3.1 mysql mysql-connector-java runtime
2.yaml配置
spring:
datasource:
url: jdbc:mysql://localhost:3306/haha?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=UTF-8
username: root
password: root
driver-class-name: com.mysql.cj.jdbc.Driver
mybatis-plus:
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl #开启sql日志
map-underscore-to-camel-case: true # 该配置就是将带有下划线的表字段映射为驼峰格式的实体类属性
mapper-locations: classpath:mapper/*.xml #配置xml地址
3.实体类
@Data
@ApiModel
@TableName(value = "user") //mybatis-plus注解
public class UserEntity implements Serializable {
private static final long serialVersionUID = 1903236519513043621L;
@ApiModelProperty("id")
private Long id;
@ApiModelProperty("名称")
private String name;
@ApiModelProperty("性别")
private Integer sex;
@ApiModelProperty("日期")
private Date date;
}
4.DAO
dao接口需要继承baseMapper,泛型为实体类
public interface UserDao extends baseMapper{ }
5.service
service接口需要继承IService,泛型为实体类
public interface UserService extends IService{ }
6.serviceImpl
serviceImpl实现service接口,并继承ServiceImpl类,泛型为DAO接口和实体类
@Service public class UserServiceImpl extends ServiceImplimplements PersonService { }
7.xml
注:记得在启动类加上@MapperScan(basePackages = “com.example.dao”)注解,或者在每个dao加上@Mapper



