国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > AJAX > 正文

SpringMVC環境下實現的Ajax異步請求JSON格式數據

2024-09-01 08:28:00
字體:
來源:轉載
供稿:網友

一 環境搭建

首先是常規的spring mvc環境搭建,不用多說,需要注意的是,這里需要引入jackson相關jar包,然后在spring配置文件“springmvc-servlet.xml”中添加json解析相關配置,我這里的完整代碼如下:

<?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:context="http://www.springframework.org/schema/context"xmlns:mvc="http://www.springframework.org/schema/mvc"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsdhttp://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd"><!-- 避免IE執行AJAX時,返回JSON出現下載文件 --><bean id="mappingJacksonHttpMessageConverter"class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"><property name="supportedMediaTypes"><list><value>text/html;charset=UTF-8</value><value>application/json;charset=UTF-8</value></list></property><property name="objectMapper"><bean class="org.codehaus.jackson.map.ObjectMapper"><property name="dateFormat"><bean class="java.text.SimpleDateFormat"><constructor-arg type="java.lang.String" value="yyyy-MM-dd HH:mm:ss"></constructor-arg></bean></property></bean></property></bean><!-- 啟動Spring MVC的注解功能,完成請求和注解POJO的映射 --><beanclass="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"><property name="messageConverters"><list><ref bean="mappingJacksonHttpMessageConverter" /><!-- json轉換器 --></list></property></bean><mvc:annotation-drivencontent-negotiation-manager="contentNegotiationManager" /><bean id="contentNegotiationManager"class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean"><!-- true,開啟擴展名支持,false關閉支持 --><property name="favorPathExtension" value="false" /><!-- 用于開啟 /userinfo/123?format=json的支持 --><property name="favorParameter" value="true" /><!-- 設置為true以忽略對Accept Header的支持 --><property name="ignoreAcceptHeader" value="false" /><property name="mediaTypes"><value>atom=application/atom+xmlhtml=text/htmljson=application/jsonxml=application/xml*=*/*</value></property></bean><context:annotation-config /><!-- 啟動自動掃描該包下所有的Bean(例如@Controller) --><context:component-scan base-package="cn.zifangsky.controller" /><mvc:default-servlet-handler /><!-- 定義視圖解析器 --><bean id="jspViewResolver"class="org.springframework.web.servlet.view.InternalResourceViewResolver"><property name="requestContextAttribute" value="rc" /><property name="viewClass"value="org.springframework.web.servlet.view.JstlView" /><property name="prefix" value="/WEB-INF/jsp/" /><property name="suffix" value=".jsp" /><property name="order" value="1"></property></bean></beans>            
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 长丰县| 汝阳县| 克东县| 钦州市| 甘谷县| 岑溪市| 黄陵县| 辽阳市| 仲巴县| 元阳县| 开鲁县| 嘉定区| 苏尼特左旗| 象山县| 高尔夫| 连州市| 扎鲁特旗| 漠河县| 河北区| 新泰市| 达州市| 池州市| 崇信县| 滨州市| 株洲县| 白城市| 交口县| 舟山市| 金堂县| 喀喇沁旗| 钦州市| 梁平县| 上杭县| 衡阳市| 安徽省| 绥化市| 渭源县| 文化| 济南市| 巴彦县| 长春市|