揚鞭在彈簧引導配置僅示出一個方法與POST映射和一個方法以獲得從每個控制器映射。揚鞭忽略與另一種方法GET和POST映射而忽略PUT和DELETE映射的所有方法。我的配置:揚鞭在Spring引導配置示出了僅與POST方法及GET映射
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket api(){
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage("my.project.controllers"))
.paths(PathSelectors.ant("/api/*"))
.build();
}
}
依賴在pom.xml中:
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.7.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.7.0</version>
<scope>compile</scope>
</dependency>
我的控制器的代碼:
@RestController @RequestMapping(值= 「/ API /用戶」,產生=「應用/ json; charset = UTF-8「) public class UserController {
@Autowired
private UserService userService;
protected UserService getService() {
return userService;
}
@RequestMapping(method = GET)
public Page<User> query(@RequestParam Map<String, Object> parameters, Pageable pageable) {
return getService().query(parameters, pageable);
}
@ResponseStatus(CREATED)
@RequestMapping(method = RequestMethod.POST)
public ResponseEntity<User> create(@RequestBody User entity) {
return ResponseEntity.status(HttpStatus.CREATED).body(getService().create(entity));
}
@RequestMapping(value = "/{id:[0-9]+}", method = RequestMethod.PUT)
public ResponseEntity<User> update(@PathVariable Long id, @RequestBody User entity) {
return ResponseEntity.ok(getService().update(id, entity));
}
@RequestMapping("/current")
public ResponseEntity current() {
return ResponseEntity.ok(userService.getUser());
}
@ResponseStatus(HttpStatus.OK)
@RequestMapping(value = "/{id:[0-9]+}/enable", method = RequestMethod.POST)
public void enable(@PathVariable("id") final long id) {
userService.enable(id);
}
@ResponseStatus(HttpStatus.OK)
@RequestMapping(value = "/{id:[0-9]+}/disable", method = RequestMethod.POST)
public void disable(@PathVariable("id") final long id) {
userService.disable(id);
}
@RequestMapping(value = "/histories", method = RequestMethod.GET)
public List<UserHistory> histories() {
return userService.histories();
}
}
可能是我需要添加一些更多的配置或添加別的東西?
你能不能請出示一些控制器代碼? –
我添加了控制器代碼。其他控制器是一樣的。 Swagger只顯示查詢方法和創建方法。 –