一、分析
二、dao
内容分类表的主键id是子增长的。另外,前端需要这个id返回。需要修改一下逆向工程生成的代码,添加主键返回。
keyProperty="id", 这个id指的是返回的值放到pojo的哪个属性中去。
resultType别名:java.lang.Long--long, long--_long.
insert id="insert"和insert id="insertSelective"的区别在于,前者有null值会插入,后者有null值不会插入。e3-manager-dao->maven->install
三、service
public E3Result addContentCategory(long parentId, String name) {
// 创建一个pojo对象
TbContentCategory contentCategory = new TbContentCategory();
// 设置属性
contentCategory.setParentId(parentId);
contentCategory.setName(name);
// 1(正常),2(删除)
contentCategory.setStatus(1);
// 默认排序就是1
contentCategory.setSortOrder(1);
contentCategory.setCreated(new Date());
contentCategory.setUpdated(new Date());
// 新添加的节点一定是叶子节点。
contentCategory.setIsParent(false);
// 插入到数据库
contentCategoryMapper.insert(contentCategory);
// 判断父节点的isParent属性。如果不是true改为true。
// 根据parentId查询父节点
TbContentCategory parent = contentCategoryMapper.selectByPrimaryKey(parentId);
if (!parent.getIsParent()) {
parent.setIsParent(true);
// 更新到数据库中
contentCategoryMapper.updateByPrimaryKey(parent);
}
// 返回结果,返回E3Result,包含pojo
return E3Result.ok(contentCategory);
}
e3-content-interface maven install
四、web
该重启的重启
删除功能。只允许删除叶子节点。删除了叶子节点,要判断父节点是否还有其他子节点,如果没有,就要修改isParent。