Springmvc請(qǐng)求參數(shù)類(lèi)型轉(zhuǎn)換器及原生api代碼實(shí)例
更新時(shí)間:2020年10月09日 08:39:07 作者:一路繁花似錦繡前程
這篇文章主要介紹了Springmvc請(qǐng)求參數(shù)類(lèi)型轉(zhuǎn)換器及原生api代碼實(shí)例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(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ù)類(lèi)型裝換器--> <bean id="conversionService" class="org.springframework.context.support.ConversionServiceFactoryBean"> <property name="converters"> <set> <bean class="com.wuxi.utils.StringToDateConverter"></bean> </set> </property> </bean> <!--開(kāi)啟springmvc框架注解的支持--> <mvc:annotation-driven conversion-service="conversionService"></mvc:annotation-driven> </beans>
二、轉(zhuǎn)換的類(lèi)
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"; }
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- Springmvc自定義參數(shù)轉(zhuǎn)換實(shí)現(xiàn)代碼解析
- SpringMVC的@InitBinder參數(shù)轉(zhuǎn)換代碼實(shí)例
- 解決springmvc關(guān)于前臺(tái)日期作為實(shí)體類(lèi)對(duì)象參數(shù)類(lèi)型轉(zhuǎn)換錯(cuò)誤的問(wèn)題
- SpringMvc自動(dòng)裝箱及GET請(qǐng)求參數(shù)原理解析
- SpringMVC Controller解析ajax參數(shù)過(guò)程詳解
- 詳解在Spring MVC或Spring Boot中使用Filter打印請(qǐng)求參數(shù)問(wèn)題
- SpringBoot中通過(guò)實(shí)現(xiàn)WebMvcConfigurer參數(shù)校驗(yàn)的方法示例
- 快速解決SpringMVC @RequestBody 用map接收請(qǐng)求參數(shù)的問(wèn)題
相關(guān)文章
java 枚舉類(lèi)定義靜態(tài)valueOf(java.lang.String)方法的問(wèn)題及解決
這篇文章主要介紹了java 枚舉類(lèi)定義靜態(tài)valueOf(java.lang.String)方法的問(wèn)題及解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-09-09java數(shù)據(jù)結(jié)構(gòu)與算法之簡(jiǎn)單選擇排序詳解
這篇文章主要介紹了java數(shù)據(jù)結(jié)構(gòu)與算法之簡(jiǎn)單選擇排序,結(jié)合實(shí)例形式分析了選擇排序的原理、實(shí)現(xiàn)方法與相關(guān)操作技巧,需要的朋友可以參考下2017-05-05Spring解決循環(huán)依賴問(wèn)題的四種方法匯總
這篇文章主要介紹了Spring解決循環(huán)依賴問(wèn)題的四種方法匯總,本文給大家介紹的非常詳細(xì),感興趣的朋友跟隨小編一起看看吧2024-07-07Java web基礎(chǔ)學(xué)習(xí)之開(kāi)發(fā)環(huán)境篇(詳解)
下面小編就為大家?guī)?lái)一篇Java web基礎(chǔ)學(xué)習(xí)之開(kāi)發(fā)環(huán)境篇(詳解)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-08-08SpringBoot實(shí)現(xiàn)無(wú)感刷新Token的項(xiàng)目實(shí)踐
token刷新是前端安全中必要的一部分,本文就來(lái)介紹一下SpringBoot實(shí)現(xiàn)無(wú)感刷新Token的項(xiàng)目實(shí)踐,具有一定的參考價(jià)值,感興趣的可以了解一下2024-03-03