[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;
    }
}

 

 

 

posted @ 2022-11-06 20:22  junlu  阅读(499)  评论(0编辑  收藏  举报