添加默认创建时间和修改时间

This commit is contained in:
lijiaqi 2022-08-12 15:09:45 +08:00
parent da91a40644
commit 648d999a7c
2 changed files with 6 additions and 0 deletions

View File

@ -21,6 +21,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.time.LocalDateTime;
/** /**
* @author chenchen * @author chenchen
* @date 2020/10/12 * @date 2020/10/12
@ -101,6 +103,7 @@ public class ApiNoticeController extends ApiBaseController {
@PostMapping("/save") @PostMapping("/save")
public void ApiNoticeSave(String title, String content, String noticeDate, Integer top, String coverNames, String coverPaths, String fileNames, String filePaths, String type, String obj) { public void ApiNoticeSave(String title, String content, String noticeDate, Integer top, String coverNames, String coverPaths, String fileNames, String filePaths, String type, String obj) {
Notice bean = new Notice(); Notice bean = new Notice();
bean.setCreatedAt(LocalDateTime.now());
bean.setTitle(title); bean.setTitle(title);
bean.setContent(content); bean.setContent(content);
bean.setNoticeDate(noticeDate); bean.setNoticeDate(noticeDate);

View File

@ -24,6 +24,7 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import java.time.LocalDateTime;
import java.util.List; import java.util.List;
/** /**
@ -87,6 +88,8 @@ public class NoticeController extends BaseAdminController {
@PreAuth("rddb:policy:save") @PreAuth("rddb:policy:save")
@PostMapping("/save") @PostMapping("/save")
public void save(@Validated NoticeBo noticeBo) { public void save(@Validated NoticeBo noticeBo) {
if (noticeBo.getId()!=null) noticeBo.setCreatedAt(LocalDateTime.now());
else noticeBo.setUpdatedAt(LocalDateTime.now());
boolean flag = noticeService.saveOrUpdate(noticeBo, getLoginUser()); boolean flag = noticeService.saveOrUpdate(noticeBo, getLoginUser());
render(flag ? Ret.ok() : Ret.fail("操作失败")); render(flag ? Ret.ok() : Ret.fail("操作失败"));
} }