@ParentPackage("all")
@Namespace("/project")
public class ProjectAction extends BaseAction {
public final static Logger logger = LoggerFactory
.getLogger(ProjectAction.class);
@Autowired(required=true)
private ProjectService projectService;
private String code;
private Project project;
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public Project getProject() {
return project;
}
public void setProject(Project project) {
this.project = project;
}
@RequiresPermissions("SYS_PROJECT:FIND")
@Action(value = "findAll", results = { @Result(name = "success", type = "json", params = {
"ignoreHierarchy", "false", "root", "dataMap" }) })
public String findAll() {
Subject subject = SecurityUtils.getSubject();
if (subject.isPermitted("SYS_PROJECT:FIND")){
System.out.println("授权验证通过");
}
ProjectCriteria projectCriteria = new ProjectCriteria();
Criteria criteria = projectCriteria.createCriteria();
if (project == null) {
project = new Project();
}
if (project.getCode() != null
&& !"".equals(project.getCode().trim())) {
criteria.andCodeLike("%" + project.getCode() + "%");
}
if (project.getName() != null
&& !"".equals(project.getName().trim())) {
criteria.andNameLike("%" + project.getName() + "%");
}
int total = 0;
try
{
System.out.println(projectService==null);
total = projectService.countByCriteria(projectCriteria);
}catch(RuntimeException e){
System.out.println(e);
}
dataMap.put("total", total);
dataMap.put("rows", projectService.selectByCriteria(projectCriteria));
return SUCCESS;
}
@RequiresPermissions("SYS_PROJECT:ADD")
@Action(value = "add", results = { @Result(name = "success", type = "json", params = {
"ignoreHierarchy", "false", "root", "resultMap" }) })
public String add() {
try {
projectService.saveProject(project);
resultMap.put("success", "true");
resultMap.put("msg", "add success");
} catch (Exception e) {
resultMap.put("msg", "add error" + e.getStackTrace());
}
return SUCCESS;
}
@RequiresPermissions("SYS_PROJECT:UPD")
@Action(value = "toUpdate", results = { @Result(name = "success", type = "json", params = {
"includeProperties", "project.*" }) })
public String toUpdate() {
project = projectService.selectByPrimaryKey(this.getCode());
return SUCCESS;
}
@RequiresPermissions("SYS_PROJECT:UPD")
@Action(value = "update", results = { @Result(name = "success", type = "json", params = {
"ignoreHierarchy", "false", "root", "resultMap" }) })
public String update() {
try {
projectService.updateByPrimaryKey(project);
resultMap.put("success", "true");
resultMap.put("msg", "Update success");
} catch (Exception e) {
resultMap.put("msg", "Update error" + e.getMessage());
}
return SUCCESS;
}
@RequiresPermissions("SYS_PROJECT:DEL")
@Action(value = "delete", results = { @Result(name = "success", type = "json", params = {
"ignoreHierarchy", "false", "root", "resultMap" }) })
public String delete() {
try {
projectService.deleteByPrimaryKey(this.getCode());
resultMap.put("success", "true");
resultMap.put("msg", "Delete success");
} catch (Exception e) {
resultMap.put("msg", "Delete error" + e.getMessage());
}
return SUCCESS;
}
}
加上@RequiresPermissions注释后可以获取到授权信息,但是projectService无法注入。
【授权验证通过
true
java.lang.NullPointerException】
删除所有的@RequiresPermissions后正常。前台可以获取到数据。
shiro的配置也没有错,
<bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor" />
<bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator" depends-on="lifecycleBeanPostProcessor">
[color=red]<property name="proxyTargetClass" value="true" /> [/color]
</bean>
求解啊