`
ll_feng
  • 浏览: 383042 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

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

    博客分类:
  • ajax
阅读更多
问题:
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转换为Date
		LoginUserInfo 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);
	}
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics