重点-编程的代码和教程千万不要去记,需要的是理解和能看懂。
1.在java测试类中间进行测试的时候,测试类需要和java代码的文件夹结构相同才可以正常运行。
1.1 在mybatis-plus中,实体类中需要指定标的名称,找到对应标的名称
@TableName("student")
1.2当表名有前缀,可以不在实体类进行配置,只需要在application.propertise配置文件统一配置前缀。
mybatis-plus.global-config.db-config.table-prefix=tb_
1.3在实体类中添加注解-实现id插入自增
@TableId(type = IdType.AUTO)
@Data
@AllArgsConstructor
@NoArgsConstructor
@TableName("student")
public class Student {
@TableId(type = IdType.AUTO)
private Integer id;
private String username;
private String password;
private String name;
private Integer age;
private String adress;
}
1.4可以设置所有表的id全局自增,在配置文件中
mybatis-plus.global-config.db-config.id-type=auto
1.5关闭驼峰命名方式,采用驼峰命名,userName---数据库中字段为user_name
当驼峰,数据库与实体类需要进行对应,不然会报错,如果数据库没有_结构,可用此注解关闭
关闭驼峰映射
mybatis-plus.configuration.map-underscore-to-camel-case=false
1.6可用次注解在映射的地方进行实体类的的映射
@TableField("address")
private String adress;
1.7可以此配置,在控制台打印mybatis-plus操作日志
#打印mybatis-plus操作日志
mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl