diff --git a/src/main/java/com/codesdream/ase/component/activity/ActivityConverter.java b/src/main/java/com/codesdream/ase/component/activity/ActivityConverter.java index 4ae1b7f..38b079a 100644 --- a/src/main/java/com/codesdream/ase/component/activity/ActivityConverter.java +++ b/src/main/java/com/codesdream/ase/component/activity/ActivityConverter.java @@ -21,9 +21,6 @@ import java.util.*; @Component public class ActivityConverter { - @Resource - ActivityService activityService; - @Resource UserService userService; @@ -40,14 +37,14 @@ public class ActivityConverter { Activity activity = new Activity(); JSONObject jsonObject = json.get(); - String username = (String) jsonObject.get("creator"); - Optional creator = userService.findUserByUsername(username); + int userId = (int) jsonObject.get("creator"); + Optional creator = userService.findUserById(userId); activity.setCreator(creator.get()); - List participateGroupFromJson = (List) jsonObject.get("participate-group"); + List participateGroupFromJson = (List) jsonObject.get("participate-group"); Set participateGroup = new HashSet<>(); - for (String name : participateGroupFromJson) { - Optional user = userService.findUserByUsername(name); + for (int id : participateGroupFromJson) { + Optional user = userService.findUserById(id); participateGroup.add(user.get()); } activity.setParticipateGroup(participateGroup); @@ -55,14 +52,14 @@ public class ActivityConverter { String title = (String) jsonObject.get("title"); activity.setTitle(title); - String chiefManagerName = (String) jsonObject.get("chief-manager"); - Optional chiefManager = userService.findUserByUsername(chiefManagerName); + int chiefManagerId = (int) jsonObject.get("chief-manager"); + Optional chiefManager = userService.findUserById(chiefManagerId); activity.setChiefManager(chiefManager.get()); - List assistManagerFromJSON = (List) jsonObject.get("assist-manager"); + List assistManagersFromJSON = (List) jsonObject.get("assist-managers"); Set assistManager = new HashSet<>(); - for (String name : assistManagerFromJSON) { - Optional user = userService.findUserByUsername(name); + for (int id : assistManagersFromJSON) { + Optional user = userService.findUserById(id); assistManager.add(user.get()); } activity.setAssistManagers(assistManager); @@ -85,26 +82,31 @@ public class ActivityConverter { String description = (String) jsonObject.get("description"); activity.setDescription(description); - List signGroupFromJSON = (List) jsonObject.get("sign-group"); + List signGroupFromJSON = (List) jsonObject.get("sign-group"); Set signGroup = new HashSet<>(); - for (String name : signGroupFromJSON) { - Optional user = userService.findUserByUsername(name); + for (int id : signGroupFromJSON) { + Optional user = userService.findUserById(id); signGroup.add(user.get()); } activity.setSignGroup(signGroup); - List informGroupFromJSON = (List) jsonObject.get("inform-group"); + List informGroupFromJSON = (List) jsonObject.get("inform-group"); + if (informGroupFromJSON == null) { + participateGroupFromJson.removeAll(signGroupFromJSON); + participateGroupFromJson.addAll(signGroupFromJSON); + informGroupFromJSON = participateGroupFromJson; + } Set informGroup = new HashSet<>(); - for (String name : informGroupFromJSON) { - Optional user = userService.findUserByUsername(name); + for (int id : informGroupFromJSON) { + Optional user = userService.findUserById(id); informGroup.add(user.get()); } activity.setInformGroup(informGroup); - List visibleGroupFromJSON = (List) jsonObject.get("visible-group"); + List visibleGroupFromJSON = (List) jsonObject.get("visible-group"); Set visibleGroup = new HashSet<>(); - for (String name : visibleGroupFromJSON) { - Optional user = userService.findUserByUsername(name); + for (int id : visibleGroupFromJSON) { + Optional user = userService.findUserById(id); visibleGroup.add(user.get()); } activity.setVisibleGroup(informGroup); diff --git a/src/main/java/com/codesdream/ase/component/activity/FileUtils.java b/src/main/java/com/codesdream/ase/component/activity/FileUtils.java new file mode 100644 index 0000000..656d3d2 --- /dev/null +++ b/src/main/java/com/codesdream/ase/component/activity/FileUtils.java @@ -0,0 +1,129 @@ +package com.codesdream.ase.component.activity; + +import org.springframework.stereotype.Component; +import org.springframework.web.multipart.MultipartFile; + +import javax.imageio.ImageIO; +import javax.imageio.stream.ImageOutputStream; +import java.awt.image.BufferedImage; +import java.io.*; + +@Component +public class FileUtils { + /** + * 得到图片字节流 数组大小 + */ + public static byte[] readStream(InputStream inStream) throws Exception { + ByteArrayOutputStream outStream = new ByteArrayOutputStream(); + byte[] buffer = new byte[1024]; + int len = -1; + while ((len = inStream.read(buffer)) != -1) { + outStream.write(buffer, 0, len); + } + outStream.close(); + inStream.close(); + return outStream.toByteArray(); + } + + /** + * 将文件转换成Byte数组 + * + * @param file + * @return + */ + public static byte[] getBytesByFile(File file) { + try { + FileInputStream fis = new FileInputStream(file); + ByteArrayOutputStream bos = new ByteArrayOutputStream(1000); + byte[] b = new byte[1000]; + int n; + while ((n = fis.read(b)) != -1) { + bos.write(b, 0, n); + } + fis.close(); + byte[] data = bos.toByteArray(); + bos.close(); + return data; + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + /** + * MultipartFile转File + * + * @param param + * @return + */ + public static File transfer(MultipartFile param) { + if (!param.isEmpty()) { + File file = null; + try { + InputStream in = param.getInputStream(); + file = new File(param.getOriginalFilename()); + OutputStream out = new FileOutputStream(file); + int bytesRead = 0; + byte[] buffer = new byte[8192]; + while ((bytesRead = in.read(buffer, 0, 8192)) != -1) { + out.write(buffer, 0, bytesRead); + } + in.close(); + out.close(); + return file; + } catch (Exception e) { + e.printStackTrace(); + return file; + } + } + return null; + } + + /** + * 获取指定文件的输入流 + * + * @param logoPath 文件的路径 + * @return + */ + public static InputStream getResourceAsStream(String logoPath) { + return FileUtils.class.getResourceAsStream(logoPath); + } + + /** + * 将InputStream写入到File中 + * + * @param ins + * @param file + * @throws IOException + */ + public void inputStreamToFile(InputStream ins, File file) throws IOException { + OutputStream os = new FileOutputStream(file); + int bytesRead = 0; + byte[] buffer = new byte[8192]; + while ((bytesRead = ins.read(buffer, 0, 8192)) != -1) { + os.write(buffer, 0, bytesRead); + } + os.close(); + ins.close(); + } + + /** + * 将图片转化成输入流 + * + * @param image 图片 + * @return inputStream 图片转化之后的输入流 + */ + public static InputStream getImageStream(BufferedImage image) { + InputStream inputStream = null; + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + ImageOutputStream imageOutputStream; + try { + imageOutputStream = ImageIO.createImageOutputStream(byteArrayOutputStream); + ImageIO.write(image, "jpg", imageOutputStream); + inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray()); + } catch (IOException e) { + e.printStackTrace(); + } + return inputStream; + } +} diff --git a/src/main/java/com/codesdream/ase/component/activity/QrCodeUtils.java b/src/main/java/com/codesdream/ase/component/activity/QrCodeUtils.java new file mode 100644 index 0000000..4389f67 --- /dev/null +++ b/src/main/java/com/codesdream/ase/component/activity/QrCodeUtils.java @@ -0,0 +1,227 @@ +package com.codesdream.ase.component.activity; + +import com.google.zxing.BarcodeFormat; +import com.google.zxing.EncodeHintType; +import com.google.zxing.MultiFormatWriter; +import com.google.zxing.common.BitMatrix; +import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; +import jdk.internal.util.xml.impl.Input; +import org.springframework.stereotype.Component; + +import javax.imageio.ImageIO; +import javax.imageio.stream.ImageOutputStream; +import java.awt.*; +import java.awt.geom.RoundRectangle2D; +import java.awt.image.BufferedImage; +import java.io.*; +import java.util.Hashtable; +import java.util.Random; + +/** + * 二维码生成工具类 + */ +@Component +public class QrCodeUtils { + private static final String CHARSET = "utf-8"; + public static final String FORMAT = "JPG"; + // 二维码尺寸 + private static final int QRCODE_SIZE = 300; + // LOGO宽度 + private static final int LOGO_WIDTH = 60; + // LOGO高度 + private static final int LOGO_HEIGHT = 60; + + /** + * 生成二维码 + * + * @param content 二维码内容 + * @param logoPath logo地址 + * @param needCompress 是否压缩logo + * @return 图片 + * @throws Exception + */ + public static BufferedImage createImage(String content, String logoPath, boolean needCompress) throws Exception { + Hashtable hints = new Hashtable<>(); + hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H); + hints.put(EncodeHintType.CHARACTER_SET, CHARSET); + hints.put(EncodeHintType.MARGIN, 1); + BitMatrix bitMatrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, QRCODE_SIZE, QRCODE_SIZE, + hints); + int width = bitMatrix.getWidth(); + int height = bitMatrix.getHeight(); + BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); + for (int x = 0; x < width; x++) { + for (int y = 0; y < height; y++) { + image.setRGB(x, y, bitMatrix.get(x, y) ? 0xFF000000 : 0xFFFFFFFF); + } + } + if (logoPath == null || "".equals(logoPath)) { + return image; + } + // 插入图片 + QrCodeUtils.insertImage(image, logoPath, needCompress); + return image; + } + + /** + * 插入LOGO + * + * @param source 二维码图片 + * @param logoPath LOGO图片地址 + * @param needCompress 是否压缩 + * @throws IOException + */ + private static void insertImage(BufferedImage source, String logoPath, boolean needCompress) throws IOException { + InputStream inputStream = null; + try { + inputStream = FileUtils.getResourceAsStream(logoPath); + Image src = ImageIO.read(inputStream); + int width = src.getWidth(null); + int height = src.getHeight(null); + if (needCompress) { // 压缩LOGO + if (width > LOGO_WIDTH) { + width = LOGO_WIDTH; + } + if (height > LOGO_HEIGHT) { + height = LOGO_HEIGHT; + } + Image image = src.getScaledInstance(width, height, Image.SCALE_SMOOTH); + BufferedImage tag = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); + Graphics g = tag.getGraphics(); + g.drawImage(image, 0, 0, null); // 绘制缩小后的图 + g.dispose(); + src = image; + } + // 插入LOGO + Graphics2D graph = source.createGraphics(); + int x = (QRCODE_SIZE - width) / 2; + int y = (QRCODE_SIZE - height) / 2; + graph.drawImage(src, x, y, width, height, null); + Shape shape = new RoundRectangle2D.Float(x, y, width, width, 6, 6); + graph.setStroke(new BasicStroke(3f)); + graph.draw(shape); + graph.dispose(); + } catch (IOException e) { + e.printStackTrace(); + throw new RuntimeException(e); + } finally { + if (inputStream != null) { + inputStream.close(); + } + } + } + + /** + * 生成二维码(内嵌LOGO) + * 二维码文件名随机,文件名可能会有重复 + * + * @param content 内容 + * @param logoPath LOGO地址 + * @param destPath 存放目录 + * @param needCompress 是否压缩LOGO + * @throws Exception + */ + public static String encode(String content, String logoPath, String destPath, boolean needCompress) throws Exception { + BufferedImage image = QrCodeUtils.createImage(content, logoPath, needCompress); + mkdirs(destPath); + String fileName = new Random().nextInt(99999999) + "." + FORMAT.toLowerCase(); + ImageIO.write(image, FORMAT, new File(destPath + "/" + fileName)); + return fileName; + } + + /** + * 生成二维码(内嵌LOGO) + * 调用者指定二维码文件名 + * + * @param content 内容 + * @param logoPath LOGO地址 + * @param destPath 存放目录 + * @param fileName 二维码文件名 + * @param needCompress 是否压缩LOGO + * @throws Exception + */ + public static String encode(String content, String logoPath, String destPath, String fileName, boolean needCompress) throws Exception { + BufferedImage image = QrCodeUtils.createImage(content, logoPath, needCompress); + mkdirs(destPath); + fileName = fileName.substring(0, fileName.indexOf(".") > 0 ? fileName.indexOf(".") : fileName.length()) + + "." + FORMAT.toLowerCase(); + ImageIO.write(image, FORMAT, new File(destPath + "/" + fileName)); + return fileName; + } + + /** + * 当文件夹不存在时,mkdirs会自动创建多层目录,区别于mkdir. + * (mkdir如果父目录不存在则会抛出异常) + * + * @param destPath 存放目录 + */ + public static void mkdirs(String destPath) { + File file = new File(destPath); + if (!file.exists() && !file.isDirectory()) { + file.mkdirs(); + } + } + + /** + * 生成二维码(内嵌LOGO) + * + * @param content 内容 + * @param logoPath LOGO地址 + * @param destPath 存储地址 + * @throws Exception + */ + public static String encode(String content, String logoPath, String destPath) throws Exception { + return QrCodeUtils.encode(content, logoPath, destPath, false); + } + + /** + * 生成二维码 + * + * @param content 内容 + * @param destPath 存储地址 + * @param needCompress 是否压缩LOGO + * @throws Exception + */ + public static String encode(String content, String destPath, boolean needCompress) throws Exception { + return QrCodeUtils.encode(content, null, destPath, needCompress); + } + + /** + * 生成二维码 + * + * @param content 内容 + * @param destPath 存储地址 + * @throws Exception + */ + public static String encode(String content, String destPath) throws Exception { + return QrCodeUtils.encode(content, null, destPath, false); + } + + /** + * 生成二维码(内嵌LOGO) + * + * @param content 内容 + * @param logoPath LOGO地址 + * @param output 输出流 + * @param needCompress 是否压缩LOGO + * @throws Exception + */ + public static void encode(String content, String logoPath, OutputStream output, boolean needCompress) + throws Exception { + BufferedImage image = QrCodeUtils.createImage(content, logoPath, needCompress); + ImageIO.write(image, FORMAT, output); + } + + /** + * 生成二维码 + * + * @param content 内容 + * @param output 输出流 + * @throws Exception + */ + public static void encode(String content, OutputStream output) throws Exception { + QrCodeUtils.encode(content, null, output, false); + } + + +} diff --git a/src/main/java/com/codesdream/ase/configure/ActivityFormConfigure.java b/src/main/java/com/codesdream/ase/configure/ActivityFormConfigure.java index 8fb2c9f..48e34b9 100644 --- a/src/main/java/com/codesdream/ase/configure/ActivityFormConfigure.java +++ b/src/main/java/com/codesdream/ase/configure/ActivityFormConfigure.java @@ -30,6 +30,7 @@ public class ActivityFormConfigure { add("attendance"); }}; + public HashSet getStdActivityForm() { return stdActivityForm; } diff --git a/src/main/java/com/codesdream/ase/controller/activity/ActivityAttendanceController.java b/src/main/java/com/codesdream/ase/controller/activity/ActivityAttendanceController.java new file mode 100644 index 0000000..29d8d83 --- /dev/null +++ b/src/main/java/com/codesdream/ase/controller/activity/ActivityAttendanceController.java @@ -0,0 +1,11 @@ +package com.codesdream.ase.controller.activity; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; + +import javax.annotation.Resource; + +@Controller +public class ActivityAttendanceController { + +} diff --git a/src/main/java/com/codesdream/ase/controller/activity/ActivityCreatorController.java b/src/main/java/com/codesdream/ase/controller/activity/ActivityCreatorController.java index 64b2d2b..35b4743 100644 --- a/src/main/java/com/codesdream/ase/controller/activity/ActivityCreatorController.java +++ b/src/main/java/com/codesdream/ase/controller/activity/ActivityCreatorController.java @@ -12,15 +12,16 @@ import com.codesdream.ase.model.activity.Activity; import com.codesdream.ase.model.activity.UserActivity; import com.codesdream.ase.model.permission.User; import com.codesdream.ase.repository.activity.UserActivityRepository; -import com.codesdream.ase.repository.permission.UserRepository; import com.codesdream.ase.service.ActivityService; +import com.codesdream.ase.service.UserService; import com.codesdream.ase.validator.ActivityValidator; import com.codesdream.ase.validator.NullValueValidator; import com.codesdream.ase.validator.JSONFormValidator; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; import org.springframework.stereotype.Controller; -import org.springframework.ui.Model; import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import javax.annotation.Resource; @@ -57,7 +58,7 @@ public class ActivityCreatorController { ActivityValidator activityValidator; @Resource - UserRepository userRepository; + UserService userService; @Resource UserActivityRepository userActivityRepository; @@ -67,12 +68,25 @@ public class ActivityCreatorController { private final String url = "/forget/activity"; - @RequestMapping(value = url + "/activity_creator") - String activityCreatorView(Model model){return "activity_creator";} - @PostMapping(value = url + "/activity_creator") @ResponseBody + @ApiOperation(value = "创建活动", notes = "所有有关用户的数据传递均使用id,类型为int") + @ApiImplicitParams({ + @ApiImplicitParam(name = "title", value = "活动标题", required = true), + @ApiImplicitParam(name = "type", value = "活动类型", required = true), + @ApiImplicitParam(name = "start-time", value = "活动开始时间,格式为yyyy-MM-dd HH:mm:ss", required = true), + @ApiImplicitParam(name = "end-time", value = "活动结束时间,格式为yyyy-MM-dd HH:mm:ss", required = true), + @ApiImplicitParam(name = "chief-manager", value = "主要负责人", required = true), + @ApiImplicitParam(name = "assist-managers", value = "次要负责人"), + @ApiImplicitParam(name = "description", value = "活动描述"), + @ApiImplicitParam(name = "cycle", value = "活动周期,格式为阿拉伯数字数字+单位,0表示无周期"), + @ApiImplicitParam(name = "participate-group", value = "预定参与人员"), + @ApiImplicitParam(name = "sign-group", value = "可参与人员"), + @ApiImplicitParam(name = "inform-group", value = "通知人群,若为空,则默认为预定参与人员和可报名人员的并集"), + @ApiImplicitParam(name = "visible-group", value = "活动可见人群,若为空,则默认为负责人、活动创建者预定参和可报名人员以及通知人员的并集"), + @ApiImplicitParam(name = "remind-time", defaultValue = "30m", value = "活动提醒时间,格式为数字+单位,可接受的单位从大到小有:w,d,h,m,s"), + }) String activityCreator(HttpServletRequest request) throws InvalidFormFormatException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { JSONObject error = new JSONObject(); @@ -80,19 +94,16 @@ public class ActivityCreatorController { Optional json = jsonParameter.getJSONByRequest(request); if (!json.isPresent()) return jsonParameter.getJSONString(new JSONStandardFailedRespond()); - //WebFormValidator webFormValidator = aseSpringUtil.getBean(WebFormValidator.class); List formatCheckResult = jsonFormValidator.check(activityFormConfigure.getStdActivityForm(), json.get()); + if (!formatCheckResult.isEmpty()) { error.put("error", formatCheckResult); return error.toJSONString(); } // 需要检查JSON是否合法 - Activity activity = activityConverter.convertToActivity(json); - - //NullValueValidator nullValueValidator = aseSpringUtil.getBean(NullValueValidator.class); List nullValues = nullValueValidator.checkNullValues(activity); - //= aseSpringUtil.getBean(NullValueAttributes.class); + for (String str : nullValues){ if(str.equals("title")){ nullValueAttributes.getNullValueAttributes().add("title"); @@ -111,9 +122,8 @@ public class ActivityCreatorController { } } //如果为空,存下此活动并跳转至成功创建页面 - if(nullValueAttributes.getNullValueAttributes().isEmpty()){ + if (!nullValueAttributes.getNullValueAttributes().isEmpty()) { - //ActivityValidator activityValidator = aseSpringUtil.getBean(ActivityValidator.class); String[] errorParameters = activityValidator.check(json); if(errorParameters != null){ JSONObject invalidParameters = new JSONObject(); @@ -122,12 +132,9 @@ public class ActivityCreatorController { } else{ - //UserRepository userRepository = aseSpringUtil.getBean(UserRepository.class); - //activityService = aseSpringUtil.getBean(ActivityService.class); activity = activityService.createActivity(activity); String username = json.get().get("creator").toString(); - Optional user = userRepository.findByUsername(username); - //UserActivityRepository userActivityRepository = aseSpringUtil.getBean(UserActivityRepository.class); + Optional user = userService.findUserByUsername(username); UserActivity userActivity = userActivityRepository.findByUser(user.get()); userActivity.getCreatedActivities().add(activity); userActivityRepository.save(userActivity); diff --git a/src/main/java/com/codesdream/ase/controller/activity/QRCodeController.java b/src/main/java/com/codesdream/ase/controller/activity/QRCodeController.java new file mode 100644 index 0000000..3c5d7d0 --- /dev/null +++ b/src/main/java/com/codesdream/ase/controller/activity/QRCodeController.java @@ -0,0 +1,36 @@ +package com.codesdream.ase.controller.activity; + +import com.codesdream.ase.component.activity.QrCodeUtils; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.OutputStream; + +@Controller +public class QRCodeController { + + /** + * 二维码 + * + * @param request + * @param response + */ + @GetMapping("/qrcode") + public void qrCode(HttpServletRequest request, HttpServletResponse response) { + StringBuffer url = request.getRequestURL(); + // 域名 + String tempContextUrl = url.delete(url.length() - request.getRequestURI().length(), url.length()).append("/").toString(); + + // 再加上请求链接 + String requestUrl = tempContextUrl + "/index"; + try { + OutputStream os = response.getOutputStream(); + QrCodeUtils.encode(requestUrl, "", os, true); + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/java/com/codesdream/ase/model/activity/Activity.java b/src/main/java/com/codesdream/ase/model/activity/Activity.java index 4da4f56..a99a6e6 100644 --- a/src/main/java/com/codesdream/ase/model/activity/Activity.java +++ b/src/main/java/com/codesdream/ase/model/activity/Activity.java @@ -2,8 +2,6 @@ package com.codesdream.ase.model.activity; import com.codesdream.ase.model.permission.User; import lombok.Data; -import lombok.EqualsAndHashCode; -import org.springframework.security.core.parameters.P; import javax.persistence.*; import java.time.LocalDateTime; diff --git a/src/main/java/com/codesdream/ase/model/activity/Attendance.java b/src/main/java/com/codesdream/ase/model/activity/Attendance.java index e37c93d..d72852c 100644 --- a/src/main/java/com/codesdream/ase/model/activity/Attendance.java +++ b/src/main/java/com/codesdream/ase/model/activity/Attendance.java @@ -15,10 +15,6 @@ public class Attendance { @GeneratedValue(strategy = GenerationType.AUTO) private int id; - //二维码url - @Column(name = "qr_code")//, nullable = false, unique = true) - private String QRCode; - //是否在线 @Column(name = "is_online")//, nullable = false) private boolean isOnline; diff --git a/src/main/java/com/codesdream/ase/model/activity/Period.java b/src/main/java/com/codesdream/ase/model/activity/Period.java index 3e39829..c0ec4d7 100644 --- a/src/main/java/com/codesdream/ase/model/activity/Period.java +++ b/src/main/java/com/codesdream/ase/model/activity/Period.java @@ -1,5 +1,7 @@ package com.codesdream.ase.model.activity; +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Data; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; @@ -18,10 +20,12 @@ public class Period { private int id; //开始时间 + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") @Column(name = "start_time")//, nullable = false) private LocalDateTime startTime = LocalDateTime.of(2020,2,18,16,36); //结束时间 + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") @Column(name = "end_time")//, nullable = false) private LocalDateTime endTime = LocalDateTime.of(2020,2,18,16,37);