play framework学习笔记之 表单提交,超链接提交 与 页面渲染
分类: play framework 2011-04-15 14:28 69人阅读 评论(0) 收藏 举报
1,超链接 提交
run
public static void run(long num,String name){
System.out.println(num); render(); }
2,表单提交
//推荐使用这种非侵入式的写法,能使用Html的地方就不要用play自己的标签。这样有利于减轻前端的压力。
#{form @Application.postComment(post.id)}
//注意到了这个地方了吗?在超链接的时候@{Application.run(1)}是加大括号的,此处没有加,也仅仅是这里没加。
#{/form}
public static void postComment(Long postId, String author, String content) {
Post post = Post.findById(postId);
post.addComment(author, content);
show(postId);
}
其中show是另外一个static方法,在其内调用render对应渲染 对应的页面,取决于 route配置文件内的配置。
Post提交,路径控制
POST /run/{postId} Application.run
注意因为postId在#{form @Application.postComment(xx)}这个地方注入了,所以可以在route配置文件内被侦查到,其它的author,content都侦查不到。路径配置也是无效的。
render(n,m)
则在页面${n} ${m}来获取
或者也可以指明要渲染的页面 render("Application/run.html",n,m)
play framework学习笔记之 表单提交,超链接提交 与 页面渲染
分类: play framework 2011-04-15 14:28 69人阅读 评论(0) 收藏 举报
1,超链接 提交
run
public static void run(long num,String name){
System.out.println(num); render(); }
2,表单提交
//推荐使用这种非侵入式的写法,能使用Html的地方就不要用play自己的标签。这样有利于减轻前端的压力。
#{form @Application.postComment(post.id)}
//注意到了这个地方了吗?在超链接的时候@{Application.run(1)}是加大括号的,此处没有加,也仅仅是这里没加。
#{/form}
public static void postComment(Long postId, String author, String content) {
Post post = Post.findById(postId);
post.addComment(author, content);
show(postId);
}
其中show是另外一个static方法,在其内调用render对应渲染 对应的页面,取决于 route配置文件内的配置。
Post提交,路径控制
POST /run/{postId} Application.run
注意因为postId在#{form @Application.postComment(xx)}这个地方注入了,所以可以在route配置文件内被侦查到,其它的author,content都侦查不到。路径配置也是无效的。
render(n,m)
则在页面${n} ${m}来获取
或者也可以指明要渲染的页面 render("Application/run.html",n,m)