1、Mybatis全注解形式 (在注解上不能直接使用动态Sql,必须要在前后面加上<script>SQL</script>标签,否则会报错):
@Select("<script>" +
"select discuss_id,discuss_content,parent_discuss_id,discuss_type,create_datetime from t_discuss " +
"<where>" +
"discuss_id in <foreach collection='discussIds' item='item' open='(' separator=',' close=')'>#{item}</foreach>" +
"</where>" +
"</script>")
@Results({
@Result(column = "discuss_id", property = "discussId"),
@Result(column = "discuss_content", property = "discussContent"),
@Result(column = "parent_discuss_id", property = "parentDiscussId"),
@Result(column = "discuss_type", property = "discussType"),
@Result(column = "create_datetime", property = "createDatetime"),
})
List<TDiscuss> selectDiscussPushByPIds(@Param("discussIds") List<Long> discussIds);
2、like不能直接使用,可以借助concat函数实现:
@Select("SELECT name from user WHERE email LIKE concat(#{prefix},'%') limit 10")