XiaoLFeng 76a1cf758c
All checks were successful
代码检查 / 代码检查 (pull_request) Successful in 23s
patch: 优化日志处理模式,删除多余的日志信息
2024-04-16 17:29:21 +08:00

64 lines
2.0 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.jsl.oa.controllers;
import com.jsl.oa.model.vodata.NewsAddVO;
import com.jsl.oa.services.NewsService;
import com.jsl.oa.utils.BaseResponse;
import com.jsl.oa.utils.ErrorCode;
import com.jsl.oa.utils.Processing;
import com.jsl.oa.utils.ResultUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
/**
* <h1>新闻控制器</h1>
* <hr/>
* 新闻控制器,包含新闻添加接口
*
* @author xiangZr-hhh | xiao_lfeng | 176yunxuan
* @version v1.1.0
* @see NewsService
* @since v1.1.0
*/
@Slf4j
@RestController
@RequiredArgsConstructor
public class NewsController {
private final NewsService newsService;
/**
* <h2>新闻添加接口</h2>
* <hr/>
* 新闻添加接口接收新闻添加VO对象并调用NewsService的newsAdd方法进行新闻添加操作。
*
* @param newsAddVO 新闻添加VO对象包含新闻信息
* @param bindingResult 数据校验结果,用于检查请求参数是否有错误
* @param request 请求对象,包含请求信息
* @return BaseResponse 返回结果,包含操作结果和错误信息
* @see NewsService#newsAdd(NewsAddVO, HttpServletRequest)
* @since v1.1.0
*/
@PostMapping("/news/add")
public BaseResponse newsAdd(
@RequestBody @Validated NewsAddVO newsAddVO,
BindingResult bindingResult,
HttpServletRequest request
) {
// 判断是否有参数错误
if (bindingResult.hasErrors()) {
return ResultUtil.error(ErrorCode.REQUEST_BODY_ERROR, Processing.getValidatedErrorList(bindingResult));
}
return newsService.newsAdd(newsAddVO, request);
}
}