您的位置:首页 > 其它

购物商城---开发流程--获取品牌列表

2017-04-18 15:45 134 查看
controller

// 品牌列表页面
@RequestMapping(value = "/brand/list.do")
// pageNo 传入的页面号码
public String list(String name, Integer isDisplay, Integer pageNo, ModelMap model) {
Brand brand = new Brand();
// sb 拼接页面请求参数
StringBuilder sb = new StringBuilder();

// 空串notblank "" null

if (StringUtils.isNotBlank(name)) {
brand.setName(name);
sb.append("name=").append(name);
}
if (isDisplay != null) {
brand.setIsDisplay(isDisplay);
sb.append("&").append("isDisplay=").append(isDisplay);
}else{
brand.setIsDisplay(1);
sb.append("&").append("isDisplay=1");
}

// 页号 如果pageNo<1 或为null 设置pageNo=1
brand.setPageNo(Pagination.cpn(pageNo));
// 每页数
brand.setPageSize(5);
// 分页对象,调用service层获取数据
Pagination pagination = brandService.getBrandListWithPage(brand);
// 页面展示
String url = "/brand/list.do";

pagination.pageView(url, sb.toString());
// 返回给页面
model.addAttribute("pagination", pagination);// 底层request.setAttribute实现
model.addAttribute("isDisplay", brand.getIsDisplay());// 底层request.setAttribute实现
model.addAttribute("name", name);// 底层request.setAttribute实现
return "brand/list";
}


Pagination pagination = brandService.getBrandListWithPage(brand);

public Pagination getBrandListWithPage(Brand brand) {
// 1:页号
// 2:每页数
// 3:总记录数
Pagination Pagination = new Pagination(brand.getPageNo(), brand.getPageSize(), brandDao.getBrandCount(brand));
// 品牌数据集合//调用dao层获取数据
Pagination.setList(brandDao.getBrandListWithPage(brand));

return Pagination;
}


brandDao.getBrandListWithPage(brand)

// list集合
public List<Brand> getBrandListWithPage(Brand brand);


调用mybatis

<!--#{isDisplay}获取对象字段值 -->
<!-- 查询品牌 get* -->
<select id="getBrandListWithPage" parameterType="Brand"
resultMap="brand">
select id,name,description,img_url,web_site,sort,is_display
from
bbs_brand
<where>
<if test="isDisplay != null">
is_display=#{isDisplay}
</if>
<if test="name != null">
and name=#{name}
</if>
</where>
order by id desc
limit #{startRow},#{pageSize}
</select>


最后将数据返回
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