欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

SpringMVC中怎么實(shí)現(xiàn)一個(gè)自定義類型轉(zhuǎn)換器

本篇文章為大家展示了SpringMVC中怎么實(shí)現(xiàn)一個(gè)自定義類型轉(zhuǎn)換器,內(nèi)容簡(jiǎn)明扼要并且容易理解,絕對(duì)能使你眼前一亮,通過這篇文章的詳細(xì)介紹希望你能有所收獲。

成都地區(qū)優(yōu)秀IDC服務(wù)器托管提供商(創(chuàng)新互聯(lián)).為客戶提供專業(yè)的資陽(yáng)托管服務(wù)器,四川各地服務(wù)器托管,資陽(yáng)托管服務(wù)器、多線服務(wù)器托管.托管咨詢專線:13518219792

1、 自定義類實(shí)現(xiàn)Convertro<S,T>接口

2、Springmvc.xml中配置ConversionServiceFactoryBean,其屬性上配置我們自定義的轉(zhuǎn)換器

3、欲使配置的轉(zhuǎn)換器生效,需要將springmvc.xml的<mvc:annotation-driven />改為

<mvc:annotation-driven conversion-service="conversionServiceFactoryBean"/>

1、 自定義類實(shí)現(xiàn)Convertro<S,T>接口

package com.example.util;import org.springframework.core.convert.converter.Converter;import org.springframework.util.StringUtils;import java.text.DateFormat;import java.text.ParseException;import java.text.SimpleDateFormat;import java.util.Date;public class StingToDateConvertr implements Converter<String, Date> { @Override public Date convert(String s) {  if(StringUtils.isEmpty(s)){   throw new RuntimeException("日期字符串不能為空!");  }  DateFormat df = new SimpleDateFormat("yyyy-MM-dd");  try {   return df.parse(s);  } catch (ParseException e) {   throw new RuntimeException("類型轉(zhuǎn)換出錯(cuò)!");  } }}

2、Springmvc.xml中配置ConversionServiceFactoryBean,其屬性上配置我們自定義的轉(zhuǎn)換器

<!--配置自定義類型轉(zhuǎn)換器--><bean id="conversionServiceFactoryBean" class="org.springframework.context.support.ConversionServiceFactoryBean"> <property name="converters">  <set>   <bean class="com.example.util.StingToDateConvertr" />  </set> </property></bean>

3、欲使配置的轉(zhuǎn)換器生效,需要將springmvc.xml的<mvc:annotation-driven />改為

<mvc:annotation-driven conversion-service="conversionServiceFactoryBean"/>

springmvc.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:aop="http://www.springframework.org/schema/aop"  xmlns:c="http://www.springframework.org/schema/c"  xmlns:cache="http://www.springframework.org/schema/cache"  xmlns:context="http://www.springframework.org/schema/context"  xmlns:jdbc="http://www.springframework.org/schema/jdbc"  xmlns:jee="http://www.springframework.org/schema/jee"  xmlns:lang="http://www.springframework.org/schema/lang"  xmlns:mvc="http://www.springframework.org/schema/mvc"  xmlns:p="http://www.springframework.org/schema/p"  xmlns:task="http://www.springframework.org/schema/task"  xmlns:tx="http://www.springframework.org/schema/tx"  xmlns:util="http://www.springframework.org/schema/util"  xsi:schemaLocation="http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.3.xsd  http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd  http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd  http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd  http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.3.xsd  http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.3.xsd  http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-4.3.xsd  http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.3.xsd  http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd  http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-4.3.xsd  http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd "> <!--開啟注解掃描--> <context:component-scan base-package="com.example" /> <!--視圖解析器,根據(jù)Controller返回的字符串找對(duì)應(yīng)的文件--> <bean id="internalResourceViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">  <!--文件路徑-->  <property name="prefix" value="/WEB-INF/pages/" />  <!--文件后綴-->  <property name="suffix" value=".jsp" /> </bean> <!--配置自定義類型轉(zhuǎn)換器--> <bean id="conversionServiceFactoryBean" class="org.springframework.context.support.ConversionServiceFactoryBean">  <property name="converters">   <set>    <bean class="com.example.util.StingToDateConvertr" />   </set>  </property> </bean> <!--1、開啟springmvc框架注解的支持--> <!--2、欲使配置的自定義類型轉(zhuǎn)換器生效,需加上conversion-service屬性--> <mvc:annotation-driven conversion-service="conversionServiceFactoryBean"/></beans>

注意:自定義的類型轉(zhuǎn)換器生效之后,日期格式就只能使用yyyy-MM-dd的格式了,若再使用原有的yyyy/MM/dd格式就會(huì)報(bào)錯(cuò)!

上述內(nèi)容就是SpringMVC中怎么實(shí)現(xiàn)一個(gè)自定義類型轉(zhuǎn)換器,你們學(xué)到知識(shí)或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識(shí)儲(chǔ)備,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。

新聞名稱:SpringMVC中怎么實(shí)現(xiàn)一個(gè)自定義類型轉(zhuǎn)換器
分享地址:http://aaarwkj.com/article6/peghog.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供面包屑導(dǎo)航、定制網(wǎng)站網(wǎng)頁(yè)設(shè)計(jì)公司、網(wǎng)站營(yíng)銷網(wǎng)站排名、網(wǎng)站設(shè)計(jì)公司

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

網(wǎng)站建設(shè)網(wǎng)站維護(hù)公司
亚洲国产成人午夜精品| 日韩有码一区在线观看| 一本大道东京热无码AⅤ片| 精精国产xxxx视频在线不卡| av免费观看男人的天堂| 日本韩国三级视频在线观看| 色在线观看综合亚洲欧洲| 国产传媒视频在线免费观看| 日韩电影在线观看二区| 免费在线观看av日韩| 日韩福利成人av在线| 黄色录像日本黄色录像| 中文字幕乱码高清欧美日韩| 日韩亚洲欧洲一区二区三区| 男人天堂手机视频在线| 日本一区二区三区加勒比| 国产午夜精品一区二区三区| 国产精品一区二区夜夜夜| 中文字幕欧美精品日韩人妻| 青青草原精品资源视频 | 91免费人成网站在线观看| 国产日韩精品国产二区| 欧美黄色成人免费网站| 青青草原网址在线观看| 欧美一区二区三区人妻激情| 久久精品女人天堂av免费观看| 日韩国产欧美一区二区在线视频| 亚洲成年人黄色在线观看| 欧美精品日韩精品一区二区| 国产亚洲一区二区精品| 日韩一区二区三区91| av影片在线观看亚洲天堂| 中文字幕日韩一区二区| 黄片超刺激在线看在线| 日韩一区二区高清视频在线观看| 日韩欧美二区三区精品在线| 亚洲中文波霸中文字幕| 日本午夜一区二区在线观看| 厕所偷拍视频一区二区三区| 亚洲乱码在线中文字幕| 亚洲欧美中文日韩一区|