Spring5 @ResponseBody 方式返回json数据 页面无刷新重回tables

本文介绍Spring5 MVC的配置方法,包括必要的jar包引入、XML配置文件详解及前后台交互中JSON数据的处理过程。展示了如何通过配置启用注解支持、扫描指定包内的控制器类,并设置消息转换器来处理HTTP请求中的JSON数据。
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();
}

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值