概述
进入owner拥有的店铺列表后,对某个店铺进行管理,其中类别管理模块的效果如上。所以获取商品类别的时候要传入shopId.
通过前面的博客,我们对开发流程有了较为清晰的认识,这里我们将类别管理这部分的内容从下至上来实现下吧。
Dao层
ProductCategoryDao接口
package com.imooc.o2o.dao;
import java.util.List;
import com.imooc.o2o.entity.ProductCategory;
public interface ProductCategoryDao {
List<ProductCategory> selectProductCategoryList(long shopId);
}
ProductCategoryDao Mapper配置文件
<?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.artisan.o2o.dao.ProductCategoryDao">
<select id="selectProductCategoryList" resultType="ProductCategory">
SELECT
tpc.product_category_id,
tpc.product_category_name,
tpc.product_category_desc,
tpc.priority,
tpc.create_time,
tpc.last_edit_time,
tpc.shop_id
FROM
tb_product_category tpc
WHERE
tpc.shop_id = #{
shopId}
ORDER BY
priority
DESC
</select>
</mapper>
单元测试
/**
* 测试查询
* @throws Exception
*/
@Test
public void testselectProductList() throws Exception {
long shopId = 29;
List<ProductCategory> productCategoryList = productCategoryDao.selectProductList(shopId);
System.out.println("该店铺自定义类别数为:" + productCategoryList.size());
for (ProductCategory productCategory :productCategoryList) {
System.out.println(productCategory.toString());
}
}
Service层
ProductCategoryService 接口
package com.artisan.o2o.service;
import java.util.List;
import com.imooc.o2o.entity.ProductCategory;
public interface ProductCategoryService {
List<ProductCategory> queryProductCategoryList(long shopId);
}
ProductCategoryServiceImpl接口实现类
package com.imooc.o2o.service.impl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.imooc.o2o.dao.ProductCategoryDao;
import com.imooc.o2o.entity.ProductCategory;
import com.imooc.o2o.service.ProductCategoryService;
/**
*
*
* @ClassName: ProductCategoryServiceImpl
*
* @Description: 使用@Service,交由Spring托管
*
* @author: Mr.Yang
*
* @date: 2018年6月9日 上午2:46:07
*/
@Service
public class ProductCategoryServiceImpl implements ProductCategoryService {
@Autowired
private ProductCategoryDao productCategoryDao;
@Override
public List<ProductCategory> queryProductCategoryList(long shopId) {
return productCategoryDao.selectProductCategoryList(shopId);
}
}