2017-03-30 15:07

@JFinal 哈哈,这个问题可能是我理解上有误差。

2017-03-29 19:36

如果能:
xxx model = new xxx();
model.setName("test");
dao.save(model);也挺好的。

2017-03-29 19:32

倒是也是,JFinal 的model设计只能查询不能做数据承载问题,比如:
final xxx dao = new xxx.dao();只能查询,删除等于操作,因为整个service操作都是dao一路下来,就卡在保存数据或更新数据要new xxx().save/update()操作,从整体观下看的确些...,当然这样也不是不行,只是有时写代码时难免有些变扭

2017-03-27 08:59

@JFinal 这个问题,我来说两句, 用model+bean模式时有些需求手动维护或以构建数据临时数据承载字段,问题在于每次都要重启tomcat,因为这些加载都是随配置文件一次性启动加载好处也不用说,但片面的问题也随之出现。后期对这些进行操作必须得重新容器才生效,可以考虑是否实现annotation方能尽可的解决这类问题,另外注解表和注解路由引发其他问题的倒不用太担心了,现在很多框架也在使用成熟,且作为jdk8还重点强调annotation,所以两种方案是可以并存的,多种实现方案,多种选择各有所需求,两者结合,取长补短这样好些,集成插件多些大点的项目,开发麻烦就是麻烦在修改些东西不生效就得重启容器,很耗时间的。

2017-03-27 08:41

@JFinal 波总他说的这种,是这样的,hibernate是通过annotation或xml做映射,是有一个特性可设置为多种创建模式的,如果update模式,新增model或bean字段后,自动相应的表字段。

2017-03-25 15:41

@lantsui,1、shrio配置不对shrio拦截器没有启动;2、就是配置后没有重启容器,配置没有生效,先看控制有什么错误提示。

2017-03-19 21:46

@JFinal 修改了。

2017-03-19 13:05

重新调整了下,在start中加一了层:for (Routes routes : getRoutesList()) :
/**
* 启动插件
*/
public boolean start() {
Set excludedMethodName = buildExcludedMethodName();
ConcurrentMap authzMaps = new ConcurrentHashMap();
//逐个访问所有注册的Controller,解析Controller及action上的所有Shiro注解。
//并依据这些注解,actionKey提前构建好权限检查处理器。
for (Routes routes : getRoutesList()) {
for (Routes.Route route : routes.getRouteItemList()) {
Class controllerClass = route.getControllerClass();

String controllerKey = route.getControllerKey();

// 获取Controller的所有Shiro注解。
List controllerAnnotations = getAuthzAnnotations(controllerClass);
// 逐个遍历方法。
Method[] methods = controllerClass.getMethods();
for (Method method : methods) {
//排除掉Controller基类的所有方法,并且只关注没有参数的Action方法。
if (!excludedMethodName.contains(method.getName())
&& method.getParameterTypes().length == 0) {
//若该方法上存在ClearShiro注解,则对该action不进行访问控制检查。
if (isClearShiroAnnotationPresent(method)) {
continue;
}
//获取方法的所有Shiro注解。
List methodAnnotations = getAuthzAnnotations(method);
//依据Controller的注解和方法的注解来生成访问控制处理器。
AuthzHandler authzHandler = createAuthzHandler(controllerAnnotations, methodAnnotations);
//生成访问控制处理器成功。
if (authzHandler != null) {
//构建ActionKey,参考ActionMapping中实现
String actionKey = createActionKey(controllerClass, method, controllerKey);
//添加映射
authzMaps.put(actionKey, authzHandler);
}
}
}
}
}
//注入到ShiroKit类中。ShiroKit类以单例模式运行。
ShiroKit.init(authzMaps);

// ShiroKit.init(jdbcAuthzService, authzMaps, false);
/**
* 设定登录,登录成功,未授权等url地址
*/
ShiroKit.setLoginUrl(loginUrl);
ShiroKit.setSuccessUrl(successUrl);
ShiroKit.setUnauthorizedUrl(unauthorizedUrl);
return true;
}

