1. 程式人生 > >springboot處理 json 轉換成 實體物件

springboot處理 json 轉換成 實體物件

 可以使用@RequestBody

@PostMapping("/add")
    public Result add(@RequestBody LogisticsDemand demand){
        if(demand.getRefreshTime()==null){
            demand.setRefreshTime(new Date());
        }
        int result = logisticsDemandService.insertdemand(demand,demand.getOrders());

        if(result>0){
            return Result.success("儲存成功!");
        }else{
            return Result.error(501,"儲存失敗!");
        }

    }

時間格式的處理

@JsonFormat( pattern="yyyy-MM-dd HH:mm:ss")
    private Date timeLimit;

參考: