本文介绍了JHipster,带有MultiPart和JSON的Spring Rest服务,挥舞/卷曲错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在JHipster上无法发布春季服务。
该服务包括MultipartFile,参数和JSON对象。据我所知,我应该可以这样发布:

I am having problems with JHipster to publish a rest spring service.The service includes a MultipartFile, parameters and a JSON object. To my knowledge, I should be able to publish as follows:

public @ResponseBody
    ResponseEntity<DocumentId> addDoc(@RequestPart(required = true) MultipartFile file, @RequestPart(required = false) String folder, @RequestPart(required = true) MetadataDoc metadata)

swagger api无法识别参数 metadata,将其声明为未定义数据类型。当我尝试进行curl请求时,出现以下错误:

The swagger api does not recognize the parameter "metadata" declaring it as "undefined"data type. And when I try to make a curl request, I get the following error:

2016-09-30 13:27:15.174  WARN 30451 --- [ XNIO-2 task-12] .m.m.a.ExceptionHandlerExceptionResolver : Resolved exception caused by Handler execution: org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'text/plain;charset=UTF-8' not supported
2016-09-30 13:27:15.298 DEBUG 30451 --- [ XNIO-2 task-14] c.q.smartgov.aop.logging.LoggingAspect   : Enter: com.queres.smartgov.web.rest.errors.ExceptionTranslator.processRuntimeException() with argument[s] = [org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'text/plain;charset=UTF-8' not supported]
2016-09-30 13:27:15.298 DEBUG 30451 --- [ XNIO-2 task-14] c.q.smartgov.aop.logging.LoggingAspect   : Exit: com.queres.smartgov.web.rest.errors.ExceptionTranslator.processRuntimeException() with result = <500 Internal Server Error,com.queres.smartgov.web.rest.errors.ErrorVM@3d872331,{}>

卷曲请求:

curl -X POST --header 'Content-Type: multipart/form-data' --header 'Accept: application/json' --header 'Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZG1pbiIsImF1dGgiOiJST0xFX0FETUlOLFJPTEVfVVNFUiIsImV4cCI6MTQ3Njk3NjY3N30.82FRMRSrrniEQcIhI6DtHEFf5ln3OSjS_6OWy-1d8h3Cp5MjRuxo04IuIxAX_WC8YJJ1QyLrq7loLUSQ8RV_Gw' -F file=@"result.txt" -F folder=folde -F metadata={"clave":"2","valor":"1"}  'http://127.0.0.1:8080/sd_api/api/almacen/addDoc'

我尝试了很多事情,有什么建议吗?

I have tried a lot of things, any suggestion?

谢谢!

推荐答案

最后,我采用了将JSON参数声明为a的解决方案字符串,由我自己解析。

Finally I took the solution of declare JSON parameter as a String, an parse it by myself.

如果有人知道如何将参数作为JSON对象发布,我将不胜感激。

If anybody knows how to publish the parameter as JSON Object I will appreciate any clue.

 ObjectMapper mapper = new ObjectMapper();
        try {
            return mapper.readValue(stringValue, mapper.getTypeFactory().constructCollectionType(List.class, MetadataDoc.class));
        } catch (IOException ex) {
            //throw exception
        }

这篇关于JHipster,带有MultiPart和JSON的Spring Rest服务,挥舞/卷曲错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-16 23:54