商品类目选择

1.商品类目选择

1.1原形

1.2功能分析

展示商品分类列表,使用EasyUI的tree控件展示。

初始化tree请求的url:/item/cat/list

参数:

初始化tree时只需要把第一级节点展示,子节点异步加载。

long id(父节点id)

返回值:json。数据格式

[{   

    "id": 1,   

    "text": "Node 1",   

    "state": "closed"

},{   

    "id": 2,   

    "text": "Node 2",   

    "state": "closed"  

}]
state:如果节点下有子节点“closed”,如果没有子节点“open”

创建一个pojo来描述tree的节点信息,包含三个属性id、text、state。放到e3-common工程中。

public class EasyUITreeNode implements Serializable{

 

      private long id;

      private String text;

      private String state;

      public long getId() {

            return id;

      }

      public void setId(long id) {

            this.id = id;

      }

      public String getText() {

            return text;

      }

      public void setText(String text) {

            this.text = text;

      }

      public String getState() {

            return state;

      }

      public void setState(String state) {

            this.state = state;

      }

     

}

 

查询的表:

tb_item_cat

查询列:

Id、name、isparent

查询条件parentId

1.3Dao层

tb_item_cat

可以使用逆向工程生成的代码

1.4Service层

参数:long parentId

业务逻辑:

  1. 根据parentId查询节点列表
  2. 转换成EasyUITreeNode列表。
  3. 返回。

返回值:List<EasyUITreeNode>

@Service

public class ItemCatServiceImpl implements ItemCatService {

 

      @Autowired

      private TbItemCatMapper itemCatMapper;

     

     

      @Override

      public List<EasyUITreeNode> getCatList(long parentId) {

            // 1、根据parentId查询节点列表

            TbItemCatExample example = new TbItemCatExample();

            //设置查询条件

            Criteria criteria = example.createCriteria();

            criteria.andParentIdEqualTo(parentId);

            List<TbItemCat> list = itemCatMapper.selectByExample(example);

            // 2、转换成EasyUITreeNode列表。

            List<EasyUITreeNode> resultList = new ArrayList<>();

            for (TbItemCat tbItemCat : list) {

                  EasyUITreeNode node = new EasyUITreeNode();

                  node.setId(tbItemCat.getId());

                  node.setText(tbItemCat.getName());

                  node.setState(tbItemCat.getIsParent()?"closed":"open");

                  //添加到列表

                  resultList.add(node);

            }

            // 3、返回。

            return resultList;

      }

 

}

1.5发布服务

applicationContext-service.xml

springmvc.xml

1.6Controller

初始化tree请求的url:/item/cat/list

参数:

long id(父节点id)

返回值:json。数据格式

 List<EasyUITreeNode>

@Controller

public class ItemCatController {

 

      @Autowired

      private ItemCatService itemCatService;

      @RequestMapping("/item/cat/list")

      @ResponseBody

      public List<EasyUITreeNode> getItemCatList(@RequestParam(value="id", defaultValue="0")Long parentId) {

           

            List<EasyUITreeNode> list = itemCatService.getCatList(parentId);

            return list;

      }

}

2.图片上传

集群环境:

解决方案:

搭建一个图片服务器,专门保存图片。可以使用分布式文件系统FastDFS。

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值