SSM 增加时间到数据库

       1.    MySQL设计

              

       2.    pojo类:    private Timestamp createTime

       3.    controller类中:

//时间转换
        String nowTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
        //上传时间
        product.setCreateTime(Timestamp.valueOf(nowTime));

        4.    jsp页面查询数据库的时间时会显示下图的解决办法:

                                                

                a.在显示时间的jsp最上面增加:


<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

                b.在需要显示的值的位置添加:

                    

<th><fmt:formatDate value="${product.createTime}" pattern="yyyy-MM-dd HH:mm:ss" /> </th>

猜你喜欢

转载自blog.csdn.net/qq_39645768/article/details/80934901
ssm