spring参数类型转换器和原生api
标签:rac oca try source bean div ace 组件 ann
一、springmvc的xml配置文件
"1.0" encoding="UTF-8"?>
"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">
base-package="com.wuxi">"internalResourceViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
"prefix" value="/WEB-INF/pages/">"suffix" value=".jsp">"conversionService" class="org.springframework.context.support.ConversionServiceFactoryBean">
"converters">
set>
class="com.wuxi.utils.StringToDateConverter">set>
"conversionService">
二、转换的类
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 {
@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";
}
spring参数类型转换器和原生api
标签:rac oca try source bean div ace 组件 ann
原文地址:https://www.cnblogs.com/linding/p/13672421.html
评论