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命令窗依次執行如下命令:html
1 git clone */jrebel-mybatisplus.git 2 cd jrebel-mybatisplus 3 mvn -f pom.xml clean package
將構建好的插件jrebel-mybatisplus\target\jr-mybatisplus-*.jar拷貝至任意目錄dirjava
修改運行配置,增長VM參數:-Drebel.plugins=dir\jr-mybatisplus-*.jar,而後以JRebel方式啓動git
修改你項目中的mapper xml 文件後,從新編譯,若是從新請求接口,你應該會看到控制檯輸出 「Reloading SQL maps」github
原文出處:https://www.cnblogs.com/andea/p/11692032.htmlsql