SSM-SpringMVC-27:SpringMVC类型转换之日期类型初步
------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥-------------
本案例是上面的异常和日期类型转换结合的一个小小的Demo
案例开始
1.自定义处理器和处理方法:
package cn.dawn.day19typeconverter; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView; import javax.servlet.http.HttpServletRequest;
import java.util.Date; /**
* Created by Dawn on 2018/3/28.
*/
@Controller
public class TypeConverterController { /*作用于这俩个*/
@ExceptionHandler
public ModelAndView resolveException(Exception ex, HttpServletRequest request) {
ModelAndView modelAndView=new ModelAndView();
/*给username回显*/
modelAndView.addObject("username",request.getParameter("username"));
/*返回的异常对象*/
modelAndView.addObject("ex",ex);
/*发生异常返回登陆页*/
modelAndView.setViewName("login"); return modelAndView;
} /*做日期类型*/
@RequestMapping("/dateconverter1")
public String dateconverter1(String username, Integer userage, Date birthday) throws Exception {
System.out.println(username);
System.out.println(userage);
System.out.println(birthday);
return "success";
}
}
2.自己的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:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd"> <!--包扫描器-->
<context:component-scan base-package="cn.dawn.day19typeconverter"></context:component-scan>
<!--视图解析器-->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/day19/"></property>
<property name="suffix" value=".jsp"></property>
</bean> </beans>
3.修改web.xml中央调度器的上下文配置位置为上面那个xml
4.jsp页面:
4.1login.jsp
<%@ page pageEncoding="UTF-8" contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<h2>登录</h2>
<form action="${pageContext.request.contextPath}/dateconverter1" method="post"> 用户名:<input name="username" value="${username}">
年龄:<input name="userage">
生日:<input name="birthday"> <input type="submit" value="登录"/>
</form>
</body>
</html>
4.2success.jsp
<%@ page language="java" pageEncoding="utf-8" isELIgnored="false" %>
<html>
<body>
<%--<img src="data:image/1.jpg">--%>
<h2>Success!</h2>
</body>
</html>
结论:什么时候跳到成功页面?就是日期格式不出错,日期格式必须为yyyy/MM/dd,SpringMVC默认的自动转换日期格式必须传入的是这个
下篇博客就做自定义类型转换器
SSM-SpringMVC-27:SpringMVC类型转换之日期类型初步的更多相关文章
- SpringMVC 自定义参数绑定实现日期类型绑定
package cn.itcast.ssm.controller.converter; import java.text.ParseException; import java.text.Simple ...
- JavaScript 把字符串类型转换成日期类型
今天在写习题时,遇到些小问题,在这里把答案分享给大家,希望能帮助到大家! 一.把字符串转换成日期类型 var str = "1997-3-12"; var d = new Date ...
- springmvc使用spring自带日期类型验证
控制器 @Controller public class MyController { // 处理器方法 @RequestMapping(value = "/first.do") ...
- SSM-SpringMVC-28:SpringMVC类型转换之自定义日期类型转换器
------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥------------- 例子很简易,要明白的是思路,话不多说,开讲 上篇博客不是说springmvc默认的日期转换格式是yyyy/M ...
- SpringMVC提交数据遭遇基础类型和日期类型报400错误解决方法
使用SpringMVC开发的时候,页面如果有日期格式的数据,后台接受也是java.util.Date,则报告400错误 .下面是解决方案的演示示例: 这个是实体类,里面createDate就是java ...
- SpringMVC由浅入深day01_12.4 pojo绑定_12.5自定义参数绑定实现日期类型绑定_12.6集合类
12.4 pojo绑定 页面中input的name和controller的pojo形参中的属性名称一致,将页面中数据绑定到pojo. 页面定义: controller的pojo形参的定义: 打断点测试 ...
- springMvc把client传过来一个String类型,转换为日期类型为例
springMvc--接受日期类型参数处理 目录 步骤 2.自定义类型转换规则 3.注册自定义的类型转换类 4.地址栏访问 这个问题,也即是springMvc如何进行参数类型的转换 , 以把cli ...
- SSM框架之SpringMVC(2)参数绑定及自定义类型转换
SpringMVC(2)参数绑定及自定义类型转换 1.请求参数的绑定 1.1. 请求参数的绑定说明 1.1.1.绑定机制 表单提交的数据都是k=v格式的 username=haha&passw ...
- SpringMVC 06: 日期类型的变量的注入和显示
日期处理和日期显示 日期处理 此时SpringMVC的项目配置和SpringMVC博客集中(指SpringMVC 02)配置相同 日期处理分为单个日期处理和类中全局日期处理 单个日期处理: 使用@Da ...
随机推荐
- 集群通信组件tribes之应用程序处理入口
Tribes为了更清晰更好地划分职责,它被设计成用IO层和应用层,IO层专心负责网络传输方面的逻辑处理,把接收到的数据往应用层传送,当然应用层发送的数据也是通过此IO层发送,数据传往应用层后必须要留一 ...
- LeetCode之“链表”:Remove Nth Node From End of List
题目链接 题目要求: Given a linked list, remove the nth node from the end of list and return its head. For ex ...
- FFMPEG结构体分析:AVCodecContext
注:写了一系列的结构体的分析的文章,在这里列一个列表: FFMPEG结构体分析:AVFrame FFMPEG结构体分析:AVFormatContext FFMPEG结构体分析:AVCodecConte ...
- ffdshow 源代码分析 5: 位图覆盖滤镜(总结)
===================================================== ffdshow源代码分析系列文章列表: ffdshow 源代码分析 1: 整体结构 ffds ...
- c/c++ 表达式求值
表达式求值 [问题描述] 一个算术表达式是由操作数(operand).运算符(operator)和界限符(delimiter)组成的.假设操作数是正整数,运算符只含加减乘除等四种运算符,界限符有左右括 ...
- Leetcode_260_Single Number III
本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/50276549 Given an array of numb ...
- butternife Zelezny自动注入插件
插件地址:http://plugins.jetbrains.com/plugin/7369 Products: IntelliJ IDEA, RubyMine, WebStorm, PhpStorm, ...
- bash编程语法自我总结
脚本2种执行方式: 1 直接执行,等于bash衍生一个子程序,当该子程序完成后,子程序内各项变量活动作不会传回父程序 2 利用source执行,直接在父程序中执行 X=/bin/xdo cmd 执行c ...
- .Net中的并行编程-7.基于BlockingCollection实现高性能异步队列
三年前写过基于ConcurrentQueue的异步队列,今天在整理代码的时候发现当时另外一种实现方式-使用BlockingCollection实现,这种方式目前依然在实际项目中使用.关于Blockin ...
- jQuery学习小结
1.jQuery hide() 和 show() 通过 jQuery,您可以使用 hide() 和 show() 方法来隐藏和显示 HTML 元素: $("#hide").clic ...