私のプロジェクトでは、いくつかのオブジェクト(名前付きプロジェクト)に対してHTTPリクエスト(GET、POST、およびDELETE)を行うコードを生成するためにswaggerを使用しました。スワッガーでH2データベースを使用する方法
ここでの問題は、これらのオブジェクトがメモリ内に作成されていることです。 Webサービスを再起動すると、以前の変更が削除されます。したがって、これらの変更を保存するために(ローカル)データベースを使用したいと思います。私はH2データベースに本当に興味があります。ローカルデータベースに接続するためにJDBCも使用したいと思います。ここでの主な問題は、まずjdbcの使い方を理解できていないことです。第二に、スガッガーによって生成されたコードは私にとっては複雑すぎる。私はどこでjdbcコードを実行すべきかわかりません...
2つのリクエスト(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