当前状态:
我的控制器中有两种方法可以根据传递的参数获取数据。编码:
@RestController
@RequestMapping("/samples")
public class SampleController {
@RequestMapping(value = "/{id}", params = {"cost"}, method = RequestMethod.GET)
public String getSamplesByIdAndCost(@PathVariable String id, @RequestParam(value = "cost") String cost) {
return "result";
}
@RequestMapping(value = "/{id}", params = {"cost", "size"}, method = RequestMethod.GET)
public String getSamplesByIdCostAndSize(@PathVariable String id, @RequestParam(value = "cost") String cost,
@RequestParam(value = "size") String size) {
return "ID : " + id + " / COST : " + cost + " / SIZE : " + size;
}
}
一切正常,但招摇的文档不是我所期望的。
问题
有没有办法从请求 URL 中删除 {?size,cost} ?
这是我的案卷信息:
@Bean
public Docket myApi() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build()
.pathMapping("/")
.directModelSubstitute(LocalDate.class,
String.class)
.genericModelSubstitutes(ResponseEntity.class)
.alternateTypeRules(
newRule(typeResolver.resolve(DeferredResult.class,
typeResolver.resolve(ResponseEntity.class, WildcardType.class)),
typeResolver.resolve(WildcardType.class)))
.useDefaultResponseMessages(false)
.globalResponseMessage(RequestMethod.GET,
newArrayList(new ResponseMessageBuilder()
.code(500)
.message("500 message")
.responseModel(new ModelRef("Error"))
.build()))
.enableUrlTemplating(true);
}
@Autowired
TypeResolver typeResolver;
@Bean
UiConfiguration uiConfig() {
return new UiConfiguration(
"validatorUrl",// url
"none", // docExpansion => none | list
"alpha", // apiSorter => alpha
"schema", // defaultModelRendering => schema
UiConfiguration.Constants.DEFAULT_SUBMIT_METHODS,
false, // enableJsonEditor => true | false
true); // showRequestHeaders => true | false
}