Mybatis 通用 Mapper 3.4.6 已发布。MyBatis 通用 Mapper 极其方便的使用 MyBatis 单表的增删改查,支持单表操作,不支持通用的多表联合查询。通用 Mapper 可以极大的方便开发人员。可以随意的按照自己的需要选择通用方法,还可以很方便的开发自己的通用方法。 3.4.6 Example 新增 builder 模式(by Ngone51) 一个简单的 builder 用法示例: /* * @description: 多个where连接的查询语句测试 * */ @test public void testWhereAndWhereCompound() { SqlSession sqlSession = MybatisHelper.getSqlSession(); try { CountryMapper mapper = sqlSession.getMapper(CountryMapper.class); Example example = Example.builder(Country.class) .where(Sqls.custom() .andEqualTo("countryname", "China") .andEqualTo("id", 35) ) .andWhere(Sqls.custom() .andEqualTo("id", 183) ) .build(); List<Country> countries = mapper.selectByExample(example); Assert.assertEquals(0, countries.size()); } finally { sqlSession.close(); } } 更多用法可以通过测试 TestExampleBuilder 了解。 使用 Maven <dependency> <groupId>tk.mybatis</groupId> <artifactId>mapper</artifactId> <version>3.4.6</version> </dependency> 如果你使用 Spring Boot 可以直接引入: <dependency> <groupId>tk.mybatis</groupId> <artifactId>mapper-spring-boot-starter</artifactId> <version>1.1.7</version> </dependency> Mybatis 通用 Mapper 3.4.6: Example 新增 builder 模式下载地址