今天学了springMVC使用ajax返回json对象,并在前台页面用jquery进行遍历,大家看完了可以尝试做一个简单的二/三级联动哦,
首先先导好spring+springMVC,jar包,这个大家都清楚,就不一一细列了,除外还需要导入两个json用的jar :
jackson-core-asl-1.9.7.jar
jackson-mapper-asl-1.9.7.jar
还有jquery-3.1.1.min.js
好了,下面开始代码演示 :
1.applicationContext.xml配置 :
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd