che*_*eng 4 redirect playframework
当我在一个动作中调用其他动作时,它也会在Play 1.1 RC中显示自己的模板,当我Redirect("...url")无法正常工作时,是否有人可以帮助我?
小智 12
只是为了添加上面的答案,这里是你如何重定向到外部网址:
public static void index(){redirect("http://geeks.aretotally.in"); }
要重定向,只需调用操作即可.从文档中的示例:
public static void show(Long id) {
Article article = Article.findById(id);
render(article);
}
public static void edit(Long id, String title) {
Article article = Article.findById(id);
article.title = title;
article.save();
show(id);
}
Run Code Online (Sandbox Code Playgroud)
在编辑操作结束时,对show(...)的调用将导致客户端浏览器上的重定向,就像它们访问了路由到show方法的相同URL一样.
由于这些答案均未提供执行此操作的通用/可重用方法,因此这是我的代码。这使您可以在conf/routes文件中创建任意数量的重定向,而无需为每个重定向创建控制器。
是的,这是微不足道的,但也许对某人有用。
conf /路由:
GET /admin Application.redirect(url:'/admin/index.html')
Run Code Online (Sandbox Code Playgroud)
app / controllers / Application.java:
public class Application extends Controller {
public static void redirect(String url) {
redirect(url, true);
}
}
Run Code Online (Sandbox Code Playgroud)