public class Route extends Routes { @Override public void config() { /** * 后台路由配置 */ addInterceptor(new TokenInterceptor()); add("/admin/auth", AuthController.class); add("/admin", HomeController.class); setBaseViewPath("/WEB-INF/views"); add("/admin/swagger", SwaggerController.class); } } public class ManageServices { private final Logger logger = Logger.getLogger(ManageServices.class); private Admin admin=new Admin(); private Cache platform = Redis.use("platform"); public void setRedis(int roleId) { try { List<String> authorities=new ArrayList<>(); authorities.add("oss:upload"); List<Record> records= Db.find("select a.authority from t_menu a \n" + "where id in(select menuid from t_permission where code=?)\n" + "and a.authority is not null",roleId); for (Record r:records) { authorities.add(r.getStr("authority")); } System.out.println(JSONObject.toJSON(authorities)); System.out.println(platform.exists("permission:"+roleId)); //platform出现空指针错误 platform.set("permission:"+roleId,JSONObject.toJSON(authorities)); }catch (Exception e) { System.out.println(e); } } }
好像在路由配置中添加拦截器后
private Cache platform = Redis.use("platform");//无法实例化但在每个方法体内 platform = Redis.use("platform"); 正常,总不能每次创建都做实例化吧
项目:JFinal
configConstant(Constants me){me.setConfigPluginOrder(1); 就可以了