11.mybatis查询条件in的使用

使用字符串拼接的方式${} ,把in后面的数据作为一个字符串拼接上去;

查询时候的字符串,需要留意,需要包含括号,而且要根据类型判断是否要单引号;

/** * 根据ID查询学生信息 * @param ids 学生信息集合 * @return */public List selectStuByIds(String ids);
@Testpublic void selectStuByIds() {    //获取SqlSession    SqlSession sqlSession = MybatisUtils.getSqlSession();    //获取StudentMapper    StudentMapper mapper = sqlSession.getMapper(StudentMapper.class);    //构造字符串    String ids = "('2', '3', '4')";    //执行查询    List studentList = mapper.selectStuByIds(ids);    //打印结果    studentList.forEach(student -> System.out.println(student));}
条件   mybatis   in
发表评论
留言与评论(共有 0 条评论) “”
   
验证码:

相关文章

推荐文章