Springmvc請求參數(shù)類型轉(zhuǎn)換器及原生api代碼實(shí)例
更新時(shí)間:2020年10月09日 08:39:07 作者:一路繁花似錦繡前程
這篇文章主要介紹了Springmvc請求參數(shù)類型轉(zhuǎn)換器及原生api代碼實(shí)例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
一、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:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
https://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
https://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!--掃描組件-->
<context:component-scan base-package="com.wuxi"></context:component-scan>
<!--視圖解析器-->
<bean id="internalResourceViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/pages/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
<!--參數(shù)類型裝換器-->
<bean id="conversionService" class="org.springframework.context.support.ConversionServiceFactoryBean">
<property name="converters">
<set>
<bean class="com.wuxi.utils.StringToDateConverter"></bean>
</set>
</property>
</bean>
<!--開啟springmvc框架注解的支持-->
<mvc:annotation-driven conversion-service="conversionService"></mvc:annotation-driven>
</beans>
二、轉(zhuǎn)換的類
package com.wuxi.utils;
import org.springframework.core.convert.converter.Converter;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class StringToDateConverter implements Converter<String, Date> {
@Override
public Date convert(String string) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date date = null;
try {
date = sdf.parse(string);
} catch (ParseException e) {
e.printStackTrace();
}
return date;
}
}
三、接口
@RequestMapping("/student")
public String student(Student student, HttpServletRequest request, HttpServletResponse response) {
System.out.println(student);
return "success";
}
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- Springmvc自定義參數(shù)轉(zhuǎn)換實(shí)現(xiàn)代碼解析
- SpringMVC的@InitBinder參數(shù)轉(zhuǎn)換代碼實(shí)例
- 解決springmvc關(guān)于前臺(tái)日期作為實(shí)體類對象參數(shù)類型轉(zhuǎn)換錯(cuò)誤的問題
- SpringMvc自動(dòng)裝箱及GET請求參數(shù)原理解析
- SpringMVC Controller解析ajax參數(shù)過程詳解
- 詳解在Spring MVC或Spring Boot中使用Filter打印請求參數(shù)問題
- SpringBoot中通過實(shí)現(xiàn)WebMvcConfigurer參數(shù)校驗(yàn)的方法示例
- 快速解決SpringMVC @RequestBody 用map接收請求參數(shù)的問題
相關(guān)文章
spring?jpa設(shè)置多個(gè)主鍵遇到的小坑及解決
這篇文章主要介紹了spring?jpa設(shè)置多個(gè)主鍵遇到的小坑及解決方案,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-06-06
hibernate-validator如何使用校驗(yàn)框架
高效、合理的使用hibernate-validator校驗(yàn)框架可以提高程序的可讀性,以及減少不必要的代碼邏輯,本文主要介紹了hibernate-validator如何使用校驗(yàn)框架,感興趣的可以了解一下2022-04-04
Java日常練習(xí)題,每天進(jìn)步一點(diǎn)點(diǎn)(44)
下面小編就為大家?guī)硪黄狫ava基礎(chǔ)的幾道練習(xí)題(分享)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧,希望可以幫到你2021-07-07
SpringMVC使用MultipartFile實(shí)現(xiàn)文件上傳
這篇文章主要為大家詳細(xì)介紹了SpringMVC使用MultipartFile實(shí)現(xiàn)文件上傳功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-04-04
Java中數(shù)據(jù)庫常用的兩把鎖之樂觀鎖和悲觀鎖
這篇文章主要介紹了數(shù)據(jù)庫常用的兩把鎖之樂觀鎖和悲觀鎖,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-07-07
JAVA并發(fā)中VOLATILE關(guān)鍵字的神奇之處詳解
這篇文章主要給大家介紹了關(guān)于JAVA并發(fā)中VOLATILE關(guān)鍵字的神奇之處的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-05-05
解決Java中的java.io.IOException: Broken pipe問題
這篇文章主要介紹了解決Java中 java.io.IOException: Broken pipe的問題,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-06-06

