atjiu / pybbs

更实用的Java开发的社区(论坛),Better use of Java development community (forum)
GNU Affero General Public License v3.0
1.87k stars 711 forks source link

角色列表,点击编辑,报500 #85

Closed Liuguozhu closed 5 years ago

Liuguozhu commented 5 years ago

先在数据库中添加一个角色, 然后再页面的角色列表中点击这个角色的编辑按钮,直接500,sql异常, ` org.springframework.jdbc.BadSqlGrammarException:

Error querying database. Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 3

The error may exist in co/yiiu/pybbs/mapper/PermissionMapper.java (best guess)

The error may involve defaultParameterMap

The error occurred while setting parameters

SQL: SELECT id,name,value,pid FROM permission WHERE id IN ()

Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 3

解决方案1 co.yiiu.pybbs.service.PermissionService的selectByRoleId(Integer roleId)方法中修改如下 // 根据角色id查询所有的权限 public List selectByRoleId(Integer roleId) { List rolePermissions = rolePermissionService.selectByRoleId(roleId); List permissionIds = rolePermissions .stream() .map(RolePermission::getPermissionId) .collect(Collectors.toList()); QueryWrapper wrapper = new QueryWrapper<>(); if (permissionIds.size() > 0) { wrapper.lambda().in(Permission::getId, permissionIds); } List permissionList = permissionMapper.selectList(wrapper); return permissionList; } ` 对permissionIds的长度进行判断后再加查询条件。 解决方案2 把添加角色的功能加上,通过添加角色进行相应数据的处理

atjiu commented 5 years ago

角色在创建的时候要关联权限, 不要直接去操作数据库, 请在后台配置, 是没有问题的