zoukankan      html  css  js  c++  java
  • 写模块的流程例子

    添加商品-类目选择

    1.1 分析

    商品类目使用的表:tb_item_cat

    初始化类目选择:

    Easyui的异步tree控件:

    请求的url/item/cat/list

    请求的参数:id(当前节点的id

    响应的结果:json数据。

    [{    

        "id": 1,    

        "text": "Node 1",    

    "state": "closed"

     }

    {    

        "id": 2,    

        "text": "Node 2",    

    "state": "closed"

     }

    ]

    如果当前节点为父节点,state应为“closed”、如果是叶子节点“open

    1.2 Dao

    查询tb_item_cat表,根据id查询商品分类列表。可以使用逆向工程。

    1.3 Service

    1.3.1 分析

    接收参数parentId,根据parentId查询分类列表。返回pojo列表。

    Pojo应该包含三个属性:

    idtextstate

    应该放到taotao-common工程中。

    public class EasyUITreeNode {

    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;

    }

    }

    1.3.2 代码实现

    @Service

    public class ItemCatServiceImpl implements ItemCatService {

    @Autowired

    private TbItemCatMapper itemCatMapper;

    @Override

    public List<EasyUITreeNode> getItemCatList(long parentId) {

    // 根据parentId查询分类列表

    TbItemCatExample example = new TbItemCatExample();

    //设置查询条件

    Criteria criteria = example.createCriteria();

    criteria.andParentIdEqualTo(parentId);

    //执行查询

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

    //转换成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);

    }

    return resultList;

    }

    }

    1.4 Controller

    接收参数,parentId。调用Service查询分类类别,返回列表(json数据),需要使用@ResponseBody

    请求的url/item/cat/list

    @Controller

    @RequestMapping("/item/cat")

    public class ItemCatController {

    @Autowired

    private ItemCatService itemCatService;

    @RequestMapping("/list")

    @ResponseBody

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

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

    return list;

    }

    }

  • 相关阅读:
    Linux 网络编程六(socket通信UDP版)
    Redis 集群方案介绍
    华为交换机STP 根ID优先级设置
    Pacemaker+Corosync搭建PostgreSQL集群
    SpookyOTP
    世界级的开源项目:TiDB 如何重新定义下一代关系型数据库
    TiDB
    Fiddler显示响应时间 显示服务器IP
    DNS记录类型名单
    Django models中关于blank与null
  • 原文地址:https://www.cnblogs.com/minconding/p/9938356.html
Copyright © 2011-2022 走看看