Skip to content

Commit

Permalink
2.7.3 release 修复一些问题
Browse files Browse the repository at this point in the history
  • Loading branch information
fengwenyi committed Nov 17, 2022
1 parent f1b06b6 commit 6bc7bd1
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 5 deletions.
6 changes: 5 additions & 1 deletion LOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

## v2.7.3

2022.07.31 ~
2022.07.31 ~ 2022.11.17

:star: New Features

Expand All @@ -12,6 +12,10 @@
- `Builder` -> `IBuilder`
- `Result` -> `IResult`

:bug: Bug Fixes

- 修复 ResultTemplate.date 转json,可能出现无法被序列化的问题

:memo: Document

- 修复文档示例代码不正确的问题
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.fengwenyi</groupId>
<artifactId>api-result</artifactId>
<version>2.7.3-SNAPSHOT</version>
<version>2.7.3</version>
<packaging>jar</packaging>
<name>api-result</name>
<description>一套RESTful风格API接口响应参数规范化的解决方案</description>
Expand Down
21 changes: 18 additions & 3 deletions src/main/java/com/fengwenyi/api/result/ResultTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Map;
import java.util.Objects;

/**
* 结果模板
Expand Down Expand Up @@ -92,8 +93,10 @@ public class ResultTemplate<T> implements Serializable {

/**
* 时间
*
* <p>格式示例:2022-11-17T22:11:33.436</p>
*/
private LocalDateTime date = LocalDateTime.now();
private String date = LocalDateTime.now().toString();

/**
* 默认操作成功
Expand Down Expand Up @@ -326,12 +329,24 @@ public ResultTemplate<T> setBody(T body) {
return this;
}

public LocalDateTime getDate() {
/**
* {@code date} 的get方法
* @return {@code date} 的值
*/
public String getDate() {
return date;
}

/**
* {@code date} 的set方法
*
* @param date 日期,注意类型为 {@link LocalDateTime}
* @return {@link ResultTemplate}
*/
public ResultTemplate<T> setDate(LocalDateTime date) {
this.date = date;
if (Objects.nonNull(date)) {
this.date = date.toString();
}
return this;
}

Expand Down
22 changes: 22 additions & 0 deletions src/test/java/com/fengwenyi/api/result/DateTimeTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.fengwenyi.api.result;

import org.junit.Test;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
* @author <a href="https://fengwenyi.com">Erwin Feng</a>
* @since 2022-11-17
*/
public class DateTimeTests {

@Test
public void testFormat() {
LocalDateTime localDateTime = LocalDateTime.now();
System.out.println(localDateTime);
System.out.println(localDateTime.format(DateTimeFormatter.ISO_DATE_TIME)); // 默认
System.out.println(localDateTime.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
}

}

0 comments on commit 6bc7bd1

Please sign in to comment.