controller不写index(),拦截器拦截的请求是/

jfinal版本3.5

自定义controller继承了Controller,没有写index()方法,定义了拦截器,拦截器通过inv.getActionKey()获取请求,获取的请求都是/,如果controller里面写了index()方法,则拦截截通过inv.getActionKey()获取的请求正确。这个是什么原因呢?

config里配了

me.add("/salary", SalaryController.class,"/salary");

请求/salary,如果SalaryController.class里无index(),则拦截器通过inv.getActionKey()
获取的请求为/


评论区

杜福忠

2018-11-19 16:53

什么原因... 看源码呗.. 路由很极简, 几行代码:
/**
* Support four types of url
* 1: http://abc.com/controllerKey ---> 00
* 2: http://abc.com/controllerKey/para ---> 01
* 3: http://abc.com/controllerKey/method ---> 10
* 4: http://abc.com/controllerKey/method/para ---> 11
* The controllerKey can also contains "/"
* Example: http://abc.com/uvw/xyz/method/para
*/
public Action getAction(String url, String[] urlPara) {
Action action = mapping.get(url);
if (action != null) {
return action;
}

// --------
int i = url.lastIndexOf('/');
if (i != -1) {
action = mapping.get(url.substring(0, i));
urlPara[0] = url.substring(i + 1);
}

return action;
}

热门反馈

扫码入社