一、分析
二、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。