将单个控制器映射到多个方法/操作

时间:2018-03-28 07:43:13

标签: grails groovy

我的控制器名称是...登录...
和方法/行动名称如.... HomeContent .....汽车......等

我也在这里发布我的控制器代码..

class LoginController {
    def dataSource;

    static allowedMethod = [userLogin:"POST",HomeContent:"GET",Disclaimer:"GET",FAQ:"GET",OurTeam:"GET",ourPortfolio:"GET",privacyPolicy:"GET",beautyTips:"GET",dietNutrition:"GET",healthFitness:"GET",yoga:"GET",mentalStress:"GET",automotive:"GET",digitalMarketing:"GET",ecommerce:"GET",education:"GET",finance:"GET",foodAndBeverage:"GET",marketUpdates:"GET",realState:"GET",coWorkingSpaces:"GET",homeRemodeling:"GET",scienceAndTechnology:"GET",sportsMania:"GET",travelAndTourism:"GET",boxOffice:"GET",dayToDayNewsUpdates:"GET",mediaGossip:"GET",poertyZone:"GET",lifestyleMagazine:"GET",becomeAContributor:"GET"]


    def HomeContent()
{
    def query ="SELECT  id,post_title,post_date,post_content FROM wp_posts where post_status='publish' and post_type='post' ORDER BY post_date  DESC limit 10"

        def db = new Sql(dataSource)
        def json = db.rows(query)
        render json as JSON
}



    // About Us section starts here         
      def Disclaimer()
    {

        def query = "select distinct id,post_title,post_date,post_content from wp_posts where post_title='disclaimer' and post_status='publish'"

        def db = new Sql(dataSource)
        def json = db.rows(query)
        render json as JSON
    }

     def FAQ()
     {
         def query = "select distinct id,post_title,post_date,post_content from wp_posts where post_title='FAQ' and post_status='publish'"

        def db = new Sql(dataSource)
        def json = db.rows(query)
        render json as JSON
     }

和我的URLMapping代码在这里..

class UrlMappings {

    static mappings = {

      "/Login"(controller:"Login",action:"HomeContent")


        "/"(view:"/index")
        "500"(view:'/error')
    }
}

1 个答案:

答案 0 :(得分:0)

为UrlMappings添加通用支持,假设您只需要:

//inside static mappings:

"/$controller/$action?"{ }