美文网首页
linkedHashMap转对象

linkedHashMap转对象

作者: 炒面Z | 来源:发表于2017-12-20 15:44 被阅读0次
  • 使用jackson的mapper序列化
   ObjectMapper mapper = new ObjectMapper();
        List<TableColumns> columns = mapper.convertValue(params.get("columns"), new TypeReference<List<TableColumns>>() {
        });
  • springMvc中使用@RequestBody序列化,
    @Requestbody这个注解时,Spring会调用 AbstractMessageConverterMethodArgumentResolver 这个父类的 readWithMessageConverters 方法 通过 HttpMessageConverter类来进行解析,然后把数据要返回的对象上,再把绑定后的对象返回到Controller.
    //第一步缓存参数
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/export")
    @ResponseBody
    public R export(@RequestBody ExcelParam excelParam) {
        Assert.notNull(excelParam,"参数不能为空");
        Assert.notNull(excelParam.getUrl(),"url参数不能为空");
        Assert.notNull(excelParam.getColumns(),"columns参数不能为空");
        Assert.notNull(excelParam.getFileName(),"fileName参数不能为空");
        String key = UUID.randomUUID().toString();
        excelParamCache.put(key,excelParam);
        return CommonUtils.msg(key);
    }

相关文章

网友评论

      本文标题:linkedHashMap转对象

      本文链接:https://www.haomeiwen.com/subject/jmbgwxtx.html