url 时提示页面未找到。玩! + 斯卡拉
When url is change prompt page not found. Play! + Scala
分页后我的网页上有以下内容URL
http://localhost:9000/employee?p=2
每当更改参数"p"时,我都需要提示找不到页面。示例:
http://localhost:9000/employee?b=2
需要控制器输入notFound。我需要什么样的条件才能做到这一点?
参考:
控制器:
@Transactional(readOnly=true)
public static Result list(int pageNum, int listSize) {
employeeMap.clear();
Page page = appModel.page(pageNum, listSize);
employeeMap = ListUtil.getEmpMap(employeeMap, page.getEmpList());
AppModel employees = new AppModel(employeeMap, searchMap);
/* if statement initiate a notFound page if pageNum us not the expected value */
if (pageNum < 0 || pageNum > page.getPage().get("intLastPage")) {
return notFound("<h1>Page not found</h1>").as("text/html");
}
/* if statement that put a not search found message if no employee is found */
if (page.getEmpList().size() == 0) {
flash("success", "There is no search results for the specified conditions");
}
return ok(index.render(appModelForm.fill(employees),page));
}
路线:
# Employee list (look at the default values for pagination parameters)
GET /employee controllers.Application.list(p:Int ?= 1,l:Int ?= 125)
您可以通过更改路由来防止人们整体更改参数名称。但是要实现您想要做的所有可能性,您可以执行以下操作:
GET /employee/:p/:l controllers.Application.list(p:Int ?= 1,l:Int ?= 125)
GET /employee/p/:p controllers.Application.list(p:Int, 125)
GET /employee/l/:l controllers.Application.list(1, l:Int)
这取决于您如何处理模板中的 URL 调用,但是如果您可以让默认参数自动生成到 URL 中(如果用户未将它们放入),你可以只保留第一个。
召唤控制器的 URL 现在改为:
http://localhost:9000/employee/p/2
http://localhost:9000/employee/l/4
http://localhost:9000/employee/2/4
然后您可以将任何其他内容路由到未找到的控制器方法:
GET /employee/--String, empty or whatever else--- controllers.Application.returnNotFound
@Transactional(readOnly=true)
public static Result returnNotFound() {
return notFound("<h1>Page not found</h1>").as("text/html");
}
分页后我的网页上有以下内容URL
http://localhost:9000/employee?p=2
每当更改参数"p"时,我都需要提示找不到页面。示例:
http://localhost:9000/employee?b=2
需要控制器输入notFound。我需要什么样的条件才能做到这一点?
参考:
控制器:
@Transactional(readOnly=true)
public static Result list(int pageNum, int listSize) {
employeeMap.clear();
Page page = appModel.page(pageNum, listSize);
employeeMap = ListUtil.getEmpMap(employeeMap, page.getEmpList());
AppModel employees = new AppModel(employeeMap, searchMap);
/* if statement initiate a notFound page if pageNum us not the expected value */
if (pageNum < 0 || pageNum > page.getPage().get("intLastPage")) {
return notFound("<h1>Page not found</h1>").as("text/html");
}
/* if statement that put a not search found message if no employee is found */
if (page.getEmpList().size() == 0) {
flash("success", "There is no search results for the specified conditions");
}
return ok(index.render(appModelForm.fill(employees),page));
}
路线:
# Employee list (look at the default values for pagination parameters)
GET /employee controllers.Application.list(p:Int ?= 1,l:Int ?= 125)
您可以通过更改路由来防止人们整体更改参数名称。但是要实现您想要做的所有可能性,您可以执行以下操作:
GET /employee/:p/:l controllers.Application.list(p:Int ?= 1,l:Int ?= 125)
GET /employee/p/:p controllers.Application.list(p:Int, 125)
GET /employee/l/:l controllers.Application.list(1, l:Int)
这取决于您如何处理模板中的 URL 调用,但是如果您可以让默认参数自动生成到 URL 中(如果用户未将它们放入),你可以只保留第一个。
召唤控制器的 URL 现在改为:
http://localhost:9000/employee/p/2
http://localhost:9000/employee/l/4
http://localhost:9000/employee/2/4
然后您可以将任何其他内容路由到未找到的控制器方法:
GET /employee/--String, empty or whatever else--- controllers.Application.returnNotFound
@Transactional(readOnly=true)
public static Result returnNotFound() {
return notFound("<h1>Page not found</h1>").as("text/html");
}