Lar*_*lis 6 java rest swagger swagger-ui spring-boot
我使用Spring Boot 1.4和Swagger和Swagger UI时遇到了问题.使用@RequestBody参数时显示为数据类型字符串.这似乎不正确.
@ApiOperation(value = "simple message resource")
@ApiImplicitParams({
@ApiImplicitParam(name = "message", value = "Message to send", required = true, dataType = "com.larmic.springboot.swagger.rest.dto.MessageDto", paramType = "body")
})
@RequestMapping(value = "/api/message", method = RequestMethod.POST,
consumes = {"application/json", "application/xml"})
public void sendMessage(@RequestBody MessageDto message) {
System.out.println("ping");
}
Run Code Online (Sandbox Code Playgroud)
和
@XmlRootElement(name = "MessageDto")
@XmlAccessorType(XmlAccessType.FIELD)
@ApiModel(value = "MessageDto", description = "TODO")
public class MessageDto {
@ApiModelProperty(value = "Message content text", required = true, example = "some demo message")
private String content;
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
}
Run Code Online (Sandbox Code Playgroud)
我发现了许多使用MessageDto全名或设置@ApiModel正确值的修复,但似乎没有任何效果.
我在这里创建了一个完整的例子https://github.com/larmic/SpringBootAndSwaggerUI
也许有人可以帮忙.
g00*_*00b 10
这似乎是Springfox中的一个错误(#1344).您可以通过不使用来解决它@ApiImplicitParams
,但通过使用@ApiParam
注释注释您的方法参数本身:
@ApiOperation(value = "simple message resource")
@RequestMapping(value = "/api/message", method = RequestMethod.POST,
consumes = {"application/json", "application/xml"})
public void sendMessage(@ApiParam(name = "message", value = "Message to send", required = true) @RequestBody MessageDto message) {
System.out.println("ping");
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
11300 次 |
最近记录: |