六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 43|回复: 0

解决extjs日期精确到分钟时被struts丢失时分秒的问题

[复制链接]

升级  0%

54

主题

54

主题

54

主题

举人

Rank: 3Rank: 3

积分
200
 楼主| 发表于 2013-1-29 10:31:13 | 显示全部楼层 |阅读模式
问题:
extjs 当日期控件的格式精确到分钟时,提交到struts的时候会丢失精度,只保留年月日,没有了时分秒。
解决办法:
1、将action中与前台对应的属性类型由date修改为string 这样就不会有类型转换的问题。
2、手动转换,string的类型还是不能直接赋给类型为date的属性的。就只能现手动转换一下了。
js:
{columnWidth : .5,layout : 'form',border : false,items : [{name : 'signDate',fieldLabel : '签发时间',labelStyle : "text-align: right;",xtype : 'datefield',format : 'Y-m-d H:i',cls : 'key',allowBlank : true,menu : new DatetimeMenu(),anchor : '90%'}]}

Action:
public class WeatherAction extends BaseAction {private  String signDate;//签发日期////////////////////////////////////////////////////////////////public String getSignDate() {return signDate;}public void setSignDate(String signDate) {this.signDate = signDate;}/////////////////////////////////////////////////////////////////////////** *  */public void save() throws IllegalAccessException, InvocationTargetException{ListRange<WeatherInfo> formList = new ListRange<WeatherInfo>();String message = "";boolean result = false;WeatherInfo wi  = new WeatherInfo();//this.getModelByForm();BeanUtils.copyProperties(wi, this);wi.setSignDate(DateUtil.getDateFromString(signDate,"yyyy-MM-dd HH:mm"));//按指定格式将String转换为DateLoginUserInfo user = this.getLoginUserInfo();try{weatherService.saveOrUpdate(wi,user);result = true;}catch(Exception e){e.printStackTrace();message = MessageConstants.ACTION_SAVE_SERVICE_FAILURE;if (e.getCause() instanceof BaseDaoException){message = MessageConstants.ACTION_SAVE_DB_FAILURE;}}formList.setMessage(message);formList.setSuccess(result);this.outJson(formList);}}
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表