统一zheng-cms返回结果

This commit is contained in:
shuzheng 2017-02-20 13:16:35 +08:00
parent a8dc6cf6fa
commit 6122e68e5a
6 changed files with 195 additions and 333 deletions

View File

@ -1,10 +1,11 @@
package com.zheng.cms.admin.controller.manage;
import com.zheng.cms.common.constant.CmsResult;
import com.zheng.cms.common.constant.CmsResultConstant;
import com.zheng.cms.dao.model.CmsArticle;
import com.zheng.cms.dao.model.CmsArticleExample;
import com.zheng.cms.rpc.api.CmsArticleService;
import com.zheng.common.base.BaseController;
import com.zheng.common.util.Paginator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
@ -13,13 +14,12 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 文章控制器
@ -27,7 +27,7 @@ import java.util.List;
*/
@Controller
@RequestMapping("/manage/article")
@Api(value = "文章控制器", description = "文章管理")
@Api(value = "文章管理", description = "文章管理")
public class CmsArticleController extends BaseController {
private final static Logger _log = LoggerFactory.getLogger(CmsArticleController.class);
@ -35,91 +35,65 @@ public class CmsArticleController extends BaseController {
@Autowired
private CmsArticleService cmsArticleService;
/**
* 列表
* @param page 当前页码
* @param rows 每页条数
* @param desc 降序排序
* @param request
* @param modelMap
* @return
*/
@ApiOperation(value = "文章列表", notes = "获取文章列表并分页")
@ApiOperation(value = "文章首页")
@RequiresPermissions("cms:article:read")
@RequestMapping(value = "/index", method = RequestMethod.GET)
public String index() {
return "/manage/article/index";
}
@ApiOperation(value = "文章列表")
@RequiresPermissions("cms:article:read")
@RequestMapping(value = "/list", method = RequestMethod.GET)
public String list(
@RequestParam(required = false, defaultValue = "1", value = "page") int page,
@RequestParam(required = false, defaultValue = "20", value = "rows") int rows,
@RequestParam(required = false, defaultValue = "true", value = "desc") boolean desc,
HttpServletRequest request, ModelMap modelMap) {
// 数据列表
@ResponseBody
public Object list(
@RequestParam(required = false, defaultValue = "0", value = "offset") int offset,
@RequestParam(required = false, defaultValue = "10", value = "limit") int limit,
@RequestParam(required = false, value = "sort") String sort,
@RequestParam(required = false, value = "order") String order) {
CmsArticleExample cmsArticleExample = new CmsArticleExample();
cmsArticleExample.setOffset((page - 1) * rows);
cmsArticleExample.setLimit(rows);
cmsArticleExample.setOrderByClause(desc ? "orders desc" : "orders asc");
List<CmsArticle> articles = cmsArticleService.selectByExample(cmsArticleExample);
// 分页对象
cmsArticleExample.setOffset(offset);
cmsArticleExample.setLimit(limit);
if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)) {
cmsArticleExample.setOrderByClause(sort + " " + order);
}
List<CmsArticle> rows = cmsArticleService.selectByExample(cmsArticleExample);
long total = cmsArticleService.countByExample(cmsArticleExample);
Paginator paginator = new Paginator(total, page, rows, request);
modelMap.put("articles", articles);
modelMap.put("paginator", paginator);
return "/manage/article/list";
Map<String, Object> result = new HashMap<>();
result.put("rows", rows);
result.put("total", total);
return result;
}
/**
* 新增get
* @return
*/
@ApiOperation(value = "新增文章", notes = "新增文章页")
@ApiOperation(value = "新增文章")
@RequiresPermissions("cms:article:create")
@RequestMapping(value = "/create", method = RequestMethod.GET)
public String add() {
public String create() {
return "/manage/article/create";
}
/**
* 新增post
* @param cmsArticle
* @param modelMap
* @return
*/
@ApiOperation(value = "新增文章", notes = "新增文章提交接口")
@ApiOperation(value = "新增文章")
@RequiresPermissions("cms:article:create")
@RequestMapping(value = "/create", method = RequestMethod.POST)
public String add(CmsArticle cmsArticle, ModelMap modelMap) {
@ResponseBody
public Object create(CmsArticle cmsArticle) {
long time = System.currentTimeMillis();
cmsArticle.setCtime(time);
cmsArticle.setOrders(time);
int count = cmsArticleService.insertSelective(cmsArticle);
modelMap.put("count", count);
return "redirect:/manage/article/list";
return new CmsResult(CmsResultConstant.SUCCESS, count);
}
/**
* 删除
* @param ids
* @param modelMap
* @return
*/
@ApiOperation(value = "删除文章", notes = "批量删除文章")
@ApiOperation(value = "删除文章")
@RequiresPermissions("cms:article:delete")
@RequestMapping(value = "/delete/{ids}",method = RequestMethod.GET)
public String delete(@PathVariable("ids") String ids, ModelMap modelMap) {
@ResponseBody
public Object delete(@PathVariable("ids") String ids) {
int count = cmsArticleService.deleteByPrimaryKeys(ids);
modelMap.put("count", count);
return "redirect:/manage/article/list";
return new CmsResult(CmsResultConstant.SUCCESS, count);
}
/**
* 修改get
* @param id
* @param modelMap
* @return
*/
@ApiOperation(value = "修改文章", notes = "根据id修改文章页")
@ApiOperation(value = "修改文章")
@RequiresPermissions("cms:article:update")
@RequestMapping(value = "/update/{id}", method = RequestMethod.GET)
public String update(@PathVariable("id") int id, ModelMap modelMap) {
@ -127,22 +101,15 @@ public class CmsArticleController extends BaseController {
modelMap.put("article", article);
return "/manage/article/update";
}
/**
* 修改post
* @param id
* @param cmsArticle
* @param modelMap
* @return
*/
@ApiOperation(value = "修改文章", notes = "根据id修改文章提交接口")
@ApiOperation(value = "修改文章")
@RequiresPermissions("cms:article:update")
@RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
public String update(@PathVariable("id") int id, CmsArticle cmsArticle, ModelMap modelMap) {
@ResponseBody
public Object update(@PathVariable("id") int id, CmsArticle cmsArticle) {
cmsArticle.setArticleId(id);
int count = cmsArticleService.updateByPrimaryKeySelective(cmsArticle);
modelMap.put("count", count);
modelMap.put("id", id);
return "redirect:/manage/article/list";
return new CmsResult(CmsResultConstant.SUCCESS, count);
}

View File

@ -1,12 +1,12 @@
package com.zheng.cms.admin.controller.manage;
import com.zheng.cms.common.constant.CmsResult;
import com.zheng.cms.common.constant.CmsResultConstant;
import com.zheng.cms.dao.model.CmsCategory;
import com.zheng.cms.dao.model.CmsCategoryExample;
import com.zheng.cms.rpc.api.CmsCategoryService;
import com.zheng.common.base.BaseController;
import com.zheng.common.util.Paginator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
@ -14,13 +14,12 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 类目控制器
@ -28,7 +27,7 @@ import java.util.List;
*/
@Controller
@RequestMapping("/manage/category")
@Api(value = "类目控制器", description = "类目管理")
@Api(value = "类目管理", description = "类目管理")
public class CmsCategoryController extends BaseController {
private final static Logger _log = LoggerFactory.getLogger(CmsCategoryController.class);
@ -36,92 +35,65 @@ public class CmsCategoryController extends BaseController {
@Autowired
private CmsCategoryService cmsCategoryService;
/**
* 列表
* @param page 当前页码
* @param rows 每页条数
* @param desc 降序排序
* @param request
* @param modelMap
* @return
*/
@ApiOperation(value = "类目列表", notes = "获取类目列表并分页")
@ApiOperation(value = "类目首页")
@RequiresPermissions("cms:category:read")
@RequestMapping(value = "/index", method = RequestMethod.GET)
public String index() {
return "/manage/category/index";
}
@ApiOperation(value = "类目列表")
@RequiresPermissions("cms:category:read")
@RequestMapping(value = "/list", method = RequestMethod.GET)
public String list(
@RequestParam(required = false, defaultValue = "1", value = "page") int page,
@RequestParam(required = false, defaultValue = "20", value = "rows") int rows,
@RequestParam(required = false, defaultValue = "false", value = "desc") boolean desc,
HttpServletRequest request, ModelMap modelMap) {
// 数据列表
@ResponseBody
public Object list(
@RequestParam(required = false, defaultValue = "0", value = "offset") int offset,
@RequestParam(required = false, defaultValue = "10", value = "limit") int limit,
@RequestParam(required = false, value = "sort") String sort,
@RequestParam(required = false, value = "order") String order) {
CmsCategoryExample cmsCategoryExample = new CmsCategoryExample();
cmsCategoryExample.setOffset((page - 1) * rows);
cmsCategoryExample.setLimit(rows);
cmsCategoryExample.setOrderByClause(desc ? "orders desc" : "orders asc");
List<CmsCategory> categorys = cmsCategoryService.selectByExample(cmsCategoryExample);
// 分页对象
cmsCategoryExample.setOffset(offset);
cmsCategoryExample.setLimit(limit);
if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)) {
cmsCategoryExample.setOrderByClause(sort + " " + order);
}
List<CmsCategory> rows = cmsCategoryService.selectByExample(cmsCategoryExample);
long total = cmsCategoryService.countByExample(cmsCategoryExample);
Paginator paginator = new Paginator(total, page, rows, request);
modelMap.put("categorys", categorys);
modelMap.put("paginator", paginator);
return "/manage/category/list";
Map<String, Object> result = new HashMap<>();
result.put("rows", rows);
result.put("total", total);
return result;
}
/**
* 新增get
* @return
*/
@ApiOperation(value = "新增类目", notes = "新增类目页")
@ApiOperation(value = "新增类目")
@RequiresPermissions("cms:category:create")
@RequestMapping(value = "/create", method = RequestMethod.GET)
public String add() {
public String create() {
return "/manage/category/create";
}
/**
* 新增post
* @param cmsCategory
* @param modelMap
* @return
*/
@ApiOperation(value = "新增类目", notes = "新增类目提交接口")
@ApiOperation(value = "新增类目")
@RequiresPermissions("cms:category:create")
@ApiImplicitParam(name = "cmsCategory", value = "类目实体cmsCategory", required = true, dataType = "CmsCategory")
@RequestMapping(value = "/create", method = RequestMethod.POST)
public String add(CmsCategory cmsCategory, ModelMap modelMap) {
@ResponseBody
public Object create(CmsCategory cmsCategory) {
long time = System.currentTimeMillis();
cmsCategory.setCtime(time);
cmsCategory.setOrders(time);
int count = cmsCategoryService.insertSelective(cmsCategory);
modelMap.put("count", count);
return "redirect:/manage/category/list";
return new CmsResult(CmsResultConstant.SUCCESS, count);
}
/**
* 删除
* @param ids
* @param modelMap
* @return
*/
@ApiOperation(value = "删除类目", notes = "批量删除类目")
@ApiOperation(value = "删除类目")
@RequiresPermissions("cms:category:delete")
@RequestMapping(value = "/delete/{ids}",method = RequestMethod.GET)
public String delete(@PathVariable("ids") String ids, ModelMap modelMap) {
@ResponseBody
public Object delete(@PathVariable("ids") String ids) {
int count = cmsCategoryService.deleteByPrimaryKeys(ids);
modelMap.put("count", count);
return "redirect:/manage/category/list";
return new CmsResult(CmsResultConstant.SUCCESS, count);
}
/**
* 修改get
* @param id
* @param modelMap
* @return
*/
@ApiOperation(value = "修改类目", notes = "根据id修改类目页")
@ApiOperation(value = "修改类目")
@RequiresPermissions("cms:category:update")
@RequestMapping(value = "/update/{id}", method = RequestMethod.GET)
public String update(@PathVariable("id") int id, ModelMap modelMap) {
@ -129,22 +101,15 @@ public class CmsCategoryController extends BaseController {
modelMap.put("category", category);
return "/manage/category/update";
}
/**
* 修改post
* @param id
* @param cmsCategory
* @param modelMap
* @return
*/
@ApiOperation(value = "修改类目", notes = "根据id修改类目提交接口")
@ApiOperation(value = "修改类目")
@RequiresPermissions("cms:category:update")
@RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
public String update(@PathVariable("id") int id, CmsCategory cmsCategory, ModelMap modelMap) {
@ResponseBody
public Object update(@PathVariable("id") int id, CmsCategory cmsCategory) {
cmsCategory.setCategoryId(id);
int count = cmsCategoryService.updateByPrimaryKeySelective(cmsCategory);
modelMap.put("count", count);
modelMap.put("id", id);
return "redirect:/manage/category/list";
return new CmsResult(CmsResultConstant.SUCCESS, count);
}
}

View File

@ -1,10 +1,11 @@
package com.zheng.cms.admin.controller.manage;
import com.zheng.cms.common.constant.CmsResult;
import com.zheng.cms.common.constant.CmsResultConstant;
import com.zheng.cms.dao.model.CmsComment;
import com.zheng.cms.dao.model.CmsCommentExample;
import com.zheng.cms.rpc.api.CmsCommentService;
import com.zheng.common.base.BaseController;
import com.zheng.common.util.Paginator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
@ -13,13 +14,12 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 评论控制器
@ -27,7 +27,7 @@ import java.util.List;
*/
@Controller
@RequestMapping("/manage/comment")
@Api(value = "评论控制器", description = "评论管理")
@Api(value = "评论管理", description = "评论管理")
public class CmsCommentController extends BaseController {
private final static Logger _log = LoggerFactory.getLogger(CmsCommentController.class);
@ -35,89 +35,64 @@ public class CmsCommentController extends BaseController {
@Autowired
private CmsCommentService cmsCommentService;
/**
* 列表
* @param page 当前页码
* @param rows 每页条数
* @param desc 降序排序
* @param request
* @param modelMap
* @return
*/
@ApiOperation(value = "评论列表", notes = "获取评论列表并分页")
@ApiOperation(value = "评论首页")
@RequiresPermissions("cms:comment:read")
@RequestMapping(value = "/index", method = RequestMethod.GET)
public String index() {
return "/manage/commentcomment/index";
}
@ApiOperation(value = "评论列表")
@RequiresPermissions("cms:comment:read")
@RequestMapping(value = "/list", method = RequestMethod.GET)
public String list(
@RequestParam(required = false, defaultValue = "1", value = "page") int page,
@RequestParam(required = false, defaultValue = "20", value = "rows") int rows,
@RequestParam(required = false, defaultValue = "true", value = "desc") boolean desc,
HttpServletRequest request, ModelMap modelMap) {
// 数据列表
@ResponseBody
public Object list(
@RequestParam(required = false, defaultValue = "0", value = "offset") int offset,
@RequestParam(required = false, defaultValue = "10", value = "limit") int limit,
@RequestParam(required = false, value = "sort") String sort,
@RequestParam(required = false, value = "order") String order) {
CmsCommentExample cmsCommentExample = new CmsCommentExample();
cmsCommentExample.setOffset((page - 1) * rows);
cmsCommentExample.setLimit(rows);
cmsCommentExample.setOrderByClause(desc ? "comment_id desc" : "comment_id asc");
List<CmsComment> comments = cmsCommentService.selectByExample(cmsCommentExample);
// 分页对象
cmsCommentExample.setOffset(offset);
cmsCommentExample.setLimit(limit);
if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)) {
cmsCommentExample.setOrderByClause(sort + " " + order);
}
List<CmsComment> rows = cmsCommentService.selectByExample(cmsCommentExample);
long total = cmsCommentService.countByExample(cmsCommentExample);
Paginator paginator = new Paginator(total, page, rows, request);
modelMap.put("comments", comments);
modelMap.put("paginator", paginator);
return "/manage/comment/list";
Map<String, Object> result = new HashMap<>();
result.put("rows", rows);
result.put("total", total);
return result;
}
/**
* 新增get
* @return
*/
@ApiOperation(value = "新增评论", notes = "新增评论页")
@ApiOperation(value = "新增评论")
@RequiresPermissions("cms:comment:create")
@RequestMapping(value = "/create", method = RequestMethod.GET)
public String add() {
public String create() {
return "/manage/comment/create";
}
/**
* 新增post
* @param cmsComment
* @param modelMap
* @return
*/
@ApiOperation(value = "新增评论", notes = "新增评论提交接口")
@ApiOperation(value = "新增评论")
@RequiresPermissions("cms:comment:create")
@RequestMapping(value = "/create", method = RequestMethod.POST)
public String add(CmsComment cmsComment, ModelMap modelMap) {
cmsComment.setCtime(System.currentTimeMillis());
@ResponseBody
public Object create(CmsComment cmsComment) {
long time = System.currentTimeMillis();
cmsComment.setCtime(time);
int count = cmsCommentService.insertSelective(cmsComment);
modelMap.put("count", count);
return "redirect:/manage/comment/list";
return new CmsResult(CmsResultConstant.SUCCESS, count);
}
/**
* 删除
* @param ids
* @param modelMap
* @return
*/
@ApiOperation(value = "删除评论", notes = "批量删除评论")
@ApiOperation(value = "删除评论")
@RequiresPermissions("cms:comment:delete")
@RequestMapping(value = "/delete/{ids}",method = RequestMethod.GET)
public String delete(@PathVariable("ids") String ids, ModelMap modelMap) {
@ResponseBody
public Object delete(@PathVariable("ids") String ids) {
int count = cmsCommentService.deleteByPrimaryKeys(ids);
modelMap.put("count", count);
return "redirect:/manage/comment/list";
return new CmsResult(CmsResultConstant.SUCCESS, count);
}
/**
* 修改get
* @param id
* @param modelMap
* @return
*/
@ApiOperation(value = "修改评论", notes = "根据id修改评论页")
@ApiOperation(value = "修改评论")
@RequiresPermissions("cms:comment:update")
@RequestMapping(value = "/update/{id}", method = RequestMethod.GET)
public String update(@PathVariable("id") int id, ModelMap modelMap) {
@ -125,22 +100,15 @@ public class CmsCommentController extends BaseController {
modelMap.put("comment", comment);
return "/manage/comment/update";
}
/**
* 修改post
* @param id
* @param cmsComment
* @param modelMap
* @return
*/
@ApiOperation(value = "修改评论", notes = "根据id修改评论提交接口")
@ApiOperation(value = "修改评论")
@RequiresPermissions("cms:comment:update")
@RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
public String update(@PathVariable("id") int id, CmsComment cmsComment, ModelMap modelMap) {
@ResponseBody
public Object update(@PathVariable("id") int id, CmsComment cmsComment) {
cmsComment.setCommentId(id);
int count = cmsCommentService.updateByPrimaryKeySelective(cmsComment);
modelMap.put("count", count);
modelMap.put("id", id);
return "redirect:/manage/comment/list";
return new CmsResult(CmsResultConstant.SUCCESS, count);
}
}

View File

@ -1,5 +1,7 @@
package com.zheng.cms.admin.controller.manage;
import com.zheng.cms.common.constant.CmsResult;
import com.zheng.cms.common.constant.CmsResultConstant;
import com.zheng.cms.dao.model.CmsTag;
import com.zheng.cms.dao.model.CmsTagExample;
import com.zheng.cms.rpc.api.CmsTagService;
@ -15,7 +17,9 @@ import org.springframework.ui.ModelMap;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 标签控制器
@ -23,7 +27,7 @@ import java.util.List;
*/
@Controller
@RequestMapping("/manage/tag")
@Api(value = "标签控制器", description = "标签管理")
@Api(value = "标签管理", description = "标签管理")
public class CmsTagController extends BaseController {
private final static Logger _log = LoggerFactory.getLogger(CmsTagController.class);
@ -31,26 +35,14 @@ public class CmsTagController extends BaseController {
@Autowired
private CmsTagService cmsTagService;
/**
* 首页
* @return
*/
@ApiOperation(value = "评论首页", notes = "获取评论列表首页")
@ApiOperation(value = "评论首页")
@RequiresPermissions("cms:tag:read")
@RequestMapping(value = "/index", method = RequestMethod.GET)
public String index() {
return "/manage/tag/index";
}
/**
* 列表
* @param offset
* @param limit
* @param sort
* @param order
* @return
*/
@ApiOperation(value = "评论列表", notes = "获取评论列表并分页")
@ApiOperation(value = "评论列表")
@RequiresPermissions("cms:tag:read")
@RequestMapping(value = "/list", method = RequestMethod.GET)
@ResponseBody
@ -59,72 +51,49 @@ public class CmsTagController extends BaseController {
@RequestParam(required = false, defaultValue = "10", value = "limit") int limit,
@RequestParam(required = false, value = "sort") String sort,
@RequestParam(required = false, value = "order") String order) {
// 数据列表
CmsTagExample cmsTagExample = new CmsTagExample();
cmsTagExample.setOffset(offset);
cmsTagExample.setLimit(limit);
if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)) {
cmsTagExample.setOrderByClause(sort + " " + order);
}
List<CmsTag> tags = cmsTagService.selectByExample(cmsTagExample);
// long total = cmsTagService.countByExample(cmsTagExample);
return tags;
List<CmsTag> rows = cmsTagService.selectByExample(cmsTagExample);
long total = cmsTagService.countByExample(cmsTagExample);
Map<String, Object> result = new HashMap<>();
result.put("rows", rows);
result.put("total", total);
return result;
}
/**
* 新增get
* @return
*/
@ApiOperation(value = "新增标签", notes = "新增标签页")
@ApiOperation(value = "新增标签")
@RequiresPermissions("cms:tag:create")
@RequestMapping(value = "/create", method = RequestMethod.GET)
public String add() {
public String create() {
return "/manage/tag/create";
}
/**
* 新增post
* @param cmsTag
* @param modelMap
* @return
*/
@ApiOperation(value = "新增标签", notes = "新增标签提交接口")
@ApiOperation(value = "新增标签")
@RequiresPermissions("cms:tag:create")
@RequestMapping(value = "/create", method = RequestMethod.POST)
public String add(CmsTag cmsTag, ModelMap modelMap) {
@ResponseBody
public Object create(CmsTag cmsTag) {
long time = System.currentTimeMillis();
cmsTag.setCtime(time);
cmsTag.setOrders(time);
int count = cmsTagService.insertSelective(cmsTag);
modelMap.put("count", count);
return "redirect:/manage/tag/list";
return new CmsResult(CmsResultConstant.SUCCESS, count);
}
/**
* 删除
* @param ids
* @param modelMap
* @return
*/
@ApiOperation(value = "删除标签", notes = "批量删除标签")
@ApiOperation(value = "删除标签")
@RequiresPermissions("cms:tag:delete")
@RequestMapping(value = "/delete/{ids}",method = RequestMethod.GET)
public String delete(@PathVariable("ids") String ids, ModelMap modelMap) {
@ResponseBody
public Object delete(@PathVariable("ids") String ids) {
int count = cmsTagService.deleteByPrimaryKeys(ids);
modelMap.put("count", count);
return "redirect:/manage/tag/list";
return new CmsResult(CmsResultConstant.SUCCESS, count);
}
/**
* 修改get
* @param id
* @param modelMap
* @return
*/
@ApiOperation(value = "修改标签", notes = "根据id修改标签页")
@ApiOperation(value = "修改标签")
@RequiresPermissions("cms:tag:update")
@RequestMapping(value = "/update/{id}", method = RequestMethod.GET)
public String update(@PathVariable("id") int id, ModelMap modelMap) {
@ -132,22 +101,15 @@ public class CmsTagController extends BaseController {
modelMap.put("tag", tag);
return "/manage/tag/update";
}
/**
* 修改post
* @param id
* @param cmsTag
* @param modelMap
* @return
*/
@ApiOperation(value = "修改标签", notes = "根据id修改标签提交接口")
@ApiOperation(value = "修改标签")
@RequiresPermissions("cms:tag:update")
@RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
public String update(@PathVariable("id") int id, CmsTag cmsTag, ModelMap modelMap) {
@ResponseBody
public Object update(@PathVariable("id") int id, CmsTag cmsTag) {
cmsTag.setTagId(id);
int count = cmsTagService.updateByPrimaryKeySelective(cmsTag);
modelMap.put("count", count);
modelMap.put("id", id);
return "redirect:/manage/tag/list";
return new CmsResult(CmsResultConstant.SUCCESS, count);
}
}

View File

@ -6,7 +6,8 @@ package com.zheng.cms.common.constant;
*/
public enum CmsResultConstant {
SUCCESS(1, "success");
SUCCESS(1, "success"),
FILE_TYPE_ERROR(20001, "File type not supported!");
public int code;

View File

@ -1,5 +1,7 @@
package com.zheng.cms.web.controller;
import com.zheng.cms.common.constant.CmsResult;
import com.zheng.cms.common.constant.CmsResultConstant;
import com.zheng.cms.dao.model.CmsUser;
import com.zheng.cms.dao.model.CmsUserExample;
import com.zheng.cms.rpc.api.UserService;
@ -181,9 +183,8 @@ public class UserController extends BaseController {
(!contentType.equals("image/x-png")) &&
(!contentType.equals("image/bmp")) &&
(!contentType.equals("image/gif"))) {
map.put(RESULT, FAILED);
map.put(DATA, "不支持该类型的文件!");
return map;
return new CmsResult(CmsResultConstant.FILE_TYPE_ERROR, "不支持该类型的文件!");
}
// 创建图片目录
String basePath = request.getSession().getServletContext().getRealPath("/attached");
@ -195,9 +196,7 @@ public class UserController extends BaseController {
}
// 保存图片
file.transferTo(targetFile);
map.put(RESULT, SUCCESS);
map.put(DATA, targetFile.getAbsoluteFile());
return map;
return new CmsResult(CmsResultConstant.SUCCESS, targetFile.getAbsoluteFile());
}
/**