SSM校园商铺平台(三)
1.从后台获取店铺类别和区域信息
1.1 dao层
- 如果传入的对象不为空,实例化对象,我们就显示所有的子类别,注意:最顶层父类别不会显示,最顶层父类别指的是parent_id为空
- 如果传入参数的parent,也就是父类别为空,就返回所有的ShopCategory;
- 如果不为空,就返回与传入参数的shopCategoryCondition相同父类别下的所有子类别.
public interface ShopCategoryDao {
List<ShopCategory> queryShopCategory(@Param("shopCategoryCondition")
ShopCategory shopCategoryCondition);
}
<mapper namespace="com.imooc.o2o.dao.ShopCategoryDao">
<select id="queryShopCategory" resultType="com.imooc.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 not null
</if>
<if test="shopCategoryCondition.parent!=null">
and parent_id = #{shopCategoryCondition.parent.shopCategoryId}
</if>
</where>
order by priority desc
</select>
</mapper>
1.2 service层
public interface ShopCategoryService {
List<ShopCategory> getShopCategoryList(ShopCategory shopCategory);
}
@Service
public class ShopCategoryServiceImpl implements ShopCategoryService {
@Autowired
private ShopCategoryDao shopCategoryDao;
@Override
public List<ShopCategory> getShopCategoryList(ShopCategory shopCategory) {
return shopCategoryDao.queryShopCategory(shopCategory);
}
}
1.3 controller层
还是写在ShopManagementController.java文件中,因为他们访问的根路径都是 /admin
- 获取shopCategoryList和areaList
- 将这两个list放到一个容器modelMap中
- 将modelMap包装成JSON数据类型,发送到前台
@RequestMapping(value="/getshopinitinfo",method= {
RequestMethod.GET})
@ResponseBody
private Map<String,Object> getShopInitInfo(){
Map<String,Object> modelMap = new HashMap<String, Object>();
List<ShopCategory> shopCategoryList = new ArrayList<ShopCategory>();
List<Area> areaList