[springboot]字符串与Date互转
@Data public class xxxQuery{ //字符串转Date @DateTimeFormat(pattern = "<dateformate>") private Date date; }
@Data public class xxxVO{ //Date转字符串 @JsonFormat(pattern = "<dateformate>") private Date date; }
例如:
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@RestController public class xxxController{ @GetMapping("/") public xxxVO xxx(xxxQuery query){ xxxVO vo = new xxxVO(); vo.setDate(new Date()); return vo; } }