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 files
<body>
<button value= "Click 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 "/>//this is customized for users
</property>
<property name= "Messageconverters" >
<ref bean= "Jsonhttpmessageconverter"/>// This provides JSON support for @responsebody
</property>
</bean>
<bean id= "Jsonhttpmessageconverter"
C lass= "Org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"/>