小峰mybatis(5)mybatis使用注解配置sql映射器--动态sql
2017-04-13 01:26
609 查看
一、使用注解配置映射器 动态sql:
用的并不是很多,了解下;
View Code
用的并不是很多,了解下;
1 public class StudentTest { 2 private static Logger logger = Logger.getLogger(StudentTest.class); 3 4 private SqlSession sqlSession=null; 5 private StudentMapper studentMapper=null; 6 7 @Before 8 public void setUp() throws Exception { 9 sqlSession=SqlSessionFactoryUtil.openSession(); 10 studentMapper=sqlSession.getMapper(StudentMapper.class); 11 } 12 13 @After 14 public void tearDown() throws Exception { 15 sqlSession.close(); 16 } 17 18 @Test 19 public void testInsertStudent() { 20 logger.info("测试insertStudent"); 21 Student stu = new Student("琪琪", 12); 22 int count = studentMapper.inertStudent(stu); 23 sqlSession.commit(); 24 } 25 26 @Test 27 public void testUpdateStudent() { 28 logger.info("测试updateStudent"); 29 Student stu = new Student("琪琪琪琪", 13); 30 stu.setId(16); 31 int count = studentMapper.updateStudent(stu); 32 sqlSession.commit(); 33 } 34 35 @Test 36 public void testDeleteStudent() { 37 logger.info("测试删除学生"); 38 int count = studentMapper.deleteStudent(16); 39 sqlSession.commit(); 40 } 41 42 @Test 43 public void testGetStudentById() { 44 logger.info("根据id查找学生"); 45 Student student = studentMapper.getStudentById(1); 46 System.out.println(student); 47 } 48 49 @Test 50 public void testFindStudents() { 51 logger.info("根据条件查找学生"); 52 Map<String,Object> map = new HashMap<String,Object>(); 53 // map.put("name", "%a%"); 54 map.put("age", 14); 55 List<Student> students = studentMapper.findStudents(map); 56 for(Student student: students){ 57 System.out.println(student); 58 } 59 } 60 }
View Code
相关文章推荐
- mybatis使用注解替代xml配置,动态生成Sql
- MyBatis 3(中文版) 第四章 使用注解配置SQL映射器
- MyBatis 3 使用注解配置SQL映射器
- Java Persistence with MyBatis 3(中文版) 第四章 使用注解配置SQL映射器
- MyBatis 3(中文版) 第四章 使用注解配置SQL映射器
- Mybatis SQL映射语句中参数注解使用规则
- ssm项目使用Mybatis动态拼接sql语句,生成的sql中文全部显示为???的问题(配置文件sql语句中文解析问题)
- MyBatis 注解使用动态SQL
- SpringBoot入门-20(springboot集成mybatis注解形式properties配置,利用@Provider实现动态SQL)
- SpringBoot使用Mybatis注解开发教程-分页-动态sql
- mybatis简单sql使用java注解而不是xml配置
- mybatis中关于使用注解来完成动态SQL拼接的解决办法
- MyBatis之使用XML配置SQL映射(二)CRUD映射配置
- 小峰mybatis(4)mybatis使用注解配置sql映射器
- MyBatis(三)配置文件,输入输出映射,动态SQL
- SpringBoot入门-21(springboot集成mybatis注解形式增删查改properties配置,利用@Provider实现动态SQL)
- SpringBoot使用Mybatis注解开发教程-分页-动态sql
- 三(二)mybatis接口映射sql使用注解
- MyBatis在注解上使用动态SQL(@select使用if)
- MyBatis(三)配置文件,输入输出映射,动态SQL