折磨半天的问题只需要在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}">更新