1 package com.hanking.dao; 2 3 import com.hanking.pojo.User; 4 import com.hanking.utils.MybatisUtils; 5 import org.apache.ibatis.session.SqlSession; 6 import org.junit.Test; 7 8 import java.util.List; 9 10 public class MybatisTest { 11 @Test 12 public void getAllUser(){ 13 SqlSession sqlSession = MybatisUtils.getSqlSession(); 14 UserMapper mapper = sqlSession.getMapper(UserMapper.class); 15 List<User> allUser = mapper.getAllUser(); 16 for (User u : 17 allUser) { 18 System.out.println(u); 19 } 20 sqlSession.close(); 21 } 22 @Test 23 public void getById(){ 24 SqlSession sqlSession = MybatisUtils.getSqlSession(); 25 UserMapper mapper = sqlSession.getMapper(UserMapper.class); 26 User byId = mapper.getById(1); 27 System.out.println(byId); 28 sqlSession.close(); 29 } 30 @Test 31 public void getListUserByLike(){ 32 SqlSession sqlSession = MybatisUtils.getSqlSession(); 33 UserMapper mapper = sqlSession.getMapper(UserMapper.class); 34 List<User> list = mapper.getListUserByLike("管理"); 35 for (User u : 36 list) { 37 System.out.println(u); 38 } 39 sqlSession.close(); 40 } 41 }