2.2.实现步骤:
1、按钮添加点击事件,弹出窗口,加载数据显示tree
2、将选择类目的组件封装起来,通过TT.iniit()初始化,最终调用initItemCat()方法进行初始化
3、创建数据库、以及tb _item_cat表,初始化数据
4、编写Controller、Service、Mapper
2.3.EasyUI tree数据结构
数据结构中必须包含:
Id:节点id
Text:节点名称
State:如果不是叶子节点就是close,叶子节点就是open。Close的节点点击后会在此发送请求查询子项目。
可以根据parentid查询分类列表。
2.4.Mapper
使用逆向工程生成的mapper文件。
2.5.Service
@Service
public class ItemCatServiceImpl implements ItemCatService {
@Autowired
private TbItemCatMapper itemCatMapper;
@Override
public List getItemCatList(Long parentId) throws Exception {
TbItemCatExample example = new TbItemCatExample();
//设置查询条件
Criteria criteria = example.createCriteria();
//根据parentid查询子节点
criteria.andParentIdEqualTo(parentId);
//返回子节点列表
List list = itemCatMapper.selectByExample(example);
return list;
}
}
2.6.Controller
@Controller
@RequestMapping(“/item/cat”)
public class ItemCatController {
@Autowired
private ItemCatService itemCatService;
@SuppressWarnings({ “rawtypes”, “unchecked” })
@RequestMapping(“/list”)
@ResponseBody
//如果id为null是使用默认值,也就是parentid为0的分类列表
public List categoryList(@RequestParam(value=”id”, defaultValue=”0”) Long parentId) throws Exception {
List catList = new ArrayList();
//查询数据库
List list = itemCatService.getItemCatList(parentId);
for (TbItemCat tbItemCat : list) {
Map node = new HashMap
UI
最新推荐文章于 2024-01-15 15:10:52 发布