我在我的項目中使用swagger生成代碼來執行某些objcets(命名項目)的http請求(GET,POST和DELETE)。如何使用H2數據庫與swagger
這裏的問題是這些對象是在內存中創建的。我的意思是,當我重新啓動我的Web服務時,以前的更改將被刪除。所以,我想使用(本地)數據庫來保存這些更改。我對H2數據庫非常感興趣。我也想用JDBC來連接我的本地數據庫。這裏的主要問題是我不明白如何首先使用jdbc。其次,招搖把所產生的代碼對我來說太複雜了。我不知道我應該在哪裏做jdbc代碼...
我在這裏複製了用於兩個請求(例如POST和DELETE)的代碼。你能幫我做一下當地的h2數據庫嗎?我應該在這個班上做這個代碼嗎?
這裏是招搖的部分代碼:
@POST
@Consumes({"application/x-www-form-urlencoded"})
@Produces({"application/json"})
@io.swagger.annotations.ApiOperation(value = "", notes = "Creates a project and returns the whole object", response = Project.class, tags = {})
@io.swagger.annotations.ApiResponses(value = {
@io.swagger.annotations.ApiResponse(code = 200, message = "Created project", response = Project.class),
@io.swagger.annotations.ApiResponse(code = 500, message = "Internal API error/Server error", response = Project.class)})
public Response createProject(
@ApiParam(value = "Document name", required = true) @FormParam("name") String name,
@ApiParam(value = "Document title") @FormParam("trigram") String trigram, @Context SecurityContext securityContext)
throws NotFoundException {
return delegate.createProject(name, trigram, securityContext);
}
//url is localhost:8080/api/v1/projects/{id}
@DELETE
@Path("/{id}")
@io.swagger.annotations.ApiOperation(value = "", notes = "Deletes all projects", response = void.class, tags={ })
@io.swagger.annotations.ApiResponses(value = {
@io.swagger.annotations.ApiResponse(code = 200, message = "Project is deleted.", response = void.class),
@io.swagger.annotations.ApiResponse(code = 500, message = "Internal API error/Server error", response = void.class) })
public Response deleteProject(
@ApiParam(value = "Document ID",required=true) @PathParam("id") String id,@Context SecurityContext securityContext)
throws NotFoundException {
return delegate.deleteProject(id,securityContext); }
是你能解決這個@ salamanka44? – Sampada