应用属性:
# Database Connection Properties
spring.datasource.url=jdbc:mysql://localhost:3306/quizmaker
spring.datasource.username=root
spring.datasource.password=Corona@123
# Specify the JDBC driver for MySQL
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
# Hibernate properties
spring.jpa.hibernate.ddl-auto=update
# # Connection pool settings
# spring.datasource.hikari.connection-timeout=20000
# spring.datasource.hikari.minimum-idle=5
# spring.datasource.hikari.maximum-pool-size=20
# spring.datasource.hikari.idle-timeout=300000
# Logging SQL statements
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
server.port=8081
我尝试执行上面的程序..但是我对@Getmapping和@PostMapping都遇到了相同的错误
{"timestamp":"2024-02-11T11:22:56.192+00:00",
"status":404,
"error":"Not Found",
"path":"/question/allQuestions"}
getAllQuestions() 的路径已使用
/allQuestions
定义,但您使用 /allQuestion
API 路径调用 API。
尝试检查您的控制器以调查 404 错误的原因。当您的应用程序无法在控制器中找到请求的资源(例如 /question/allQuestion 端点)时,通常会发生该错误。
您是否在控制器中正确注册了路径?
例如:
@RestController
@RequestMapping(path = "/question")
public class QuestionController {
@GetMapping(path = "/allQuestion")
ResponseEntity<?> getAllQuestions() {
return ResponseEntity.ok();
}
}