1、pom.xml
<!-- mysql 驱动 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.30</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.2.13-SNSAPSHOT</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.4.1</version>
</dependency>
<dependency>
<groupId>com.gitee.sunchenbin.mybatis.actable</groupId>
<artifactId>mybatis-enhance-actable</artifactId>
<version>1.5.0.RELEASE</version>
</dependency>
2、yml
classpath*:mapper/.xml:自己xml的路径
classpath:com/gitee/sunchenbin/mybatis/actable/mapping//.xml: actable的路径,固定写死
mybatis:
table:
auto: update
model:
pack: com.java.test.entity
database:
type: mysql
mybatis-plus:
mapper-locations: classpath:mapper/*.xml,classpath*:com/gitee/sunchenbin/mybatis/actable/mapping/*/*.xml
3、Application
com.gitee.sunchenbin.mybatis.actable… : 固定写死
@MapperScan(basePackages = {"com.gitee.sunchenbin.mybatis.actable.dao.*","com.java.test.mapper"})
@ComponentScan("com.gitee.sunchenbin.mybatis.actable.manager.*")
4、entity
- @Id是主键
- @GeneratedValue 主键配置:
参数 | 描述 |
---|---|
AUTO | 主键由程序控制, 默认选项 |
IDENTITY | 主键由数据库生成, 采用数据库自增长, Oracle不支持这种方式 |
SEQUENCE | 通过数据库的序列产生主键, MYSQL 不支持 |
Table | 提供特定的数据库产生主键, 该方式更有利于数据库的移植 |
- @GeneratedValue无效就使用@IsAutoIncrement
- @Column默认是VARCHAR类型
- @ColumnType指定其他类型,默认参数是enum对象MySqlTypeConstant
@Data
@Entity
@Table(name = "t_table")
public class Table {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@ColumnType(MySqlTypeConstant.INT)
@IsAutoIncrement
private Long id;
@Column(length = 50)
private String name;
@Column(length = 50)
private String age;
@Column
@ColumnType(value = MySqlTypeConstant.TEXT)
private String text;
}
5、日志
2022-09-29 09:29:37.621 INFO 11247 --- [main] ...... : databaseType=mysql,开始执行mysql的处理方法
2022-09-29 09:29:37.769 INFO 11247 --- [main] ...... : {dataSource-1} inited
2022-09-29 09:29:38.219 INFO 11247 --- [main] ...... : 开始创建表:t_table
2022-09-29 09:29:38.862 INFO 11247 --- [main] ...... : 完成创建表:t_table