LambaQueryWrapper的经常使用方法(修改、查询、删除)
public void main(String[] args) {//修改方法String unitId = "1";//将UnitCompanyCategory表下UnitId值为1对应的unitCategoryId字段数据改为1String categoryId = "1";LambdaUpdateWrapper<UnitCompanyCategory> lambdaUpdateW
·
public void main(String[] args) {
//修改方法
String unitId = "1";
//将UnitCompanyCategory表下UnitId值为1对应的unitCategoryId字段数据改为1
String categoryId = "1";
LambdaUpdateWrapper<UnitCompanyCategory> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
lambdaUpdateWrapper.set(UnitCompanyCategory::getUnitCategoryId, categoryId);
lambdaUpdateWrapper.eq(UnitCompanyCategory::getUnitId, unitId);
this.update(lambdaUpdateWrapper);
//以下为查和删除方法
//根据unitId查询一个对象,有多个会报错
LambdaQueryWrapper<UnitCompanyCategory> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(UnitCompanyCategory::getUnitId, unitId);
UnitCompanyCategory unitCompanyCategory = this.getOne(lambdaQueryWrapper);
//查询UnitCompanyCategory表下unitId为1的数据返回List
LambdaQueryWrapper<UnitCompanyCategory> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(UnitCompanyCategory::getUnitId, unitId);
List<UnitCompanyCategory> list = this.list(lambdaQueryWrapper);
//删除UnitCompanyCategory表下企业unitId为1的数据
LambdaQueryWrapper<UnitCompanyCategory> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(UnitCompanyCategory::getUnitId, unitId);
baseMapper.delete(lambdaQueryWrapper);
}
更多推荐
已为社区贡献2条内容
所有评论(0)