个人主页: 叶落闲庭
我的专栏:
c语言
数据结构
javaEE
操作系统
石可破也,而不可夺坚;丹可磨也,而不可夺赤。
查询条件
LambdaQueryWrapper<User> lqw = new LambdaQueryWrapper<>();
//等同于"="
lqw.eq(User::getUsername,"张三").eq(User::getPassword,123);
List<User> selectList = userDao.selectList(lqw);
System.out.println(selectList);
LambdaQueryWrapper<User> lqw = new LambdaQueryWrapper<>();
//范围查询lt le gt ge eq between
lqw.between(User::getId,1,3);
User user = userDao.selectOne(lqw);
System.out.println(user);
LambdaQueryWrapper<User> lqw = new LambdaQueryWrapper<>();
//模糊匹配 like
lqw.like(User::getUsername,"张");
List<User> userList = userDao.selectList(lqw);
System.out.println(userList);
QueryWrapper<User> qw = new QueryWrapper<>();
qw.select("count(*) as count");
qw.groupBy("gender");
LambdaQueryWrapper<User> lqw = new LambdaQueryWrapper<>();
List<User> userList = userDao.selectList(lqw);
System.out.println(userList);
public class User {
private Integer id;
@TableField(value = "username")
private String userName;
@TableField(value = "password")
private String passWord;
private String gender;
private String addr;
}
public class User {
private Integer id;
@TableField(value = "username")
private String userName;
@TableField(value = "password")
private String passWord;
private String gender;
private String addr;
@TableField(exist = false)
private Integer online;
}
public class User {
private Integer id;
@TableField(value = "username")
private String userName;
@TableField(value = "password",select = false)
private String passWord;
private String gender;
private String addr;
@TableField(exist = false)
private Integer online;
}
@TableName("tb_user")
public class User {
private Integer id;
@TableField(value = "username")
private String userName;
@TableField(value = "password")
private String passWord;
private String gender;
private String addr;
}
@TableName("tb_user")
public class User {
private Integer id;
@TableField(value = "username")
private String userName;
@TableField(value = "password")
private String passWord;
private String gender;
private String addr;
}
相关属性:
AUTO(0):使用数据库id自增策略控制id生成
NONE(1):不设置id生成策略
INPUT(2):用户手工输入id
ASSIGN_UUID(4):以UUID生成算法作为id生成策略
@TableName("tb_user")
public class User {
@TableId(type = IdType.ASSIGN_ID)
private Long id;
}
@TableName("tb_user")
public class User {
@TableId(type = IdType.ASSIGN_ID)
private Long id;
}
# 设置统一id生成算法(为所有实体类设置)
mybatis-plus:
global-config:
banner: false
db-config:
id-type: assign_id
# 设置数据库表名前缀
table-prefix: tb_
void testDelete() {
List<Long> list = new ArrayList<>();
list.add(1698537145196683265L);
list.add(1698539961168465921L);
list.add(1698540047797653506L);
userDao.deleteBatchIds(list);
}
void testSelect() {
List<Long> list = new ArrayList<>();
list.add(1L);
list.add(2L);
list.add(3L);
list.add(4L);
userDao.selectBatchIds(list);
}