shop--11.前端展示系统--首页展示(后端)

概述

接下来我们来完成前端展示模块部分的功能

可以分析得出,主页中轮播图需要从后台加载数据,同样的一级类别(即parent_id = null )的商铺信息也需要从后台加载数据

HeadLineDao.java

1     /**
2      * 根据传入的查询条件(头条名查询头条)
3      * 
4      * @param headLineCondition
5      * @return
6      */
7     List<HeadLine> queryHeadLine(@Param("headLineCondition")HeadLine headLineCondition); 

HeadLineDao.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper 
  PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" 
  "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ryanxu.o2o.dao.HeadLineDao">
    <select id="queryHeadLine" resultType="com.ryanxu.o2o.entity.HeadLine">
        SELECT
        line_id,
        line_name,
        line_link,
        line_img,
        priority,
        enable_status,
        create_time,
        last_edit_time
        FROM
        tb_head_line
        <where>
            <if test="headLineCondition.enableStatus!=null">
                and enable_status = #{headLineCondition.enableStatus}
            </if>
        </where>
        ORDER BY
        priority DESC
    </select>

</mapper>

ShopCategoryDao.xml

因为之前的queryShopCategory 只支持返回parent_id不为空的情况 做个补充 加入parent_id可以为空的情况

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper 
  PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" 
  "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ryanxu.o2o.dao.ShopCategoryDao">
    <select id="queryShopCategory"
        resultType="com.ryanxu.o2o.entity.ShopCategory">
        SELECT
        shop_category_id,
        shop_category_name,
        shop_category_desc,
        shop_category_img,
        priority,
        create_time,
        last_edit_time,
        parent_id
        FROM
        tb_shop_category
        <where>
            <if test="shopCategoryCondition == null">
                and parent_id is null
            </if>
            <if test="shopCategoryCondition != null">
                and parent_id is not null
            </if>
            <if
                test="shopCategoryCondition !=null and shopCategoryCondition.parent!=null">
                and parent_id = #{shopCategoryCondition.parent.shopCategoryId}
            </if>
        </where>
        ORDER BY
        priority DESC
    </select>
</mapper>

HeadLineService.java

 1 public interface HeadLineService {
 2     /**
 3      * 根据传入的条件返回指定的头条列表
 4      * 
 5      * @param headLineCondition
 6      * @return
 7      * @throws IOException
 8      */
 9     List<HeadLine> getHeadLineList(HeadLine headLineCondition) throws IOException;
10 }

HeadLineServiceImpl.java

 1 @Service
 2 public class HeadLineServiceImpl implements HeadLineService{
 3 
 4     @Autowired
 5     private HeadLineDao headLineDao;
 6     
 7     @Override
 8     public List<HeadLine> getHeadLineList(HeadLine headLineCondition) throws IOException {
 9         return headLineDao.queryHeadLine(headLineCondition);
10     }
11     
12 }

MainPageController.java

 1 @Controller
 2 @RequestMapping(value="/frontend")
 3 public class MainPageController {
 4     @Autowired
 5     private HeadLineService headLineService;
 6     @Autowired
 7     private ShopCategoryService shopCategoryService;
 8     
 9     /**
10      * 初始化前端展示系统的主页信息,包括获取一级店铺类别列表以及头条列表
11      * 
12      * @return
13      */
14     @RequestMapping(value="/listmainpageinfo",method=RequestMethod.GET)
15     @ResponseBody
16     private Map<String, Object> listMainPageInfo(){
17         Map<String, Object> modelMap = new HashMap<String, Object>();
18         List<ShopCategory> shopCategoryList = new ArrayList<ShopCategory>();
19         try {
20             //获取以及店铺类别列表(即parentId为空的ShopCategory)
21             shopCategoryList = shopCategoryService.getShopCategoryList(null);
22             modelMap.put("shopCategoryList", shopCategoryList);
23         }catch (Exception e) {
24             modelMap.put("success", false);
25             modelMap.put("errMsg", e.getMessage());
26             return modelMap;
27         }
28         List<HeadLine> headLineList = new ArrayList<HeadLine>();
29         try {
30             //获取状态为可用(1)的头条列表
31             HeadLine headLineCondition = new HeadLine();
32             headLineCondition.setEnableStatus(1);
33             headLineList = headLineService.getHeadLineList(headLineCondition);
34             modelMap.put("headLineList", headLineList);
35         }catch (Exception e) {
36             modelMap.put("success", false);
37             modelMap.put("errMsg", e.getMessage());
38             return modelMap;
39         }
40         modelMap.put("success", true);
41         return modelMap;
42     }
43 }

猜你喜欢

转载自www.cnblogs.com/windbag7/p/9424961.html