• <bdo id='CWTb8'></bdo><ul id='CWTb8'></ul>

    1. <i id='CWTb8'><tr id='CWTb8'><dt id='CWTb8'><q id='CWTb8'><span id='CWTb8'><b id='CWTb8'><form id='CWTb8'><ins id='CWTb8'></ins><ul id='CWTb8'></ul><sub id='CWTb8'></sub></form><legend id='CWTb8'></legend><bdo id='CWTb8'><pre id='CWTb8'><center id='CWTb8'></center></pre></bdo></b><th id='CWTb8'></th></span></q></dt></tr></i><div id='CWTb8'><tfoot id='CWTb8'></tfoot><dl id='CWTb8'><fieldset id='CWTb8'></fieldset></dl></div>
        <legend id='CWTb8'><style id='CWTb8'><dir id='CWTb8'><q id='CWTb8'></q></dir></style></legend>

        <small id='CWTb8'></small><noframes id='CWTb8'>

        <tfoot id='CWTb8'></tfoot>
      1. 如何使用 Struts2 REST 插件创建自定义方法

        时间:2023-09-24
            <tbody id='xvKR7'></tbody>
          <tfoot id='xvKR7'></tfoot>

          <legend id='xvKR7'><style id='xvKR7'><dir id='xvKR7'><q id='xvKR7'></q></dir></style></legend>

          <small id='xvKR7'></small><noframes id='xvKR7'>

              <i id='xvKR7'><tr id='xvKR7'><dt id='xvKR7'><q id='xvKR7'><span id='xvKR7'><b id='xvKR7'><form id='xvKR7'><ins id='xvKR7'></ins><ul id='xvKR7'></ul><sub id='xvKR7'></sub></form><legend id='xvKR7'></legend><bdo id='xvKR7'><pre id='xvKR7'><center id='xvKR7'></center></pre></bdo></b><th id='xvKR7'></th></span></q></dt></tr></i><div id='xvKR7'><tfoot id='xvKR7'></tfoot><dl id='xvKR7'><fieldset id='xvKR7'></fieldset></dl></div>

                • <bdo id='xvKR7'></bdo><ul id='xvKR7'></ul>
                • 本文介绍了如何使用 Struts2 REST 插件创建自定义方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我的问题涉及在操作中创建自定义方法.我正在使用 Struts2 和 REST 插件来实现 RESTful WebService.我的动作类如下:

                  My problem concerns the creation of a custom method within an action. I'm using Struts2 and REST Plugin in order to implement a RESTful WebService. My action class is the following:

                  public class SampleController implements ModelDriven<Object> {
                  
                  private Sample sample = new Sample();
                  private Collection<Sample> list;
                  private int id;
                  
                  public HttpHeaders create() {
                      sdao.save(sample);
                      return new DefaultHttpHeaders("create");
                  }   
                  
                  
                  public HttpHeaders destroy() {
                      return new DefaultHttpHeaders("destroy");
                  }
                  
                  public HttpHeaders show() {
                      return new DefaultHttpHeaders("show").disableCaching();
                  }
                  
                  public HttpHeaders update() {
                      sdao.save(sample);
                      return new DefaultHttpHeaders("update");
                  }
                  
                  public HttpHeaders index() {
                      list = sdao.findAll();
                      return new DefaultHttpHeaders("index").disableCaching();
                  }
                  
                  public Object getModel() {
                      return (list != null ? list : sample);
                  }
                  
                  
                  public int getId() {
                      return id;
                  }
                  
                  public void setId(Integer id) {
                      if (id != null) {
                          this.sample = (Sample) sdao.findById(id);
                      }
                      this.id = id;
                  }
                  

                  }

                  我可以通过 GET HTTP 方法正确访问资源.为了使用自定义方法,通过将参数传递给搜索资源来调用,即

                  I can access to a resource via a GET HTTP method correctly. In order to use a custom method, called by passing a parameter to search resources i.e

                  public searchBySenderName(String senderName) {
                      list.addAll(sdao.findBySenderName(senderName))
                  }    
                  

                  正确的程序是什么?如何通过 GET 以下 URL 调用它?

                  What is the correct procedures? How can I call it via GET following URL?

                  推荐答案

                  您可以从 GET 的任何预定义方法(index, show) 在您的情况下,请参阅 RESTful URL 映射逻辑 .

                  You can call custom method from any of the predefined methods for GET (index, show) in your case, see RESTful URL mapping logic .

                  RESTful URL 映射逻辑

                  这个 Restful 动作映射器强制执行 Ruby-On-Rails REST 样式的映射.如果未指定方法(通过 '!' 或 'method:' 前缀),则方法是猜测的";在使用 REST 风格的约定来检查URL 和 HTTP 方法.已给予特别注意以确保这一点映射器与代码隐藏插件一起正常工作,以便 XML无需配置.

                  This Restful action mapper enforces Ruby-On-Rails REST-style mappings. If the method is not specified (via '!' or 'method:' prefix), the method is "guessed" at using REST-style conventions that examine the URL and the HTTP method. Special care has been given to ensure this mapper works correctly with the codebehind plugin so that XML configuration is unnecessary.


                  当然,您可以更改动作映射器使用的方法名称,但这会影响整个应用程序.如果您已经占用了一个资源 URL,那么您应该使用另一个来执行它的工作.这是在您使用严格的 rest 映射器的情况下.在混合模式你可以将通常的操作映射到某个操作方法.


                  Of course you can change the method names used by the action mapper, but it will affect a whole application. If you already occupied a resource URL then you should use another to perform its job. This is in case if you are using a strict rest mapper. In the mixed mode you can map an usual action to some action method.

                  REST 和非 RESTful URL 的共同配置

                  如果您想在 REST 旁边继续使用一些非 RESTful URL东西,那么你必须提供一个配置,利用给映射器.

                  If you want to keep using some non-RESTful URL's alongside your REST stuff, then you'll have to provide for a configuration that utilizes to mappers.

                  插件包含自己的配置.如果你看剩下的插件 jar,您将看到 struts-plugin.xml 并在其中看到插件所做的一些配置设置.通常,插件只是按照它想要的方式设置事物.您可能经常需要覆盖这些设置在您自己的 struts.xml 中.

                  Plugins contain their own configuration. If you look in the Rest plugin jar, you'll see the struts-plugin.xml and in that you'll see some configuration settings made by the plugin. Often, the plugin just sets things the way it wants them. You may frequently need to override those settings in your own struts.xml.


                  最后,您可能不会通过 !method: 前缀指定方法,因为它受到默认配置的限制.


                  And last, you mightn't specify a method via ! or method: prefix because it's restricted by default configuration.

                  这篇关于如何使用 Struts2 REST 插件创建自定义方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:jdk9 win10为什么不能运行struts2.5.13 下一篇:使用 param 标签抑制空参数

                  相关文章

                  <small id='oGWnQ'></small><noframes id='oGWnQ'>

                • <tfoot id='oGWnQ'></tfoot>

                      <bdo id='oGWnQ'></bdo><ul id='oGWnQ'></ul>

                  1. <legend id='oGWnQ'><style id='oGWnQ'><dir id='oGWnQ'><q id='oGWnQ'></q></dir></style></legend>
                  2. <i id='oGWnQ'><tr id='oGWnQ'><dt id='oGWnQ'><q id='oGWnQ'><span id='oGWnQ'><b id='oGWnQ'><form id='oGWnQ'><ins id='oGWnQ'></ins><ul id='oGWnQ'></ul><sub id='oGWnQ'></sub></form><legend id='oGWnQ'></legend><bdo id='oGWnQ'><pre id='oGWnQ'><center id='oGWnQ'></center></pre></bdo></b><th id='oGWnQ'></th></span></q></dt></tr></i><div id='oGWnQ'><tfoot id='oGWnQ'></tfoot><dl id='oGWnQ'><fieldset id='oGWnQ'></fieldset></dl></div>