Sping5MVC 需要导入包
jackson-annotations-2.9.4.jar
jackson-core-2.9.4.jar
jackson-databind-2.9.4.jar springAnnotation-servlet.xml配置
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<!-- 开启注解 -->
<mvc:annotation-driven/>
<!-- 注解扫描包 -->
<context:component-scan base-package="com.supercontrol.cms.controller.*" />
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
<property name="messageConverters">
<list>
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"/>
<bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter"/>
<bean class="org.springframework.http.converter.xml.SourceHttpMessageConverter"/>
<bean class="org.springframework.http.converter.FormHttpMessageConverter"/>
<bean class="org.springframework.http.converter.StringHttpMessageConverter"/>
</list>
</property>
</bean>
<!-- 静态资源访问 -->
<mvc:resources location="/IMG/" mapping="/IMG/**"/>
<mvc:resources location="/JS/" mapping="/JS/**"/>
<mvc:resources location="/CSS/" mapping="/CSS/**"/>
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
</beans>
前台利用jquery ui接受返回的json数据 重绘tables
/*重新绘制用户表*/
function rebuildTable(e,data){
var ss=new Array;
var temp=new Array;
table = e.dataTable();
oSettings = table.fnSettings();
table.fnClearTable(this);
// alert(data.length);
for(var j=0;j<data.length;j++)
{
var checkbox = "<input type='checkbox' value='false'/>"
var id="<span class='userid'>"+data[j].id+"</span>";
var username=data[j].username;
var password=data[j].password;
ss=[checkbox,id,username,password];
temp.push(ss);
table.oApi._fnAddData(oSettings, ss);
}
oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
table.fnDraw();
}
本文介绍Spring5 MVC的配置方法,包括必要的jar包引入、XML配置文件详解及前后台交互中JSON数据的处理过程。展示了如何通过配置启用注解支持、扫描指定包内的控制器类,并设置消息转换器来处理HTTP请求中的JSON数据。
1241

被折叠的 条评论
为什么被折叠?



