spring mvc 在jsp页面如何使时间以格式yyyy-MM-dd HH:mm:ss显示,24小时制
来源:互联网 发布:淘宝实体店是什么意思 编辑:程序博客网 时间:2024/06/10 18:46
首先,javaBean为:
import java.util.Date;
public class OutcomeVo {private int oid;private int uid;private String ocName;private String ocType;private Date gotOCDate;private Date commitTime;private String fileUrl;public String getFileUrl() {return fileUrl;}public void setFileUrl(String fileUrl) {this.fileUrl = fileUrl;}public String getOcName() {return ocName;}public void setOcName(String ocName) {this.ocName = ocName;}public int getOid() {return oid;}public void setOid(int oid) {this.oid = oid;}public int getUid() {return uid;}public void setUid(int uid) {this.uid = uid;}public String getOcType() {return ocType;}public void setOcType(String ocType) {this.ocType = ocType;}public Date getGotOCDate() {return gotOCDate;}public void setGotOCDate(Date gotOCDate) {this.gotOCDate = gotOCDate;}public Date getCommitTime() {return commitTime;}public void setCommitTime(Date commitTime) {this.commitTime = commitTime;}}
其次,在后台从数据库中获取的时候是:
import java.sql.ResultSet;import java.sql.SQLException;import java.util.HashMap;import java.util.List;import java.util.Map;import org.springframework.jdbc.core.RowMapper;import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;import org.springframework.jdbc.core.namedparam.SqlParameterSource;import org.springframework.jdbc.support.GeneratedKeyHolder;import org.springframework.jdbc.support.KeyHolder;import org.springframework.stereotype.Repository;import cn.cnic.outcome.front.vo.OutcomeVo;import cn.cnic.outcome.util.BaseDAO;@Repository@SuppressWarnings("unchecked")public class OutcomeDao extends BaseDAO{private static final String TABLE = " outcome ";private static final String FIELDS = " uid,ocType,ocName,fileUrl,gotOCDate,commitTime ";private static final String SAVED_VALUES = " :uid,:ocType,:ocName,:fileUrl,:gotOCDate,:commitTime ";private static final String UPDATED_VALUES = " uid=:uid,ocType=:ocType,ocName=:ocName,fileUrl=:fileUrl,gotOCDate=:gotOCDate ";@SuppressWarnings("unchecked")public List<OutcomeVo> findByProperty(String propertyName, Object value) {String sql = "select distinct * from " + TABLE + " where "+ propertyName + "=:" + propertyName;Map paramMap = new HashMap();paramMap.put(propertyName, value);return (List<OutcomeVo>) getNamedParameterJdbcTemplate().query(sql,paramMap, rowMapper);}@SuppressWarnings("unchecked")public List<OutcomeVo> findAll() {String sql = "select * from " + TABLE + " order by oid";Map paramMap = new HashMap();return (List<OutcomeVo>) getNamedParameterJdbcTemplate().query(sql,paramMap, rowMapper);}public int save(OutcomeVo outcomeVo) {String sql = "insert into " + TABLE + " ( " + FIELDS + " ) values ( "+ SAVED_VALUES + " )";KeyHolder keyHolder = new GeneratedKeyHolder();SqlParameterSource ps = new BeanPropertySqlParameterSource(outcomeVo);getNamedParameterJdbcTemplate().update(sql, ps, keyHolder);return keyHolder.getKey().intValue();}public int update(OutcomeVo outcomeVo) {String sql = "update " + TABLE + " set " + UPDATED_VALUES+ " where oid=:oid";SqlParameterSource ps = new BeanPropertySqlParameterSource(outcomeVo);return getNamedParameterJdbcTemplate().update(sql, ps);}@SuppressWarnings("unchecked")private RowMapper rowMapper = new RowMapper() {public Object mapRow(ResultSet rs, int arg1) throws SQLException {OutcomeVo outcomeVo = new OutcomeVo();outcomeVo.setCommitTime(rs.getTimestamp("commitTime"));outcomeVo.setGotOCDate(rs.getDate("gotOCDate"));outcomeVo.setOcType(rs.getString("ocType"));outcomeVo.setOcName(rs.getString("ocName"));outcomeVo.setFileUrl(rs.getString("fileUrl"));outcomeVo.setOid(rs.getInt("oid"));outcomeVo.setUid(rs.getInt("uid"));return outcomeVo;}};}
最后,在页面上显示的时候是这样的:
<fmt:formatDate value="${outcome.commitTime}" pattern="yyyy-MM-dd HH:mm:ss" />
以上仅为关键代码,只需看红色字体部分即可知晓,如何操作
- spring mvc 在jsp页面如何使时间以格式yyyy-MM-dd HH:mm:ss显示,24小时制
- jsp页面按yyyy-MM-dd HH:mm:ss格式显示Date类型的数据
- jsp页面时间类型显示为 yyyy-MM-dd hh:mi:ss的格式化js
- 获得系统时间并以“yyyy-MM-dd HH:mm:ss”格式返回
- 时间格式:yyyy-MM-dd HH:mm:ss,YYYY-MM-dd hh:mm:ss等,详细解释
- JSP 页面取yyyy-MM-dd HH:mm:ss 变成yyyy-MM-dd
- DateTime.Now.ToString ("yyyy:MM:dd,hh:mm:ss") 12小时制转成24小时制
- js如何取当前日期时间/格式为:yyyy-mm-dd hh:mm:ss
- 如何简单正确地向前台返回"YYYY-MM-DD hh:mm:ss"格式的时间值
- 如何将oracle date类型的字段,显示为格式 yyyy-mm-dd hh:mm:ss
- js 格式化时间(显示格式为:yyyy-mm-dd hh:mi:ss)
- java yyyy-MM-dd HH:mm:ss格式的时间存储到MySQL中时 HH:mm:ss显示为00:00:00.000000
- 日期格式yyyy-MM-dd HH:mm:ss的解释
- js 时间比较 yyyy-mm-dd HH:MM:ss
- Linux时间(date)格式化(yyyy-mm-dd hh:MM:ss)
- android 获取当前时间 yyyy-MM-dd HH:mm:ss
- javascript时间戳转yyyy-MM-dd hh:mm:ss
- js获取当前时间:yyyy-MM-dd HH:MM:SS
- 什么是Wayland
- JSON过滤属性,设置属性转换器的方法
- poj 3667 Hotel 线段树区间合并
- 字符编码详解及由来(UNICODE,UTF-8,GBK)
- 通达OA 缓慢,打开页面速度十分慢,cpu 负载高 如何解决?
- spring mvc 在jsp页面如何使时间以格式yyyy-MM-dd HH:mm:ss显示,24小时制
- js无缝滚动,很好用的jquery的,简单方便。
- Android Https服务器端和客户端简单实例
- VisionMobile:为何有些出版商放弃应用而压注在web
- android build 过程 (ramdisk.img、sytem.img、userdata.img)和 启动过程简单分析
- 职场新人不能做的5种花
- 添加 UINavigationBar 和 UINavigationItem
- 实用SQL命令大全
- Android 调用WebService(讲解一)