开发者社区> bboss> 正文

bboss mvc框架中使用注解指定控制器方法日期类型参数日期格式的例子

简介: bboss mvc框架中使用注解指定控制器方法日期类型参数日期格式的例子 直入正题: 1.控制器方法定义-DateConvertController /* * Copyright 2008 biaoping.
+关注继续查看
bboss mvc框架中使用注解指定控制器方法日期类型参数日期格式的例子
直入正题:
1.控制器方法定义-DateConvertController
/*
 *  Copyright 2008 biaoping.yin
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package org.frameworkset.web.date;

import org.frameworkset.util.annotations.RequestParam;
import org.frameworkset.web.servlet.ModelMap;

/**
 * <p>Title: DateConvertController.java</p> 
 * <p>Description: 日期转换实例</p>
 * <p>bboss workgroup</p>
 * <p>Copyright (c) 2008</p>
 * @Date 2011-4-30
 * @author biaoping.yin
 * @version 1.0
 */
public class DateConvertController {
	
	public String converStringToDate(@RequestParam(name="d12",dateformat="yyyy-MM-dd") java.util.Date d12,
									 @RequestParam(name="stringdate",dateformat="yyyy-MM-dd") java.sql.Date stringdate,
									 @RequestParam(name="stringdatetimestamp",dateformat="yyyy-MM-dd HH/mm/ss") java.sql.Timestamp stringdatetimestamp,
									 @RequestParam(name="stringdatetimestamp") String stringdatetimestamp_,
			ModelMap model)
	{
		model.put("java.util.Date", d12);
		model.put("java.sql.Date", stringdate);
		model.put("java.sql.Timestamp", stringdatetimestamp);
		return "path:convertok";
		
	}
	public String dateconvert()
	{
		return "path:convertin";
	}

}


2.选择日期的jsp页面
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>

		<title>DatePicker</title>
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">
	
		<script type="text/javascript"
			src="${pageContext.request.contextPath}/jsp/datepicker/My97DatePicker/WdatePicker.js"></script>
         <link rel="shortcut icon"
		href="${pageContext.request.contextPath}/css/favicon.gif">
	<link rel="stylesheet"
		href="${pageContext.request.contextPath}/css/classic/tables.css"
		type="text/css">
	<link rel="stylesheet"
		href="${pageContext.request.contextPath}/css/classic/main.css"
		type="text/css">
	<link rel="stylesheet"
		href="${pageContext.request.contextPath}/css/classic/mainnav.css"
		type="text/css">
	<link rel="stylesheet"
		href="${pageContext.request.contextPath}/css/classic/messages.css"
		type="text/css">
	<link rel="stylesheet"
		href="${pageContext.request.contextPath}/css/classic/tooltip.css"
		type="text/css">
	</head>
 
	<body>
	<h1>日期格式转换demo</h1>
	<form action="converStringToDate.html" method="post">
	<table class="genericTbl">
	   <tr>
	   <th class="order1 sorted" >demo描述
	   </th>
	   <th class="order1 sorted">演示区
	   </th>
	   </tr>
	 <tr class="even" >
	   
	    <td align="right">
	   普通触发:
	    </td>
	    <td>
	   <input id="d12" name="d12" type="text"
        onclick="WdatePicker({el:'d12'})" src="${pageContext.request.contextPath}/jsp/datepicker/My97DatePicker/skin/datePicker.gif" width="16" height="22" align="absmiddle"/>
	   </td>
	   </tr>
	  
	
		
		<tr class="even">
	    <td align="right">
		精确到日期:
		</td>
	    <td>
		<input class="Wdate" type="text" name="stringdate" onClick="WdatePicker()">
		</td>
	   </tr>
	   <tr class="even">
	    <td align="right">
		精确具体时间:
		</td>
	    <td>
		<input class="Wdate" type="text" name="stringdatetimestamp" onClick="WdatePicker({dateFmt:'yyyy-MM-dd HH/mm/ss'})">
		</td>
	    </tr>
	    
	     <tr class="even">
	    <td align="right">
		提交:
		</td>
	    <td>
		<input type="submit" value="提交转换"/>
		</td>
	    </tr>
		
		</table>
		</form>
	</body>
</html>


