1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > http参数自动转换java接口参数设置_Springmvc请求参数类型转换器及原生api代码实例...

http参数自动转换java接口参数设置_Springmvc请求参数类型转换器及原生api代码实例...

时间:2022-12-17 10:53:14

相关推荐

http参数自动转换java接口参数设置_Springmvc请求参数类型转换器及原生api代码实例...

一、springmvc的xml配置文件

xmlns:xsi="/2001/XMLSchema-instance"

xmlns:context="/schema/context"

xmlns:mvc="/schema/mvc"

xsi:schemaLocation="/schema/beans

/schema/beans/spring-beans.xsd

/schema/context

/schema/context/spring-context.xsd

/schema/mvc

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

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

}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。