我在我的项目中使用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