0
点赞
收藏
分享

微信扫一扫

Mybatis-动态SQL案例

案例

根据 非id 两个字段删除

void deleteBatchRelation(@Param(entites) List<AttrAttrgroupRelationEntity> entites);

<delete id=deleteBatchRelation>
delete from pms_attr_attrgroup_relation where
-- 遍历循环删除 item separator是分隔符 or
<foreach collection=entites item=item separator=OR>
(attr_id=#{item.attrId} and attr_group_id=#{item.attrGroupId})
</foreach>
</delete>

【多选删除】根据ids

EmployeeController层
//给出接口
@RequestMapping(/delempList)
public String deleteEmp(@RequestBody Integer[] ids){
employeeService.deleteList(ids);
return success删除;
}

EmployeeService层
//定义接口impl
void deleteList(Integer[] ids);

EmployeeServiceImpl层
public void deleteList(Integer[] ids) {
employeeDao.deleteList(ids);
}
核心数EmployeeDao
<delete id=deleteList >
delete from employee where id in
<foreach collection=array item=ids open=( separator=,
close=)>
#{ids}
</foreach>
</delete>

模糊查询

<select id=getEmpListByname resultType=com.springboot10.entity.EmployeeEntity>
SELECT * FROM employee where lastname like CONCAT(CONCAT('%', #{lastname}), '%') or email like CONCAT(CONCAT('%', #{email}), '%')
</select>
举报

相关推荐

0 条评论