Mybatis-plus 一对多关联查询,附JRebel热加载mapper.xml

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 }
@Service
@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); }
@Mapper
<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>
mapper.xml

 

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

相关文章
相关标签/搜索