Jersey CRUDRESTful教程

Jersey CRUDRESTful教程,jersey,crud,Jersey,Crud,我已经成功地建立了一个基于此。然而,我没有任何运气在它上面扩展。具体地说,我正在尝试在某处(任何地方)插入一个新方法,该方法将接受“ID”,这是来自web浏览器的参数 例如,我尝试了我能想到的所有方法来插入此方法: public class Gateway{ public static void gateway (String id) throws IOException{ FileWriter out = new FileWriter("C:\\Atest.t

我已经成功地建立了一个基于此。然而,我没有任何运气在它上面扩展。具体地说,我正在尝试在某处(任何地方)插入一个新方法,该方法将接受“ID”,这是来自web浏览器的参数

例如,我尝试了我能想到的所有方法来插入此方法:

public class Gateway{

    public static void gateway (String id) throws IOException{
            FileWriter out = new FileWriter("C:\\Atest.txt");
            out.write("Hello "+id);
            out.close();
            }
}
分为5.3级或5.3级

例如,在TodoResource中: 原始的-

我试图通过网关()-

有人能告诉我如何将我的方法合并到这个例子中,这样它就不会忽略它了吗


谢谢。

根据您使用的浏览器,有些浏览器更喜欢应用程序XML而不是文本XML。因此,很可能正在调用以下方法,而不是将Bridge.gateway(id)方法添加到的方法:

@GET
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public Todo getTodo() {
    Todo todo = TodoDao.instance.getModel().get(id);
    if(todo==null)
        throw new RuntimeException("Get: Todo with " + id +  " not found");
    return todo;
}
// For the browser
@GET
@Produces(MediaType.TEXT_XML)
public Todo getTodoHTML() {
    Todo todo = TodoDao.instance.getModel().get(id);
    if(todo==null)
        throw new RuntimeException("Get: Todo with " + id +  " not found");
Bridge.gateway(id)  //Here I tried to pass id   
return todo;
}
@GET
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public Todo getTodo() {
    Todo todo = TodoDao.instance.getModel().get(id);
    if(todo==null)
        throw new RuntimeException("Get: Todo with " + id +  " not found");
    return todo;
}