First prepare juqury-ui, Ztree js files and CSS files, the next step Xiang see this article hope to help you
The first step: First prepare Juqury-ui, Ztree js files and CSS files
Step two: Write in example.jsp file code
Copy Code code as follows:
.. Introduction of jQueryUI, Ztree js and css file
<body>
<button value= "Click on the Dialog dialog box of the pop-up tree" onclick = "gettree ()"/>
<div id= "Ztree" class= ztree "/>"
</body>
<script type= "Text/javascript" >
function Gettree () {
var url = "<c:url value= ' xx.html '/>";
var setting={
};
var znodes =[];
var option={
width:200,
hight:300
};
$.ajax ({
Url:url,
success:function (data) {
$.each (data,funtion (n,d) {
Znode.push ({
Id:d.id,
Name:d.name,
Pid:d.pid
})
});
$.fn.init.ztree (' #ztree '), Setting,znode);
$ (' #ztree '). dialog (option);
}
})
}
</script>
Step three: Provide data backstage
Copy Code code as follows:
@RequestMapping ("/zone_ajaxtree")
@ResponseBody
public list<zonebody> Zone_ajaxtree () {
list<zonebody> zones = Zonebodyservice.getzone_ajax ();
return zones;
}
Because to use the @responsebody, to introduce Jackson-core-asl-1.8.7.jar and Jackson-mapper-asl-1.8.7.jar, there is code in the Mvc.xml file:
Copy Code code as follows:
<bean
class= "Org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" >
<property name= "Webbindinginitializer" >
<bean class= "Com.building.controller.BindingInitializer" />//here for user-defined
</property>
<property name= "Messageconverters" >
<ref bean= " Jsonhttpmessageconverter "/>//here provides JSON support for @responsebody
</property>
</bean>
<bean id= "Jsonhttpmessageconverter"
class= " Org.springframework.http.converter.json.MappingJacksonHttpMessageConverter "/>