生成Controller
This commit is contained in:
parent
7c2914f461
commit
57bdacafb0
|
@ -1,11 +1,16 @@
|
|||
package com.zheng.cms.admin.controller.manage;
|
||||
|
||||
import com.baidu.unbiz.fluentvalidator.ComplexResult;
|
||||
import com.baidu.unbiz.fluentvalidator.FluentValidator;
|
||||
import com.baidu.unbiz.fluentvalidator.ResultCollectors;
|
||||
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.validator.LengthValidator;
|
||||
import com.zheng.common.validator.NotNullValidator;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
@ -26,11 +31,11 @@ import java.util.Map;
|
|||
* Created by shuzheng on 2016/11/14.
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping("/manage/article")
|
||||
@Api(value = "文章管理", description = "文章管理")
|
||||
@RequestMapping("/manage/article")
|
||||
public class CmsArticleController extends BaseController {
|
||||
|
||||
private final static Logger _log = LoggerFactory.getLogger(CmsArticleController.class);
|
||||
private static Logger _log = LoggerFactory.getLogger(CmsArticleController.class);
|
||||
|
||||
@Autowired
|
||||
private CmsArticleService cmsArticleService;
|
||||
|
@ -77,6 +82,13 @@ public class CmsArticleController extends BaseController {
|
|||
@RequestMapping(value = "/create", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public Object create(CmsArticle cmsArticle) {
|
||||
ComplexResult result = FluentValidator.checkAll()
|
||||
.on(cmsArticle.getTitle(), new LengthValidator(1, 200, "标题"))
|
||||
.doValidate()
|
||||
.result(ResultCollectors.toComplex());
|
||||
if (!result.isSuccess()) {
|
||||
return new CmsResult(CmsResultConstant.INVALID_LENGTH, result.getErrors());
|
||||
}
|
||||
long time = System.currentTimeMillis();
|
||||
cmsArticle.setCtime(time);
|
||||
cmsArticle.setOrders(time);
|
||||
|
@ -107,10 +119,16 @@ public class CmsArticleController extends BaseController {
|
|||
@RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public Object update(@PathVariable("id") int id, CmsArticle cmsArticle) {
|
||||
ComplexResult result = FluentValidator.checkAll()
|
||||
.on(cmsArticle.getTitle(), new LengthValidator(1, 200, "标题"))
|
||||
.doValidate()
|
||||
.result(ResultCollectors.toComplex());
|
||||
if (!result.isSuccess()) {
|
||||
return new CmsResult(CmsResultConstant.INVALID_LENGTH, result.getErrors());
|
||||
}
|
||||
cmsArticle.setArticleId(id);
|
||||
int count = cmsArticleService.updateByPrimaryKeySelective(cmsArticle);
|
||||
return new CmsResult(CmsResultConstant.SUCCESS, count);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,11 +1,15 @@
|
|||
package com.zheng.cms.admin.controller.manage;
|
||||
|
||||
import com.baidu.unbiz.fluentvalidator.ComplexResult;
|
||||
import com.baidu.unbiz.fluentvalidator.FluentValidator;
|
||||
import com.baidu.unbiz.fluentvalidator.ResultCollectors;
|
||||
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.validator.LengthValidator;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
@ -26,11 +30,11 @@ import java.util.Map;
|
|||
* Created by shuzheng on 2016/11/14.
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping("/manage/category")
|
||||
@Api(value = "类目管理", description = "类目管理")
|
||||
@RequestMapping("/manage/category")
|
||||
public class CmsCategoryController extends BaseController {
|
||||
|
||||
private final static Logger _log = LoggerFactory.getLogger(CmsCategoryController.class);
|
||||
private static Logger _log = LoggerFactory.getLogger(CmsCategoryController.class);
|
||||
|
||||
@Autowired
|
||||
private CmsCategoryService cmsCategoryService;
|
||||
|
@ -77,6 +81,13 @@ public class CmsCategoryController extends BaseController {
|
|||
@RequestMapping(value = "/create", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public Object create(CmsCategory cmsCategory) {
|
||||
ComplexResult result = FluentValidator.checkAll()
|
||||
.on(cmsCategory.getName(), new LengthValidator(1, 20, "名称"))
|
||||
.doValidate()
|
||||
.result(ResultCollectors.toComplex());
|
||||
if (!result.isSuccess()) {
|
||||
return new CmsResult(CmsResultConstant.INVALID_LENGTH, result.getErrors());
|
||||
}
|
||||
long time = System.currentTimeMillis();
|
||||
cmsCategory.setCtime(time);
|
||||
cmsCategory.setOrders(time);
|
||||
|
@ -107,6 +118,13 @@ public class CmsCategoryController extends BaseController {
|
|||
@RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public Object update(@PathVariable("id") int id, CmsCategory cmsCategory) {
|
||||
ComplexResult result = FluentValidator.checkAll()
|
||||
.on(cmsCategory.getName(), new LengthValidator(1, 20, "名称"))
|
||||
.doValidate()
|
||||
.result(ResultCollectors.toComplex());
|
||||
if (!result.isSuccess()) {
|
||||
return new CmsResult(CmsResultConstant.INVALID_LENGTH, result.getErrors());
|
||||
}
|
||||
cmsCategory.setCategoryId(id);
|
||||
int count = cmsCategoryService.updateByPrimaryKeySelective(cmsCategory);
|
||||
return new CmsResult(CmsResultConstant.SUCCESS, count);
|
||||
|
|
|
@ -26,11 +26,11 @@ import java.util.Map;
|
|||
* Created by shuzheng on 2016/11/14.
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping("/manage/comment")
|
||||
@Api(value = "评论管理", description = "评论管理")
|
||||
@RequestMapping("/manage/comment")
|
||||
public class CmsCommentController extends BaseController {
|
||||
|
||||
private final static Logger _log = LoggerFactory.getLogger(CmsCommentController.class);
|
||||
private static Logger _log = LoggerFactory.getLogger(CmsCommentController.class);
|
||||
|
||||
@Autowired
|
||||
private CmsCommentService cmsCommentService;
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
package com.zheng.cms.admin.controller.manage;
|
||||
|
||||
import com.baidu.unbiz.fluentvalidator.ComplexResult;
|
||||
import com.baidu.unbiz.fluentvalidator.FluentValidator;
|
||||
import com.baidu.unbiz.fluentvalidator.ResultCollectors;
|
||||
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;
|
||||
import com.zheng.common.base.BaseController;
|
||||
import com.zheng.common.validator.LengthValidator;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
@ -26,11 +30,11 @@ import java.util.Map;
|
|||
* Created by shuzheng on 2016/11/14.
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping("/manage/tag")
|
||||
@Api(value = "标签管理", description = "标签管理")
|
||||
@RequestMapping("/manage/tag")
|
||||
public class CmsTagController extends BaseController {
|
||||
|
||||
private final static Logger _log = LoggerFactory.getLogger(CmsTagController.class);
|
||||
private static Logger _log = LoggerFactory.getLogger(CmsTagController.class);
|
||||
|
||||
@Autowired
|
||||
private CmsTagService cmsTagService;
|
||||
|
@ -77,6 +81,13 @@ public class CmsTagController extends BaseController {
|
|||
@RequestMapping(value = "/create", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public Object create(CmsTag cmsTag) {
|
||||
ComplexResult result = FluentValidator.checkAll()
|
||||
.on(cmsTag.getName(), new LengthValidator(1, 20, "名称"))
|
||||
.doValidate()
|
||||
.result(ResultCollectors.toComplex());
|
||||
if (!result.isSuccess()) {
|
||||
return new CmsResult(CmsResultConstant.INVALID_LENGTH, result.getErrors());
|
||||
}
|
||||
long time = System.currentTimeMillis();
|
||||
cmsTag.setCtime(time);
|
||||
cmsTag.setOrders(time);
|
||||
|
@ -107,6 +118,13 @@ public class CmsTagController extends BaseController {
|
|||
@RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public Object update(@PathVariable("id") int id, CmsTag cmsTag) {
|
||||
ComplexResult result = FluentValidator.checkAll()
|
||||
.on(cmsTag.getName(), new LengthValidator(1, 20, "名称"))
|
||||
.doValidate()
|
||||
.result(ResultCollectors.toComplex());
|
||||
if (!result.isSuccess()) {
|
||||
return new CmsResult(CmsResultConstant.INVALID_LENGTH, result.getErrors());
|
||||
}
|
||||
cmsTag.setTagId(id);
|
||||
int count = cmsTagService.updateByPrimaryKeySelective(cmsTag);
|
||||
return new CmsResult(CmsResultConstant.SUCCESS, count);
|
||||
|
|
Loading…
Reference in New Issue