-
Notes on UserMapper interface, do not write a Mapper.xml
@Select(value = "select * from user") List<User> getUsers();
-
Bind the interface to the core configuration file!
<!--绑定接口--> <mappers> <mapper class="com.tt.dao.UserMapper"/> </mappers>
-
test
public class UserMapperTest {
@Test
public void test(){
SqlSession sqlSession = MyBatisUtils.getSqlSession();
//底层主要应用反射
UserMapper mapper = sqlSession.getMapper(UserMapper.class);
List<User> users = mapper.getUsers();
for (User user : users) {
System.out.println(user);
}
sqlSession.close();
}
}
Notes that the nature of reflection