1 public class Person extends PersonOthers{} 2 public class PersonOthers{private List<Map<String,String>> otherList;}
1 public class PersonService { 2 3 @Resource 4 private PersonDao dao; 5 6 public List<Person> selectPlusQuery(QueryPersonDto query, Page<Person> page) { 7 String sql = "SELECT * FROM t_person_info"; 8 QueryWrapper<Person> qw = new QueryWrapper<>(); 9 if (null != query) { 10 String keyword = query.getKeyword(); 11 if (StringUtils.isNotBlank(keyword)) qw.like("person_name", keyword); 12 } 13 return dao.selectPlusQuery(sql, page, qw); 14 } 15 }
@Repository public interface PersonDao { /** * Mybatis注解 + xml(没法省?) + mybatis-plus 条件查询、分页 * @param sql 自定义sql * @param page 分页查询 * @param queryWrapper mybatis-plus条件构造器 */ @Results({ @Result(property = "otherList", javaType = List.class, column = "pid" ,many = @Many(select = "selectOtherByPid")) }) @Select("${sql} ${ew.customSqlSegment}") List<Person> selectPlusQuery(@Param("sql") String sql, Page<Person> page, @Param(Constants.WRAPPER) QueryWrapper<Person> queryWrapper); }
<resultMap id="BaseResultMap" type="*.Person"> <id column="id" property="id"/> <result column="pid" property="pid"/> <!-- ... --> <collection property="otherList" javaType="List" ofType="map" select="selectOtherByPid" column="pid"> <!-- javaType:对应Person属性otherList的类型,可以不写; ofType:对应嵌套sql中的resultType; select: 对应文件中的select标签id; column:对应主表中的字段(嵌套sql中的参数字段:#{pid}); --> </collection> </resultMap> <select id="selectOtherByPid" resultType="map"> SELECT * FROM t_other AS o WHERE o.pid = #{pid} </select>
jrebel-mybatisplus 下载地址 ,然后在git命令窗依次执行以下命令:
1 git clone */jrebel-mybatisplus.git 2 cd jrebel-mybatisplus 3 mvn -f pom.xml clean package
将构建好的插件jrebel-mybatisplus argetjr-mybatisplus-*.jar拷贝至任意目录dir
修改运行配置,增加VM参数:-Drebel.plugins=dirjr-mybatisplus-*.jar,然后以JRebel方式启动
修改你项目中的mapper xml 文件后,重新编译,如果重新请求接口,你应该会看到控制台输出 “Reloading SQL maps”