当我尝试使用邮递员(http://localhost:9690/regime/add)执行请求时,我收到 401 未经授权。
这是控制器包:
@AllArgsConstructor @RestController @RequestMapping(path ="/patient") public class PatientController
{
@Autowired
private PatientService patientService;
@GetMapping("/get")
public List<Patient> getAll(){
return patientService.getPatients();
}
@GetMapping("/getid/{patientId}")
public Optional<Patient> getByID(@PathVariable("patientId") Long patientId){
return patientService.getPatient(patientId);
}
@PostMapping("/add")
public Patient save(@RequestBody Patient patient) {
return patientService.save(patient);
}
@DeleteMapping("/delete/{patientId}")
public void delete(@PathVariable("patientId") Long patientId){
patientService.delete(patientId);
}
}
这是应用程序.属性:
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/nutridb?createDatabaseIfNotExist=true
spring.datasource.username=root
spring.datasource.password=
spring.jpa.hibernate.ddl-auto=update
spring.jpa.hibernate.dialect=org.hibernate.dialect.nutridb
spring.jpa.show-sql=true
server.port=9690`
我看到端点是错误的。试试这个
http://localhost:9690/病人/add通过HTTP方法POST
或者您可以使用 CURL 尝试此命令(您应该使用您想要传递的数据更改下面示例中的数据)
curl -d '{"key1":"value1", "key2":"value2"}' -H "Content-Type: application/json" -X POST http://localhost:9690/patient/add