我们学到现在基本上都是基本面向接口编程
为什么?
为了解耦
在UserMapper中
@Select("select * from User")List<User> getUsers();//返回值是List<User> //User对象(这是我自己创建的一个类)
然后我们在mybatis-config.xml里绑定接口
<mappers> <mapper resource="com/zou/dao/UserMapper.xml"/></mappers>
然后我们编写测试类
public class UserMapperTest { //查询所有用户和密码 @Test public void test(){ SqlSession sqlSession = MybatisUtils.getSession(); UserMapper mapper = sqlSession.getMapper(UserMapper.class); List<User> users = mapper.getUsers(); for(User user:users){ System.out.println(user); } sqlSession.close(); }}
来源:https://www.cnblogs.com/tuyaojiao/p/12378719.html