一、springmvc的xml配置文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | <? xml version = "1.0" encoding = "UTF-8" ?> xsi:schemaLocation="http://www.springframework.org/schema/beans <!--扫描组件--> < 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 > <!--参数类型装换器--> < 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 > |
二、转换的类
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | 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; } } |
三、接口
1 2 3 4 5 | @RequestMapping ( "/student" ) public String student(Student student, HttpServletRequest request, HttpServletResponse response) { System.out.println(student); return "success" ; } |
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持自学编程网。
- 本文固定链接: https://zxbcw.cn/post/197043/
- 转载请注明:必须在正文中标注并保留原文链接
- QQ群: PHP高手阵营官方总群(344148542)
- QQ群: Yii2.0开发(304864863)