Quarkus反应性入门和删除操作
我正在浏览 quarkus Quarkus反应性入门页面和put and delete方法实现是丢失的。
似乎假设我们已经知道Quarkus,并且只是在阅读指南以从反应性转变为反应性。为什么他们不提供完整的例子,我不知道。我的意思是,如果不是指导,或者有人向您展示它是如何完成的?
放置应更换条目,并删除应删除。
PUT /{id} = replace
DELETE /{id} = delete
我的实体不是水果,而不是果实。
package de.icod.reso.resources;
import de.icod.reso.entities.Profile;
import io.quarkus.hibernate.reactive.panache.Panache;
import io.quarkus.panache.common.Sort;
import io.smallrye.mutiny.Uni;
import javax.enterprise.context.ApplicationScoped;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.net.URI;
import java.util.List;
import java.util.UUID;
@Path("/profile")
@ApplicationScoped
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class ProfileResource {
@GET
public Uni<List<Profile>> get() {
return Profile.listAll(Sort.by("name"));
}
@GET
@Path("/{id}")
public Uni<Profile> getSingle(UUID id) {
return Profile.findById(id);
}
@POST
public Uni<Response> create(Profile profile) {
return Panache.<Profile>withTransaction(profile::persist)
.onItem().transform(inserted -> Response.created(URI.create("/profile" + inserted.id)).build());
}
@PUT
@Path("/{id}")
public Uni<Response> replace(UUID id, Profile profile) {
// error: incompatible types: incompatible parameter types in method reference
return Panache.<Profile>withTransaction(profile::update)
.onItem().transform(updated -> Response.ok(URI.create("/profile" + updated.id)).build());
}
@DELETE
@Path("/{id}")
public Uni<Response> delete(UUID id) {
// delete entity by id
}
}
您可以填写两个丢失的功能吗?
我知道有,
但内容与入门页面中写的内容不同。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一般而言,入门和Quick Starts可能会略有不同。原因是入门的目的是帮助新用户快速设置一个小型工作项目,而QuickStart是展示所涉及的扩展功能的不同功能的地方。
我们试图确保文档始终是最新的,但是没有什么比快速启动之类的工作示例了。
在这种情况下,我不明白您的抱怨。
An example of PUT and DELETE is available in the
对于您的用例> fruit 和
uuid
而不是long
ID。我认为您不需要其他任何东西才能使它起作用。错误消息告诉您问题的原因:语法
panache.withtransaction(profile :: Update :: Update)
不正确。这是不起作用的,因为
profile.update(...)
期望在使用withtransaction
的方法参考时,您不会传递其他参数。另一方面,可以使用
panache.withtransaction(profile :: persist)
因为profile.persist()
是一种不需要参数的方法。这就是方法参考在Java中的工作方式。
也就是说,文档从未完成,并且根据我们收到的反馈会随着时间的流逝而变得更好。
另外,Stackoverflow可能不是解决此类问题的最佳场所。
我可能会在
用户
首先。如果您推出一个在某处给您麻烦的代码的示例,那么收到答案的速度更快,这样我们就可以运行它并为您提供有关它的问题的精确帮助。此问题中的示例为2年,此后发生了变化。实际上,该问题中引用的同一Quickstart和Tutorial现在与我使用的代码匹配。
Generally speaking, the Getting Started and the quickstarts might be slightly different. The reason is that the purpose of the Getting Started is to help a new user to set up a small working project quickly and the quickstart is a place to showcase different functionalities of the extensions involved.
We try to make sure that the documentation is always up to date but nothing beats a working example like the quickstart.
In this case I don't understand your complains.
An example of PUT and DELETE is available in the Hibernate Reactive with panache quickstart:
For your use case you need to use
Profile
instead ofFruit
, andUUID
instead ofLong
for the id. I don't think you need anything else to make it work.The error message is telling you the cause of the problem: the syntax
Panache.withTransaction(profile::update)
is not correct.This won't work because
profile.update(...)
expects additional parameters that you are not passing when using method reference withwithTransaction
.On the other hand, one can use
Panache.withTransaction(profile::persist)
becauseprofile.persist()
is a method that doesn't require parameters.This is how method reference works in Java.
That said, the documentation is never done and it will get better over time based on the feedback we receive.
Also, StackOverflow might not be the best place for this type of questions.
I would have probably asked this on the
users
stream on Zulip first. It's even faster to receive an answer if you push an example of the code that's giving you trouble somewhere, so that we can run it and give you precise help about what's wrong with it.The example in this question is 2 years old and things have changed since then. In fact, the same quickstart and tutorial referenced in that question now match the code I've used.
您可以在 https:htttps:https:> https: //quarkus.io/guides/hibernate-orm-panache#writing-a-jax-rs-resource 。
您还可以通过查看 hibernate反应性panache quick quick quick 和
You can find the information you are asking for at https://quarkus.io/guides/hibernate-orm-panache#writing-a-jax-rs-resource.
You can also compare reactive vs. non-reactive versions of the same application by looking at the Hibernate Reactive Panache Quickstart and the Hibernate ORM Panache Quickstart