当我为 swagger 文档添加以下依赖项时,它不起作用
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.2.0</version>
</dependency>
它应该在
swagger-ui/index.html
页面上提供 API 列表,但它给出的是空页面。
下面是控制器类
import com.vikram.explorespringboot.entity.Person;
import com.vikram.explorespringboot.service.Impl.PersonServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Optional;
@Controller
public class PersonController {
@Autowired
PersonServiceImpl personService;
@GetMapping("/person/{id}")
public ResponseEntity<Optional<Person>> getPersonById(@PathVariable int id){
Optional<Person> person = personService.getPersonById(id);
return ResponseEntity.ok(person);
}
@GetMapping("/persons/{age}")
public ResponseEntity<List<Person>> getPersonByAge(@PathVariable int age){
List<Person> person = personService.getPersonByAge(age);
return ResponseEntity.ok(person);
}
@GetMapping("/person")
public ResponseEntity<List<Person>> getPersonList(){
List<Person> persons = personService.getPersonList();
return ResponseEntity.ok(persons);
}
@PostMapping("/person")
public ResponseEntity<Person> createPerson(@RequestBody Person person){
Person newPerson = personService.createPerson(person);
return new ResponseEntity<>(newPerson, HttpStatus.CREATED);
}
}
我只想为我的API启用swagger ui,我指的是这个网站在浏览了许多youtube教程后
由于您使用的是 springdoc-openapi java 库。我相信 Swagger UI 页面或更确切地说 OpenAPI UI 页面将在以下样式 url 中提供:
http://server:port/context-path/swagger-ui.html