简体   繁体   中英

grails url mappings controller

In my app - grails 3.0 I'm trying to return custom URL: /book/showbook/2 The controller has two actions:

action1 - collecting user form and create object book

action2 - showing the information of the created book.

Spring security plugin is installed.

Problem : instead of displaying: /book/showbook/2 the result of the submit button is: /book/showbook .

URL mappings code:

  static mappings = {
            "/book/showbook/$id?(.$format)?"(controller: 'game', action: 'showbook')

            "/$controller/$action?/$id?(.$format)?"{
                constraints {
                }
            }

View action 1 code:

<button type="submit" class="btn btn-danger btn-xs" params:[id: ${bookID}]>Submit data</button>

Action2 code:

def showbook(Book book) {
        respond book
    }

I don't think you are creating the form as it should be. You can read the Grails official form tag. http://docs.grails.org/latest/ref/Tags/form.html

Please try this

<g:form name="book" action="showbook" id="${bookID}">
    <button type="submit" class="btn btn-danger btn-xs">Submit data</button>
</g:form>

Please make sure that ${bookID} is defined somewhere in your gsp or passed from your modal to the appropriate view otherwise, it will not work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM