20.Mybatis动态sql之choose when otherwise

choose when otherwise在使用的时候,相当于java语言中的if ---esleif--- esle,只会有一个满足条件,所以无须使用and;

/** * 根据Map查询学生信息 * @param map * @return */public List selectStuByMap(Map map);
@Testpublic void selectStuByMap(){    //把配置文件读取到数据流    InputStream stream = Student.class.getClassLoader().getResourceAsStream("mybatis-config.xml");    //创建SqlSessionFactory    SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(stream);    //创建SqlSession    SqlSession sqlSession = sqlSessionFactory.openSession();    //使用反射获取StudentMapper    StudentMapper studentMapper = sqlSession.getMapper(StudentMapper.class);    //构造Map封装查询条件    Map map=new HashMap<>();    map.put("name","赵六");    //    map.put("address","四川省成都市成华区");    //查询数据    List studentList = studentMapper.selectStuByMap(map);    //打印结果    for (Student student : studentList) {        System.out.println("student = " + student);    }}
发表评论
留言与评论(共有 0 条评论) “”
   
验证码:

相关文章

推荐文章