jsp获取当前时间存入mysql数据库_插入记录时获取当前时间保存到数据库并显示出来...

本文介绍了如何在Struts2和Hibernate4整合的项目中,通过在Action中设置new Date()来获取当前时间,并将其存储到MySQL数据库中。在categoryAdd.jsp页面上,将createtime字段设为隐藏,然后在categoryAddAction中将时间对象传递给Hibernate保存。成功保存后,数据将在categoryManage.jsp页面上展示,包括类别编号、名称、创建时间和描述。
摘要由CSDN通过智能技术生成

折磨半天的问题只需要在action中set时new Date()。。。

Struts2+hibernate4,数据库mysql,项目目录C:\Users\111\workspacebyluna\MedicineManager​

修改内容:

​添加记录categoryAdd.jsp页面:createtime设为隐藏

提交表单的​action类:categoryAddAction

​public class categoryAddAction

extends ActionSupport {

private int id; // 类别编号

private String name; // 类别名称

private String description; // 类别描述

private Date createTime;

//类别创建时间

private CategoryService categoryService = new

CategoryServiceImpl();

getter和setter方法。。。

@Override

public String execute() throws Exception {

Category category = new Category();

category.setId(id);

category.setName(name);

category.setDescription(description);

category.setCreateTime(new

Date());

if (categoryService.saveCategory(category)) {

return SUCCESS;

} else {

this.addActionError("该类别已经添加过了,请不要重复添加!");

return INPUT;

}

}

​显示页面:categoryManage.jsp

类别编号:

name="id" size="40">

${category.id}

${category.name}

${category.createTime}

${category.subDesc}

href="categoryParticular.action?id=${category.id}">查看

href="categoryUpadateBefore.action?id=${category.id}">更新

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值