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
业务逻辑:
- 根据parentId查询节点列表
- 转换成EasyUITreeNode列表。
- 返回。
返回值: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。