多语言展示
当前在线:1909今日阅读:84今日分享:32

前端date类型的数据,后端如何接收

前端date类型的数据,后端如何用实体对象接收
方法/步骤
1

@RequestMapping(value = '/add',method = RequestMethod.POST)    @ResponseBody    public Map add(Product product){       Map maps = new HashMap();        try {    productService.save(product);

2

maps.put('message', '100');} catch (Exception e) {// TODO: handle exception}        return maps;    }后端实体对象直接

3

@InitBinder public void initBinder(WebDataBinder binder){ DateFormat format = new SimpleDateFormat('yyyy-MM-dd'); binder.registerCustomEditor(Date.class, new CustomDateEditor(format,true)); }后端必须配置,springmvc 默认不会自动转换date

4

政府认证

质量保证

公司担保

7

@RequestMapping(value = '/delete',method = RequestMethod.POST)    @ResponseBody    public Map delete(            @RequestParam('ids[]') List ids){        Map result = new HashMap<>();        try{        for(Long i:ids){        productService.delete(i);        }                      result.put('success',true);        }catch (RuntimeException e){            e.printStackTrace();            result.put('success',false);            result.put('errorInfo',e.getMessage());        }        return result;    }

推荐信息