Current SpringBoot Reference Guide के अनुसार यदि मैं spring.jackson.date-format
संपत्ति सेट करता हूं, तो यह होगा: Date format string or a fully-qualified date format class name. For instance 'yyyy-MM-dd HH:mm:ss'
।वसंत बूट के 'spring.jackson.date-format' संपत्ति का उपयोग कैसे करें?
हालांकि, यह वसंत बूट 1.5.3 के साथ इस तरह से काम नहीं करता है।
प्रदर्शित करने के लिए, इस वर्ग के साथ शुरू:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import java.time.Instant;
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
@RestController
class NowController{
@GetMapping("/now")
Instant getNow(){
return Instant.now();
}
}
और इस src/main/resources/application.properties
spring.jackson.date-format=dd.MM.yyyy
और इस build.gradle
:
buildscript {
ext {
springBootVersion = '1.5.3.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'org.springframework.boot'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
compile('com.fasterxml.jackson.datatype:jackson-datatype-jdk8')
compile('com.fasterxml.jackson.datatype:jackson-datatype-jsr310')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
मैं निम्नलिखित मिल 0
http localhost:8080/now
HTTP/1.1 200
Content-Type: application/json;charset=UTF-8
Date: Tue, 25 Apr 2017 22:37:58 GMT
Transfer-Encoding: chunked
"2017-04-25T22:37:58.319Z"
ध्यान दें कि यह निर्दिष्ट प्रारूप dd.MM.yyyy
नहीं है। क्या spring.jackson.date-format
दस्तावेज के रूप में काम नहीं कर रहा है?
ग्रेट। लेकिन अगर मैं केवल java.util.Date (या java.sql.Date) का उपयोग कर रहा हूं, तो मैं इसका उपयोग कैसे करूं? – MiguelMunoz