IN查询
@Select({"<script> " +
" select * "+
" from business_threat bt \n" +
" join abnormal_event_type aet on bt.event_type_id = aet.id " +
" where 1=1 " +
" <if test = ' ids != null'> " +
" and bt.id in " +
" <foreach item = 'item' index = 'index' collection = 'ids' open = '(' separator = ',' close = ')' > " +
" #{item} " +
" </foreach> " +
" </if> " +
"</script>"})
List<BusinessThreatVO> getByBusinessThreadId(@Param("ids") List<Long> ids);
模糊查询 ' '这个就是 表示不等于空字符串
"<if test='userName !=null and userName!= '' ' >" +
" and u.user_name like CONCAT('%',#{userName},'%') " +
" </if>" +
批量插入
@Insert({
"<script>",
"insert into table_name(column1, column2) values ",
"<foreach collection='lists' item='item' index='index' separator=','>",
"(#{item.实体属性1}, #{item.实体属性2})",
"</foreach>",
"</script>"
})
int insertCollectList(@Param(value="lists") List<Test> lists);
插入数据返回主键
@Options(useGeneratedKeys = true,keyProperty ="id(主键的字段)")
@Insert(" insert into user (id, user_name, ”)