@IocBean
public class AdminCheckSession implements ActionFilter {
@Inject
private RedisService redisService;
@Override
public View match(ActionContext actionContext) {
HttpSession session = Mvcs.getHttpSession();
Admin admin = (Admin) session.getAttribute("admin");
if (null == admin)
return new ViewWrapper(new JspView("/404.jsp"),null); //返回404
else {
String loginName = admin.getUsername();
String adminInfo = redisService.get(loginName);//这里空指针
// String[] tmp = adminInfo.split(",", 4);
// if (!Toolkit.getIpAddress(Mvcs.getReq()).equals(tmp[3])) {
// Map<String,Object> params = Maps.newHashMap();
// params.put("Logining", Constants.LOGINING_EXIST);
// return new ViewWrapper(new JspView("views/admin/login"),params);
// }
}
return null;
}
4 回复
这个问题我回过好多次.
@Filters, 注入就不会传参, 传参就不能注入, 二选一
@Filters(@By(XXXX.class, args={"ioc:xxxFilter"})) // 没法逐个参数传
@Filters(@By(XXXX.class, args={"abc", "def", "ghi"})) // 可以传参,但没有注入
但方法还是有的, 虽然不能注入,但ActionContext里面有Ioc容器, 取一下需要的不就好了?
if (redisService == null)
redisService = actionContext.getIoc().get(RedisService.class);
@wendal OK
添加回复
请先登陆