SSM博客系统(博客类型的增删改)
SSM博客系统
博客类型的增删改
BlogTypeAdminController
/**
* 添加,更新博客类别信息
* @throws Exception
*/
@RequestMapping({
"/save"})
public String save(BlogType blogType,HttpServletResponse response) throws Exception {
int resultTotal=0;
//如果传过来的是空的id那么就是新增
if(blogType.getId()==null) {
//添加
resultTotal=blogTypeService.add(blogType).intValue();
}else {
//更新
resultTotal=blogTypeService.update(blogType).intValue();
}
JSONObject result=new JSONObject();
if(resultTotal>0) {
result.put("success", Boolean.valueOf(true));
}else {
result.put("success", Boolean.valueOf(false));
}
ResponseUtil.write(response, result);
return null;
}
/**
* 删除博客类别
*/
@RequestMapping({
"/delete"})
public String delete(@RequestParam("ids")String ids,HttpServletResponse response) throws Exception {
String[] idsStr =ids.split(",");
for(int i=0;i<idsStr.length;i++) {
blogTypeService.delete(Integer.valueOf(idsStr[i]));//要传入的是Integer,这里是String
}
JSONObject result=new JSONObject();
result.put("success", Boolean.valueOf(true));
ResponseUtil.write(response, result);
return null;
}
博客类别管理界面
结尾小插曲-Bug
Cannot delete or update a parent row: a foreign key constraint fails (db_blog.t_blog, CONSTRAINT t_blog_ibfk_1 FOREIGN KEY (typeId) REFERENCES t_blogtype (id))–无法删除或更新父行:外键约束失败(’ db_blog ‘。外键约束为’ typeId ‘引用’ t_blogtype ’ (’ id ))
因为之前删除的那个博客类型有博客外键约束 所以无法删除
