一、insert
1、插入操作
//添加操作
@Test
public void addUser() {
User user = new User();
user.setName("岳不群1");
user.setAge(70);
user.setEmail("[email protected]");
int insert = userMapper.insert(user);
System.out.println("insert:"+insert);
}
执行日志输出结果 Parameters: 1249545169748951041(Long), 岳不群1(String), 70(Integer), [email protected](String)
1249545169748951041是MP自动生成的
Creating a new SqlSession
SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@4ab550d5] was not registered for synchronization because synchronization is not active
JDBC Connection [HikariProxyConnection@999674172 wrapping com.mysql.cj.jdbc.ConnectionImpl@3730ab42] will not be managed by Spring
==> Preparing: INSERT INTO user ( id, name, age, email ) VALUES ( ?, ?, ?, ? )
==> Parameters: 1249545169748951041(Long), 岳不群1(String), 70(Integer), [email protected](String)
<== Updates: 1
Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@4ab550d5]
insert:1
2、主键策略
(1)ID_WORKER
MyBatis-Plus默认的主键策略是:ID_WORKER 全局唯一ID
参考资料:分布式系统唯一ID生成方案汇总:https://www.cnblogs.com/haoxinyue/p/5208136.html
@Data
public class User {
//@TableId(type = IdType.ID_WORKER) //mp自带策略,生成19位值,数字类型使用这种策略,比如long
//@TableId(type = IdType.ID_WORKER_STR) //mp自带策略,生成19位值,字符串类型使用这种策略
private Long id;
private String name;
private Integer age;
private String email;
}