프론트엔트 (Vue2)
<template>
<div class="hello">
<button @click="dateTest">요청</button>
{{time}}
</div>
</template>
<script>
import axios from 'axios'
export default {
data() {
return {
time: ""
}
},
methods: {
dateTest() {
console.log("요청")
const now = new Date()
console.log(now);
axios
.post("http://localhost:5000/datetest", {
time:now
})
.then((res)=>{
this.time=res.data.time
console.log(res)
})
}
},
}
</script>
백엔드
package com.accurasoft.aop.dto;
import java.time.LocalDateTime;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.format.annotation.DateTimeFormat.ISO;
public class DateDTO {
@DateTimeFormat(iso = ISO.DATE_TIME)
LocalDateTime time;
public LocalDateTime getTime() {
return time;
}
public void setTime(LocalDateTime time) {
this.time = time;
}
}
@CrossOrigin
@RestController
public class LDTController {
@PostMapping("/datetest")
public DateDTO save(@RequestBody DateDTO dto, ZoneId zoneId, TimeZone timeZone, Locale locale) {
System.out.println("ZoneId: "+zoneId.toString());
System.out.println("TimeZone: "+timeZone.toString());
System.out.println("locale: "+locale.toString());
System.out.println(dto.getTime().toString());
return dto;
}
}
댓글