- 平时项目中不可避免的会使用多表关联查询。
public R selectPersonInfo(){
//mybatis会自动把重复数据合并组装。不重复数据放入list中
List<DemoPersion> demoPersions = demoUserDao.selectPersonInfo("120928001");
return R.ok(demoPersions);
}
xml文件的写法
<resultMap type="com.standard.modules.demo.entity.DemoPersion" id="demoPerson">
<result property="collectId" column="COLLECT_ID"></result>
<!-- 一对多关系 -->
<collection property="staPostList" ofType="com.standard.modules.homepage.entity.StaPostEntity"
javaType="java.util.List">
<result property="isMainPost" column="IS_MAIN_POST"></result>
<result property="postCode" column="POST_CODE"></result>
<result property="postName" column="POST_NAME"></result>
</collection>
</resultMap>
<select id="selectTest" resultMap="demoUserString">
select 'test_success' test from dual
</select>
<select id="selectPersonInfo" parameterType="java.lang.String" resultMap="demoPerson">
SELECT cp.COLLECT_TAG,cp.COLLECT_ID
,po.IS_MAIN_POST,po.POST_CODE,po.POST_NAME
FROM sta_collect_person cp
left JOIN sta_post po on cp.COLLECT_ID = po.EMPLID
WHERE cp.EMPLID = ${emplid}
</select>
-
分页插件的使用,使用pagehelper
package com.standard.config; import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor; import com.github.pagehelper.PageHelper; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import java.util.Properties; /** * mybatis-plus配置 * */ @Configuration public class MybatisPlusConfig { /** * 分页插件 */ @Bean public PaginationInterceptor paginationInterceptor() { return new PaginationInterceptor(); } @Bean public PageHelper pageHelper(){ PageHelper pageHelper = new PageHelper(); Properties properties = new Properties(); properties.setProperty("offsetAsPageNum","true"); properties.setProperty("rowBoundsWithCount","true"); properties.setProperty("reasonable","true"); // properties.setProperty("dialect","mysql"); //配置mysql数据库的方言 pageHelper.setProperties(properties); return pageHelper; } }
//代码中直接使用 public R queryLowMark(@RequestBody CollectPersonParam collectPersonParam) { Page<Object> result=PageHelper.startPage(collectPersonParam.getPageNum(), collectPersonParam.getPageSize(),true); List<StaCollectPersonDTO> list=staHomeService.queryLowMark(); PageInfo<Object> pageInfo = new PageInfo<>(result.getResult()); return R.ok(pageInfo); }
网友评论