打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
spring mvc 在jsp页面如何使时间以格式yyyy

首先,javaBean为:

  1. <span style="color:#ff0000;"></span><p><span style="color:#ff0000;">import java.util.Date;</span></p><p>  
  2. public class OutcomeVo {  
  3.     private int oid;  
  4.     private int uid;  
  5.     private String ocName;  
  6.     private String ocType;  
  7.     private Date gotOCDate;  
  8.     <span style="color:#ffffff;">private Date commitTime;  
  9. </span> private String fileUrl;  
  10.       
  11.     public String getFileUrl() {  
  12.         return fileUrl;  
  13.     }  
  14.     public void setFileUrl(String fileUrl) {  
  15.         this.fileUrl = fileUrl;  
  16.     }  
  17.     public String getOcName() {  
  18.         return ocName;  
  19.     }  
  20.     public void setOcName(String ocName) {  
  21.         this.ocName = ocName;  
  22.     }  
  23.     public int getOid() {  
  24.         return oid;  
  25.     }  
  26.     public void setOid(int oid) {  
  27.         this.oid = oid;  
  28.     }  
  29.     public int getUid() {  
  30.         return uid;  
  31.     }  
  32.     public void setUid(int uid) {  
  33.         this.uid = uid;  
  34.     }  
  35.     public String getOcType() {  
  36.         return ocType;  
  37.     }  
  38.     public void setOcType(String ocType) {  
  39.         this.ocType = ocType;  
  40.     }  
  41.     public Date getGotOCDate() {  
  42.         return gotOCDate;  
  43.     }  
  44.     public void setGotOCDate(Date gotOCDate) {  
  45.         this.gotOCDate = gotOCDate;  
  46.     }  
  47.     public Date getCommitTime() {  
  48.         return commitTime;  
  49.     }  
  50.     public void setCommitTime(Date commitTime) {  
  51.         this.commitTime = commitTime;  
  52.     }  
  53. }  
  54. </p>  


 

其次,在后台从数据库中获取的时候是:

  1. import java.sql.ResultSet;  
  2. import java.sql.SQLException;  
  3. import java.util.HashMap;  
  4. import java.util.List;  
  5. import java.util.Map;  
  6.   
  7. import org.springframework.jdbc.core.RowMapper;  
  8. import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;  
  9. import org.springframework.jdbc.core.namedparam.SqlParameterSource;  
  10. import org.springframework.jdbc.support.GeneratedKeyHolder;  
  11. import org.springframework.jdbc.support.KeyHolder;  
  12. import org.springframework.stereotype.Repository;  
  13.   
  14. import cn.cnic.outcome.front.vo.OutcomeVo;  
  15. import cn.cnic.outcome.util.BaseDAO;  
  16.   
  17. @Repository  
  18. @SuppressWarnings("unchecked")  
  19. public class OutcomeDao extends BaseDAO{  
  20.     private static final String TABLE = " outcome ";  
  21.     private static final String FIELDS = " uid,ocType,ocName,fileUrl,gotOCDate,commitTime ";  
  22.     private static final String SAVED_VALUES = " :uid,:ocType,:ocName,:fileUrl,:gotOCDate,:commitTime ";  
  23.     private static final String UPDATED_VALUES = " uid=:uid,ocType=:ocType,ocName=:ocName,fileUrl=:fileUrl,gotOCDate=:gotOCDate ";  
  24.       
  25.     @SuppressWarnings("unchecked")  
  26.     public List<OutcomeVo> findByProperty(String propertyName, Object value) {  
  27.         String sql = "select distinct * from " + TABLE + " where "  
  28.                 + propertyName + "=:" + propertyName;  
  29.         Map paramMap = new HashMap();  
  30.         paramMap.put(propertyName, value);  
  31.         return (List<OutcomeVo>) getNamedParameterJdbcTemplate().query(sql,  
  32.                 paramMap, rowMapper);  
  33.     }  
  34.   
  35.     @SuppressWarnings("unchecked")  
  36.     public List<OutcomeVo> findAll() {  
  37.         String sql = "select * from " + TABLE + " order by oid";  
  38.         Map paramMap = new HashMap();  
  39.         return (List<OutcomeVo>) getNamedParameterJdbcTemplate().query(sql,  
  40.                 paramMap, rowMapper);  
  41.     }  
  42.   
  43.     public int save(OutcomeVo outcomeVo) {  
  44.         String sql = "insert into " + TABLE + " ( " + FIELDS + " ) values ( "  
  45.                 + SAVED_VALUES + " )";  
  46.         KeyHolder keyHolder = new GeneratedKeyHolder();  
  47.         SqlParameterSource ps = new BeanPropertySqlParameterSource(outcomeVo);  
  48.         getNamedParameterJdbcTemplate().update(sql, ps, keyHolder);  
  49.         return keyHolder.getKey().intValue();  
  50.     }  
  51.   
  52.     public int update(OutcomeVo outcomeVo) {  
  53.         String sql = "update " + TABLE + " set " + UPDATED_VALUES  
  54.                 + " where oid=:oid";  
  55.         SqlParameterSource ps = new BeanPropertySqlParameterSource(outcomeVo);  
  56.         return getNamedParameterJdbcTemplate().update(sql, ps);  
  57.     }  
  58.   
  59.     @SuppressWarnings("unchecked")  
  60.     private RowMapper rowMapper = new RowMapper() {  
  61.         public Object mapRow(ResultSet rs, int arg1) throws SQLException {  
  62.             OutcomeVo outcomeVo = new OutcomeVo();  
  63.             <span style="color:#ff0000;">outcomeVo.setCommitTime(rs.getTimestamp("commitTime"));  
  64. </span>         outcomeVo.setGotOCDate(rs.getDate("gotOCDate"));  
  65.             outcomeVo.setOcType(rs.getString("ocType"));  
  66.             outcomeVo.setOcName(rs.getString("ocName"));  
  67.             outcomeVo.setFileUrl(rs.getString("fileUrl"));  
  68.             outcomeVo.setOid(rs.getInt("oid"));  
  69.             outcomeVo.setUid(rs.getInt("uid"));  
  70.             return outcomeVo;  
  71.         }  
  72.     };  
  73. }  



最后,在页面上显示的时候是这样的:

  1. <fmt:formatDate value="${outcome.commitTime}"  <span style="color:#ff0000;">pattern="yyyy-MM-dd HH:mm:ss"</span> />  


以上仅为关键代码,只需看红色字体部分即可知晓,如何操作

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Spring MVC初探
学习SpringMVC系列教程(一)Spring MVC入门
JAVA Web框架比较
webwork+spring+hibernate
Spring 系列,第 3 部分: 进入 Spring MVC
Apache Geronimo 和 Spring 框架,第 5 部分: Spring MVC
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服