首先需要导入两个包
com.springsource.org.codehaus.jackson-1.4.2.jar
com.springsource.org.codehaus.jackson.mapper-1.4.2.jar
如果不使用MAVEN可在官网上下载,包含了所有Spring需要的Jar包:
spring-framework-3.0.5.CI-834-dependencies.zip
在配置文件中加入如下配置:
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"> <mvc:annotation-driven/> </beans>
Action
@ResponseBody
@RequestMapping("/tree/xmlTreeAction")
public List<Node> getTreeInfo(String type,HttpSession session) throws IOException{
SecurityContext sc = (SecurityContext)session.getAttribute("SPRING_SECURITY_CONTEXT");
Node es = null;
Authentication auth = sc.getAuthentication();
UserDetails user = (UserDetails)auth.getPrincipal();
es = bizTree.loadAllnode(user.getUsername());
List<Node> list = new ArrayList<Node>();
list.add(es);
return list;
}
注意必须添加ResponseBody元注解