grails - 如何将浏览器中 View 的URL映射到一个特定名称?

标签 grails url-mapping

我现在面临的新问题是,

我想在浏览我的应用程序而不是将URL作为 http:// localhost:8080 / merchant / 获得时,我只想显示:// localhost。

就像明智的做法,当我浏览我的应用程序的其他 View 时,我会得到像 http:// localhost:8080 / merchant / register / list 这样的URL,现在我也不想在其中显示应用程序 Controller 和操作名称,而是希望它显示一个一个单词可能是列表或其他我想要的东西。

我经历了URLMapping概念,但是我知道应该做什么。.我知道我应该学习理解,然后问是否有任何疑问,但是我没有很多时间。.所以请任何人告诉我确切需要做什么。

预先感谢,

最佳答案

实际上,如果您的网址中没有端口,则默认使用端口80。 apache http服务器在此端口上正常运行。

对于在Tomcat服务器上运行的grails应用程序,有两种不同的实现方法。

  • 更改tomcat服务器的端口(启动grails时使用Dserver.port参数)

    grails -Dserver.port=80 run-app
    

  • 或将apache http服务器用作您的tomcat服务器的代理。

  • http://www.unidata.ucar.edu/projects/THREDDS/tech/tds4.1/reference/TomcatBehindProxyServer.html

    编辑:

    对于URL的第二件事。如果我的问题正确,那么您希望将列表 View 作为默认 View 。
    为此,请使用以下URL映射(尽管未对其进行测试):
    static mappings = {
        "/$controller" {
           controller = "controller"
           action = "list"
        }
    }
    

    编辑2:

    您只想查看操作而不是 Controller 名称。
  • 这仅适用于一个 Controller 。否则,grails将如何知道要使用哪个 Controller 的哪个 Action 。
  • ,您可以定义您的操作,这些操作无需家庭 Controller 的url中的 Controller 名称即可访问。
  • 设为家庭 Controller
  • 设置以下映射

  • "/$action"
     {
        controller = "yourController"
        action = "action"
     }
    


    请注意,这样所有其他 Controller 上的索引 Action 都将生效。 / controller将无法正常工作,因为它希望您对home Controller 中的名称controller进行操作。

    编辑3:
    您还可以为每个您希望在URL中没有 Controller 名称的情况下可访问的操作定义URL映射。这样,操作就不必在家庭 Controller 中了。



    "/myAction"
     {
        controller = "yourController"
        action = "myAction"
     }
    

    关于grails - 如何将浏览器中 View 的URL映射到一个特定名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5973774/

    相关文章:

    spring - grails插件动态bean创建

    grails - 网址中的编码斜杠问题

    grails - 如何在Grails 3.2.x拦截器中为 Controller 匹配操作null

    grails - 未加载Grails网址映射布局

    grails - 从过滤器返回false时使URLMapping失败?

    grails - 测试闭包是否为实例的 'injected"

    grails - 为什么我不能在集成测试中注入(inject) Controller ?

    grails - 为 Controller 中的所有方法创建Grails URLMapping?

    java - 我的 url 映射转移了我的 CSS 页面

    grails - 如何在 UrlMappings.groovy 中重写 Grails 中的 URI