1.局部日期转换

@Controller
public class ProductController{
@RequestMapping(value="/test/springmvc.do")
public String test(String name,Date birthday){
System.out.println(name+birthday);
return "";
}
//局部性的转换
@InitBinder
public void initBinder(WebDataBinder binder, WebRequest request) {
// TODO Auto-generated method stub
//转换日期格式
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat,true));
}
}

2.全局性的时间转换

1).在springmvc.xml添加配置

<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<!-- 日期格式转换 -->
<property name="webBindingInitializer">
<bean class="cn.itcast.core.web.DateConverter" />
</property>
</bean>

2).编写 DateConverter

public class DateConverter implements WebBindingInitializer {    

    public void initBinder(WebDataBinder binder, WebRequest request) {
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat,true));
}
}

Springmvc配置时间日期转换的更多相关文章

  1. 时间日期转换工具类,获取当前时间YYYYMMDD24HHMISS、YYYYMMDDHHMISS

    YYYYMMDD24HHMISS:24小时制时间(显示上只是比YYYYMMDDHHMISS中间多了一个24),例:2018102224112440 YYYYMMDDHHMISS:12小时制时间,例20 ...

  2. SpringMVC配置全局日期转换器,处理日期转换异常

    Spring 3.1.1使用Mvc配置全局日期转换器,处理日期转换异常链接地址: https://www.2cto.com/kf/201308/236837.html spring3.0配置日期转换可 ...

  3. 【MySQL笔记】字符串、时间日期转换

    1.新增一列,将字符串日期(年.月.日)转换为Date类型   报错:Error Code: 1175. You are using safe update:http://jingyan.baidu. ...

  4. 02基于注解开发SpringMVC项目(jar包,异步,request,参数传递,多选的接收,Model传参,map传参,model传参,ajax,重定向,时间日期转换)

     1 所需jar包 项目结构如下: 2 web.xml配置文件的内容如下: <?xmlversion="1.0"encoding="UTF-8"?&g ...

  5. PHP phpexcel 导入时间/日期转换时间戳

    strtotime(gmdate('Y-m-d H:i',\PHPExcel_Shared_Date::ExcelToPHP($importtime))); /** * 判断字符串是否是日期格式 * ...

  6. springMVC 返回时间格式转换

    <mvc:annotation-driven> <mvc:message-converters> <bean class="org.springframewor ...

  7. python 使用time / datetime进行时间、时间戳、日期转换

    python 使用time 进行时间.时间戳.日期格式转换 #!/usr/bin/python3 # -*- coding: utf-8 -*- # @Time : 2017/11/7 15:53 # ...

  8. Java中时间日期格式化

    1.与日期时间相关的类:      第一:java.util.Date;                           将时间作为一个整体使用.处理时,使用Date类较为简便      第二:j ...

  9. 07、MySQL—时间日期类型

    时间日期类型 1.Date 日期类型:系统使用三个字节来存储数据,对应的格式为:YYYY-mm-dd,能表示的范围是从1000-01-01 到9999-12-12,初始值为0000-00-00 2.T ...

随机推荐

  1. 公式for TinyMCE 编辑器@ cnblogs.com

    编辑器截图: 行内公式:\(  f(x,y,z) = 3y^2 z \left( 3 + \frac{7x+5}{1 + y^2} \right)  \) 行间公式:\\(  f(x,y,z) = 3 ...

  2. idea 控制台行数限制

    在本地进行测试时,会出现报错太多idea控制台被限制打印出来的日志被清楚的现象: idea改变控制台打印log限制的方法: 1. 点击 File ->Settings ->editor - ...

  3. odps 使用参考 & tips

    1.  自定义udf 编写udf 1)pom.xml <dependency> <groupId>com.aliyun.odps</groupId> <art ...

  4. webform(复合控件)

    一.组合单选 RadioButtonList 单选按钮与简单控件不同,可理解为在集合中放置多对象 例: <asp:RadioButtonList ID="RadioButtonList ...

  5. tomcat中项目后有括号

    引入他人项目时,由于报错,copy本地workspace下其他项目的 .settings和.project到该项目路径下 结果Eclipse 的 Server 中出现了  aaa(bbb)的情况 并且 ...

  6. 白鹭引擎 - 资源文件的加载 ( RES, loadConfig, loadGroup )

    class Main extends egret.DisplayObjectContainer { public constructor() { super(); this.addEventListe ...

  7. 白鹭引擎 - 对象的添加与删除 ( 开关效果 addChild, removeChild )

    class Main extends egret.DisplayObjectContainer { /** * Main 类构造器, 初始化的时候自动执行, ( 子类的构造函数必须调用父类的构造函数 ...

  8. 机器学习入门-文本数据-构造词频词袋模型 1.re.sub(进行字符串的替换) 2.nltk.corpus.stopwords.words(获得停用词表) 3.nltk.WordPunctTokenizer(对字符串进行分词操作) 4.np.vectorize(对函数进行向量化) 5. CountVectorizer(构建词频的词袋模型)

    函数说明: 1. re.sub(r'[^a-zA-Z0-9\s]', repl='', sting=string)  用于进行字符串的替换,这里我们用来去除标点符号 参数说明:r'[^a-zA-Z0- ...

  9. nodejs 解决跨域

    1.失败 app.all('*', function (req, res, next) { res.header("Access-Control-Allow-Origin", &q ...

  10. unzip解压带密码的压缩包

    // 解压 String pw = "123456"; String cmd = "unzip -P " + pw + " /root/lianlia ...