第一步:先获取到参数 (id)
//控制层
@Autowired
DemoDemoService demoDemoService ;
public Page<DemoDemoEntity > listData(DemoDemoEntity demoDemoEntity , HttpServletRequest request, HttpServletResponse response) {
String id=demoEntity.getId();
Page<DemoDemoEntity > page=new Page<>(request,response);
psge.setPageSize(10);
page=demoDemoService .findfage(id);
return page;}
//业务层
@Autowired
DemoDao demoDao;
public Page<DemoDemoEntity > findfage(String id){
Page<DemoDemoEntity > page=new Page<>();
List<DemoDemoEntity > list=new List<>();
//这里需要对id进行判断是否为blank,注意不是null
if(StringUtils.isBlank(id)){
list =demoDao.findAll();
}else{
list =demoDao.findOne(id);
}
page.setList(list); //根据查询结果封装类型,也可以是map型
return page;
}
//数据层
@Select(select * from demo group by xxx)
List<DemoDemoEntity > findAll();
List<DemoDemoEntity > findOne(@Param(id)String id); //注意当在where内请添加@Param
//xml文件内
<resultMap type="XXXXX.XXXXX.XXXX.DemoEntity" id="自定义">
<result property="id" column="id"/>
<result property="demoTimes" column="demo_times"/>
</resultMap>
<select id="findone" parameterType="java.lang.String" resultMap="自定义(与上一致)">
select a.id,count(create_time) as demoTimes from demo a
<where>
<if test="id!=null and id!=''">
a.id=#{id}
</if>
GROUP BY a.id
</where>
</select>