Springmvc请求参数类型转换器及原生api代码实例

网友投稿 918 2023-03-27

Springmvc请求参数类型转换器及原生api代码实例

Springmvc请求参数类型转换器及原生api代码实例

一、springmvc的xml配置文件

xmlns:xsi="http://w3.org/2001/XMLSchema-instance"

xmlns:context="http://springframework.org/schema/context"

xmlns:mvc="http://springframework.org/schema/mvc"

xsi:schemaLocation="http://springframework.org/schema/beans

https://springframework.org/schema/beans/spring-beans.xsd

http://springframework.org/schema/context

https://springframework.org/schema/context/spring-context.xsd

http://springframework.org/schema/mvc

https://springframework.org/schema/mvc/spring-mvc.xsd">

xmlns:xsi="http://w3.org/2001/XMLSchema-instance"

xmlns:context="http://springframework.org/schema/context"

xmlns:mvc="http://springframework.org/schema/mvc"

xsi:schemaLocation="http://springframework.org/schema/beans

https://springframework.org/schema/beans/spring-beans.xsd

http://springframework.org/schema/context

https://springframework.org/schema/context/spring-context.xsd

http://springframework.org/schema/mvc

https://springframework.org/schema/mvc/spring-mvc.xsd">

二、转换的类

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")http://;

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";

}

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:电脑微信打开小程序看课(如何在电脑上看微信小程序视频)
下一篇:微信开发者工具(微信开发者工具怎么导入图片)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~