您的位置:首页 > 数据库

ssm,mybatis注解配置动态sql语句

2020-06-05 10:46 603 查看

使用if、where、foreach标签,要加

@Select("<script>" +
"select * from course " +
"where 1=1 " +
"<if test='search != null '>" +
"and name like concat('%',#{search},'%')" +
"</if>" +
" limit #{start},#{rows} " +
"</script>")
List<Course> findCourse(@Param("start") int start,@Param("rows") int rows,@Param("search") String search);
@Select("<script>" +
"select count(id) from course where 1=1" +
"<if test='search != null' > " +
"and name like concat('%',#{search},'%')" +
"</if>" +
"</script>")
int selectCounts(@Param("search") String search);

要用@Param声明,不然sql语句中要用arg0,arg1,arg2

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: