deletetById、deleteBatchIds、deleteByMap
deleteBatchIds根据ids(数据库里的组件,不能说bizids)删除
delete
if (!CollectionUtils.isEmpty(delDictInfo.getDictIds())){
return dictMapper.delete(new UpdateWrapper<DictEntity>().in("dict_id", delDictInfo.getDictIds()));
}
deletebymap不能实现批量删除
引入依赖
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.7.RELEASE</version>
<relativePath/>
</parent>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.2.0</version>
</dependency>
配置文件
mybatis-plus:
mapper-locations: mapper/*.xml
configuration:
map-underscore-to-camel-case: true
# log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
启动类中加入
@MapperScan("com.xxx.xxx.xxx.mapper")
//mapper接口所在的包名
查询条件
条件 | 作用 | 格式 |
---|---|---|
eq | 等于 = | new QueryWrapper.eq(“字段”,val) |
ne | 不等于 | QueryWrapper<表名> 对象 = new QueryWrapper(); 对象.ne(“字段”,val) |
gt | 大于 | |
ge | 大于等于 | |
lt | 小于 | |
le | 小于等于 | |
betwen | 在…之间 | 两端都包含,相当于左边<=字段<=右边 |
noBetween | 不在…之间 | |
like | 模糊匹配 | |
noLike | ||
likeLeft | ||
likeRight | ||
isNull | ||
isNotNull | ||
in | ||
notLn |
IService和BaseMapper用法
public interface UserService extends IService<User> {
//默认拥有了基础的crud
//自己定义的一些方法
}
public interface UserMapper extends BaseMapper<User>{
//默认拥有了基础的crud
//自己定义的一些方法
}
条件查询
QueryWrapper<ItemEntity> wrapper = new QueryWrapper();
wrapper.lambda().eq(ItemEntity::getAppCode, appCode)
.eq(ItemEntity::getCode, code)
.eq(ItemEntity::getDeleted, 0);
<!-- 根据条件查询-->
<select id="retrieveStudent" parameterType="com.yy.server.entity.Student" resultType="com.yy.server.entity.Student">
select * from student where
<if test="sId != null">
s_id like concat('%',#{sId},'%') and
</if>
s_name like "%"#{sName}"%" and s_school like "%"#{sSchool}"%"
and s_major like "%"#{sMajor}"%" and s_class like "%"#{sClass}"%" and s_tel like "%"#{sTel}"%" and s_email like "%"#{sEmail}"%"
<if test="sSex != null">
and s_sex = #{sSex}
</if>
</select>
分页查询
https://blog.csdn.net/Saintyyu/article/details/88837259?utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-2.control&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-2.control
本质和这个一样