在我的应用程序-grails 3.0中,我试图返回自定义URL:/ book / showbook / 2
Controller 有两个 Action :
action1-收集用户表单并创建对象簿
Action 2-显示所创建书籍的信息。
安装了Spring Security插件。
问题:而不是显示: / book / showbook / 2 提交按钮的结果是:
/ book / showbook 。
URL映射代码:
static mappings = {
"/book/showbook/$id?(.$format)?"(controller: 'game', action: 'showbook')
"/$controller/$action?/$id?(.$format)?"{
constraints {
}
}
查看 Action 1代码:
<button type="submit" class="btn btn-danger btn-xs" params:[id: ${bookID}]>Submit data</button>
Action2代码:
def showbook(Book book) {
respond book
}
最佳答案
我认为您没有按原样创建表单。
您可以阅读Grails官方表格标签。
http://docs.grails.org/latest/ref/Tags/form.html
请尝试这个
<g:form name="book" action="showbook" id="${bookID}">
<button type="submit" class="btn btn-danger btn-xs">Submit data</button>
</g:form>
请确保$ {bookID}是在gsp中定义的,或者已从模态传递到适当的 View ,否则将无法使用。
关于url - Grails URL映射 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40093628/