多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
[TOC] 在pojo包下创建QueryVo类 ~~~ package pojo; import java.io.Serializable; public class QueryVo implements Serializable { private static final long serialVersionUID = 1L; private User user; public User getUser() { return user; } public void setUser(User user) { this.user = user; } } ~~~ UserMapper类的接口 ~~~ public List<User> findUserByQueryVo(QueryVo vo); ~~~ 然后我们写sql ~~~ <!-- 根据用户名,模糊查询 --> <select id="findUserByQueryVo" parameterType="QueryVo" resultType="pojo.User"> select * from user where username like "%"#{user.username}"%" </select> ~~~ 测试 ~~~ @Test public void testQueryVo() throws Exception { // 加载核心配置文件 String resource = "sqlMapConfig.xml"; InputStream in = Resources.getResourceAsStream(resource); // 创建SqlSessionFactory SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(in); // 创建SqlSession SqlSession sqlSession = sqlSessionFactory.openSession(); // SqlSEssion帮我生成一个实现类 (给接口) UserMapper userMapper = sqlSession.getMapper(UserMapper.class); QueryVo vo = new QueryVo(); User user = new User(); user.setUsername("五"); vo.setUser(user); List<User> us = userMapper.findUserByQueryVo(vo); for (User u : us) { System.out.println(u); } } ~~~