框架spring+springMVC+mybatis,

前台给后台传数据传不了时分秒,所以用springMVC的注解解决了,记录一下

controller中如下:

/**
*
* 方法描述 : 使用@InitBinder 标签对表单数据绑定
* @param binder
*/
@InitBinder//spring mvc使用@InitBinder 标签对表单数据绑定
public void initBinder(WebDataBinder binder) {//WebDataBinder是用来绑定请求参数到指定的属性编辑器
binder.registerCustomEditor(Date.class, new DateConvertEditor("yyyy-MM-dd HH:mm:ss")); }
DateConvertEditor
package cn.edu.hbcf.vo;

import java.beans.PropertyEditorSupport;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat; import org.apache.commons.lang.StringUtils; /**
* spring中日期转换
*
* <pre>
* @InitBinder
* public void initBinder(WebDataBinder binder) {
* binder.registerCustomEditor(Date.class, new DateConvertEditor());
* // binder.registerCustomEditor(Date.class, new
* // DateConvertEditor(&quot;yyyy-MM-dd&quot;));
* binder.registerCustomEditor(String.class, new StringTrimmerEditor(true));
* }
* </pre>
*
*
* @author LiPenghui
* @date 2011-8-10 下午1:48:37
*/
public class DateConvertEditor extends PropertyEditorSupport{
private DateFormat format; public DateConvertEditor(){
this.format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
} public DateConvertEditor(String format){
this.format=new SimpleDateFormat(format);
} /** Date-->String **/
public String getAsText(){
if(getValue()==null){
return "";
}
return this.format.format(getValue());
} /** String-->Date **/
public void setAsText(String text){
if(!StringUtils.isNotBlank(text)){
setValue(null);
}else{
try {
setValue(this.format.parse(text));
} catch (ParseException e) {
throw new IllegalArgumentException("不能被转换的日期字符串,请检查!", e);
}
}
}
}

mybatis前台传给带年月日时分秒的数据给后台,后台接收不到时分秒的更多相关文章

  1. C# 版本的 计时器类:精确到微秒 秒后保留一位小数 支持年月日时分秒带单位的输出

    class TimeCount { // 临时变量,存放当前类能表示的最大年份值 ; /// <summary> /// 获取毫秒能表示的最大年份数 /// </summary> ...

  2. JavaScript中的内置对象-8--4.date对象中-获取,设置日期时间的方法; 获取,设置年月日时分秒及星期的方法;

    学习目标 1.掌握创建日期对象的方法 2.掌握date对象中获取日期时间的方法 3.掌握date对象中设置日期时间的方法 如何创建一个日期对象 语法:new Date(); 功能:创建一个日期时间对象 ...

  3. struts2:上传多个文件时实现带进度条、进度详细信息的示范

    上一篇文章讲了上传单个文件与上传多个文件(属性驱动)的例子.本例是上传多个文件(属性驱动),并且显示进度条.进度详细信息的示范. 在文件上传选择界面,允许用户增加.删除选择的文件,且只能上传指定类型的 ...

  4. Swift3.0 iOS获取当前时间 - 年月日时分秒星期

    Swift3.0 iOS获取当前时间 - 年月日时分秒星期func getTimes() -> [Int] { var timers: [Int] = [] // 返回的数组 let calen ...

  5. H面试程序(1)编写一个函数,要求输入年月日时分秒,输出该年月日时分秒的 下一秒

    编写一个函数,要求输入年月日时分秒,输出该年月日时分秒的下一秒. 如输入 2004 年 12 月 31 日 23 时 59 分 59 秒,则输出 2005年 1 月 1 日 0 时 0 分 0 秒. ...

  6. [置顶] java得到前一个月的年月日时分秒

    import java.util.Calendar; /** * 得到前一个月的年月日时分秒 * @author Mr.hu * 2013-6-28上午12:00:35 * Class Explain ...

  7. sql server获取当前年月日 时分秒

    获取当前年月日(字符串): ),) 获取当前时间的时分秒(':'隔开): ),) 将年月日时分秒拼接成一条字符串: ),)),),':','')

  8. 年月日时分秒毫秒+随机数getSerialNum

    package com.creditharmony.apporveadapter.core.utils; import java.io.ByteArrayInputStream; import jav ...

  9. Asp.net(C#)年月日时分秒毫秒

    年月日时分秒毫秒格式:yyyyMMddHHmmssfff

随机推荐

  1. 【codevs1200】 NOIP2012—同余方程

    codevs.cn/problem/1200/ (题目链接) 题意 求关于 x 的同余方程 ax ≡ 1 (mod b)的最小正整数解. Solution 这道题其实就是求${a~mod~b}$的逆元 ...

  2. POJ1364 King

    Description Once, in one kingdom, there was a queen and that queen was expecting a baby. The queen p ...

  3. auto,register,static实例

    #include <stdio.h>int main() {    auto int i = 0;    register int j = 0;    static int k = 0;  ...

  4. linux经典命令学习

    本文介绍Linux系统的若干经典命令的常用方法. (一)grep 主要用于搜索文件内容,查看是否跟要求的pattern相匹配. 1.grep -l 'boss' *        显示所有包含boss ...

  5. Protocol Buffer技术详解(数据编码)

    Protocol Buffer技术详解(数据编码) 之前已经发了三篇有关Protocol Buffer的技术博客,其中第一篇介绍了Protocol Buffer的语言规范,而后两篇则分别基于C++和J ...

  6. 升级centos6.5系统的gcc为4.8.5的简易步骤

    Centos6.5_64位升级gcc为4.8.2的简易步骤 一.安装依赖包 yum install texinfo-tex flex zip mpfr-devel libgcc.i686 glibc- ...

  7. C# Attribute 特性 学习

    一.特性的概述 公共语言运行库允许您添加类似关键字的描述性声明(称为特性 (Attribute))来批注编程元素,如类型.字段.方法和属性 (Property).属性与 Microsoft .NET ...

  8. SQL injection

    SQL injection is a code injection technique, used to attack data-driven applications, in which malic ...

  9. 同步文本框内容的JS代码

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  10. 闲来无事,用Java的软引用写了一个山寨的缓存

    闲来无事,用Java的软引用写了一个山寨的缓存 博客分类: java基础 众所周知java中的引用分为 StrongReference.SoftReference.WeakReference.Phan ...