grails - 如何通过从gsp文件到grails中的另一个gsp文件的链接获取传递的 “id”参数

标签 grails hyperlink params

假设我有一个带有链接的gsp文件正在使用标签“阅读更多。此链接将打开另一个gsp文件名” blog”,如果您查看网址栏,您会看到我当前的链接为“MyWebApp / post /博客/(当前i值)。那么,如何从新的blog.gsp文件中获取(当前i值)实际上是一个整数?

最佳答案

class PostController {

   def list() {
     // this action calls the page that has the "Read more" link
     def posts = Post.list()
     [posts: posts]
   }

   def blog() {
     // this action is triggered by the "Read more" link and
     // renders your blog post where you want the current ID
     def post = Post.get(params.id)
     [post: post]
   }
}

blog.gsp
<html>
....
${post.id}
....
</html>

关于grails - 如何通过从gsp文件到grails中的另一个gsp文件的链接获取传递的 “id”参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16743878/

相关文章:

java - 根据Java/Grails中的元素从 map 中提取/过滤数据

security - Grails - 是否有推荐的方法来处理 AJAX 形式的 CSRF 攻击?

grails - 使用beforeUpdate拦截器的Grails block 级事务给出了StackOverFlowException

ruby-on-rails - 将 ruby​​ 哈希转换为 URL 查询字符串......没有那些方括号

javascript - 如何使用remoteFunction将JavaScript变量传递给Grails Controller

Grails 3 和 IntelliJ 无法启动项目

facebook - 指向 Facebook 个人资料的链接并不总是有效

android使TextView中的链接可点击

javascript - 强制链接在新窗口中打开

ruby-on-rails - 如何在rails中将数组保存到数据库