private List getRoutesList() {
List routesList = Routes.getRoutesList();
List ret = new ArrayList(routesList.size() + 1);
ret.add(routes);
ret.addAll(routesList);
return ret;
},经测试在configRoute中任意位置初始this.routes= me都可能实现注解如:
@RequiresRoles("superAdmin")或 @RequiresPermissions("/admin/user/add")进行拦截。

2017-03-19 12:59

@zzhkiller 加了一层for (Routes routes : getRoutesList())

2017-03-19 12:58

@zzhkiller 我重新调整了下ShiroPlugin的start获取路由这块:
/**
* 启动插件
*/
public boolean start() {
Set excludedMethodName = buildExcludedMethodName();
ConcurrentMap authzMaps = new ConcurrentHashMap();
//逐个访问所有注册的Controller,解析Controller及action上的所有Shiro注解。
//并依据这些注解,actionKey提前构建好权限检查处理器。
for (Routes routes : getRoutesList()) {
for (Routes.Route route : routes.getRouteItemList()) {
Class controllerClass = route.getControllerClass();

String controllerKey = route.getControllerKey();

// 获取Controller的所有Shiro注解。
List controllerAnnotations = getAuthzAnnotations(controllerClass);
// 逐个遍历方法。
Method[] methods = controllerClass.getMethods();
for (Method method : methods) {
//排除掉Controller基类的所有方法,并且只关注没有参数的Action方法。
if (!excludedMethodName.contains(method.getName())
&& method.getParameterTypes().length == 0) {
//若该方法上存在ClearShiro注解,则对该action不进行访问控制检查。
if (isClearShiroAnnotationPresent(method)) {
continue;
}
//获取方法的所有Shiro注解。
List methodAnnotations = getAuthzAnnotations(method);
//依据Controller的注解和方法的注解来生成访问控制处理器。
AuthzHandler authzHandler = createAuthzHandler(controllerAnnotations, methodAnnotations);
//生成访问控制处理器成功。
if (authzHandler != null) {
//构建ActionKey,参考ActionMapping中实现
String actionKey = createActionKey(controllerClass, method, controllerKey);
//添加映射
authzMaps.put(actionKey, authzHandler);
}
}
}
}
}
//注入到ShiroKit类中。ShiroKit类以单例模式运行。
ShiroKit.init(authzMaps);

// ShiroKit.init(jdbcAuthzService, authzMaps, false);
/**
* 设定登录,登录成功,未授权等url地址
*/
ShiroKit.setLoginUrl(loginUrl);
ShiroKit.setSuccessUrl(successUrl);
ShiroKit.setUnauthorizedUrl(unauthorizedUrl);
return true;
}

private List getRoutesList() {
List routesList = Routes.getRoutesList();
List ret = new ArrayList(routesList.size() + 1);
ret.add(routes);
ret.addAll(routesList);
return ret;
},Shiro完成权限控制是在ShrioInterceptor来做的。

2017-03-16 16:52

@zzhkiller 这个要配置,shrio.ini的访问规则,shiro.ini中的myRealm 的ShrioDbRealm这个类,这个是登录授权的处理类,如角色添加这片段代码
protected void authRole(int id, SimpleAuthorizationInfo info) {
List roleList = RoleService.me.byUid(id);
if (!sl.isEmpty(roleList)) {
for (Record role : roleList) {
info.addRole(role.get("name"));
authUrl(role.get("id"), info);
}
}
}
在界面如:
#if(shiro.hasRole("admin"))
#end
另外this.routers = routers; 放在最上面或最下面都不受影响的,详细的操作,
跑这看:http://www.jfinal.com/share/224

2017-03-16 16:44

@zzhkiller 没问题的,是可以拿的,你再看下我把全部的步骤了相应的代码也全站出来。

2017-03-14 16:56

@JFinal 哈哈支持JFinal的发展,分享是应该的。

2017-03-14 15:39

@JFinal 老大,按您的指意我开辟了个地址这:http://www.jfinal.com/share/224