3.转换结果查看页面-ok.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>

		<title>DatePicker</title>
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">
		<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
		<script type="text/javascript"
			src="${pageContext.request.contextPath}/jsp/datepicker/My97DatePicker/WdatePicker.js"></script>
         <link rel="shortcut icon"
		href="${pageContext.request.contextPath}/css/favicon.gif">
	<link rel="stylesheet"
		href="${pageContext.request.contextPath}/css/classic/tables.css"
		type="text/css">
	<link rel="stylesheet"
		href="${pageContext.request.contextPath}/css/classic/main.css"
		type="text/css">
	<link rel="stylesheet"
		href="${pageContext.request.contextPath}/css/classic/mainnav.css"
		type="text/css">
	<link rel="stylesheet"
		href="${pageContext.request.contextPath}/css/classic/messages.css"
		type="text/css">
	<link rel="stylesheet"
		href="${pageContext.request.contextPath}/css/classic/tooltip.css"
		type="text/css">
	</head>
 
	<body>
	<h1>日期格式转换demo转换结果</h1>
	<form action="dateconvert.html" method="post">
	<table class="genericTbl">
	   <tr>
	   <th class="order1 sorted" >demo描述
	   </th>
	   <th class="order1 sorted">演示区
	   </th>
	   </tr>
	 <tr class="even" >
	   
	    <td align="right">
	   普通触发:
	    </td>
	    <td>
	  	<%=request.getAttribute("java.util.Date") %>
	   </td>
	   </tr>
	  
	
		
		<tr class="even">
	    <td align="right">
		精确到日期:
		</td>
	    <td>
		<%=request.getAttribute("java.sql.Date") %>
		</td>
	   </tr>
	   <tr class="even">
	    <td align="right">
		精确具体时间:
		</td>
	    <td>
		<%=request.getAttribute("java.sql.Timestamp") %>
		</td>
	    </tr>
	    
	     <tr class="even">
	    <td align="right">
		返回:
		</td>
	    <td>
		<input type="submit" value="返回"/>
		</td>
	    </tr>
		
		</table>
		</form>
	</body>
</html>


4.mvc框架配置文件-bboss-dateconvert.xml:
<?xml version="1.0" encoding='gb2312'?>
<!-- 
bboss-dateconvert.xml
描述:日期类型转换
-->
<properties>
    <property 
     name="/dateconvert/*.html" 
     	path:convertok="/dateconvert/ok"
     	path:convertin="/dateconvert/in"
     class="org.frameworkset.web.date.DateConvertController"/>
</properties>


补充说明:如果不指定dateformat属性,那么将用yyyy-MM-dd HH:mm:ss作为默认的日期转换格式。

更详细的情况请参考bbossgroups 项目的mvcdemo应用相关文档《bbossgroups 3.1 mvc demo部署方法》:
http://yin-bp.iteye.com/blog/1026245
demo部署好后可以通过以下地址访问日期格式转换的例子:
http://localhost:8080/bboss-mvc/dateconvert/dateconvert.html

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
angular定制组件-bootstrap(css框架)
需要的文件 bootstrap.css ui-bootstrap-tpls.js 模态框 angular定制的bootstrap的模态框,可以方便地将视图与控制器绑定。 模块的定义与模块的控制器: //定义模块时引入依赖 angular .module('myApp', [ 'ui.bootstrap' ]); //定义控制器时传入依赖 angu
1703 0
使用IntelliJ IDEA开发SpringMVC网站(二)框架配置
原文:使用IntelliJ IDEA开发SpringMVC网站(二)框架配置 摘要 讲解如何配置SpringMVC框架xml,以及如何在Tomcat中运行 目录[-] 文章已针对IDEA 15做了一定的更新,部分更新较为重要,请重新阅读文章并下载最新源码。
1046 0
Spring MVC url提交参数和获取参数
普通URL提交参数 该格式url为:url.do?param1=mahc&param2=8888.00 需要在上文中的HelloController对象添加方法如下: ? 1 2 3 4 5 6 7 8 9 10 11 /**      *...
599 0
+关注
bboss
热衷开源,主要开源作品:开源框架bboss,bboss session,bboss 序列化等 bboss特色:http://yin-bp.iteye.com/blog/1080824
328
文章
1
问答
文章排行榜
最热
最新
相关电子书
更多
OceanBase 入门到实战教程
立即下载
阿里云图数据库GDB,加速开启“图智”未来.ppt
立即下载
实时数仓Hologres技术实战一本通2.0版(下)
立即下载