添加按钮跳转到add表单页面

 <a href="${pageContext.request.contextPath }/department_saveUI.action">添加</a>

到struts.xml找到对应的Action

<action name="department_*" class="departmentAction" method="{1}">
<result name="findAll">/frame/listDept.jsp</result>
<result name="saveUI">/frame/addDepartment.jsp</result>
</action>

在Action的类中进行跳转:

public String saveUI(){
return "saveUI";
}

add页面设置form值,进行提交给saveAction,进入数据保存

<s:form id="saveForm" action="department_save.action" method="post">
<table border="0" width="600px">
<tr>
<td align="center" style="font-size:24px; color:#666"> 部门添加</td>
</tr>
<tr>
<td align="right" >
<a href="javascript:document.getElementById('saveForm').submit()">保存</a> &nbsp;&nbsp;
<a href="javascript:history.go(-1)">退回 </a>
</td>
</tr>
</table>
<br/>
<br>
<table style="font-size::16px">
<tr>
<td>部门名称:</td>
<td><s:textfield name="dname"/></td>
</tr>
<tr>
<td>部门介绍:</td>
<td></td>
</tr>
<tr>
<td width="10%"></td>
<td>
<s:textarea rows="5" cols="50" name="ddesc"/>
</td>
</tr>
</table>
</s:form>
<action name="department_*" class="departmentAction" method="{1}">
<result name="findAll">/frame/listDept.jsp</result>
<result name="saveUI">/frame/addDepartment.jsp</result>
<result name="saveSuccess" type="redirectAction">department_findAll.action</result>
</action>

save成功之后重定向到另外一个action

public String save(Department department){
departmentService.save(department);
return "saveSuccess";
}

业务层要实现事务

@Transational

java--Hibernate添加数据save的更多相关文章

  1. hibernate添加数据入门小案例

    1.建立一个java项目,在目录下新建一个lib文件夹引入hibernate架包如图所示: 2. 新建com.LHB.domain包,在包中分别创建一个Employee.java和Employee.h ...

  2. hibernate添加数据,默认字段为null的问题解决

    数据库中的一个字段默认为0,但是在用hibernate的添加之后,默认字段竟然不是0,为NULL. 查了一下.发现想要让默认字段生效.需要在*.hbm.xml添加一些参数,如下.(红色部分) dyna ...

  3. hibernate添加数据时Exception in thread "main" org.hibernate.PropertyValueException: not-null property references a null or transient value: com.javakc.hibernate.test.entity.TestEntity.testName

    意思是,一个非null属性引用了一个null或瞬态值.就是在对应实体类配置文件hbm.xml中该属性配置了not-null="true",将其去掉即可.

  4. Hibernate的数据查找,添加!

    1.首先看一下测试数据库的物理模型 2.测试所需要的Hibernate的jar包 3.数据库的sql /*=============================================== ...

  5. Java使用Mysql数据库实现批量添加数据

    EmployeeDao.java //批处理添加数据 public int saveEmploeeBatch(){ int row = 0; try{ con = DBCon.getConn(); S ...

  6. 如何在MyEclipse中通过hibernate使用jtds驱动连接数据库,并向数据库添加数据的方法

    最近学习了下如何在MyEclipse中通过hibernate使用jtds驱动连接数据库,并向数据库添加数据的方法,虽然MyEclipse中自带了连接数据库的方法,我也尝试了下其他方法,如有不当之处请指 ...

  7. [搜索]ElasticSearch Java Api(一) -添加数据创建索引

    转载:http://blog.csdn.net/napoay/article/details/51707023 ElasticSearch JAVA API官网文档:https://www.elast ...

  8. Eclipse中java向数据库中添加数据,更新数据,删除数据

    前面详细写过如何连接数据库的具体操作,下面介绍向数据库中添加数据. 注意事项:如果参考下面代码,需要 改包名,数据库名,数据库账号,密码,和数据表(数据表里面的信息) package com.ning ...

  9. java向文件中添加数据---手动版日志添加

    核心代码为创建多级文件夹创建 //目标文件 File file=new File(filePath); //若不存在即创建文件 if(!file.exists()) { if (!file.getPa ...

随机推荐

  1. 解决ubuntukylin下各种终端字母重叠的方案

    ubuntukylin14.04什么都挺好定符合中国人的使用习惯的,可是就是终端字母重叠的问题特别严重;(事实上ubuntu14.04也存在这个问题) 导致非常多非常好用的终端都使用不了,像guake ...

  2. eclipse 连接 hadoop集群

    1 网上找插件 或者 自己编译 放到eclipse plugin里面 2 重启eclipse 配置MapReduceLocation 通吃端口为9001 9000 看你自己的配置 3 新建mapRed ...

  3. 使用Swoole加速Laravel(正式环境中)

    1 Laravel的速度瓶颈在哪? 1.1 已有的一些优化方法 1.1.1 laravel官方提供了一些优化laravel的优化方法 php artisan optimize php artisan ...

  4. Leetcode - CopyWithRandomList

    Algorithm: Iterate and copy the original list first. For the random pointer, just copy the value fro ...

  5. html5中form表单新增属性以及改良的input标签元素的种类

    在HTML5中,表单新增了一些属性,input标签也有了更多的type类型,有些实现了js才能实现的特效,但目前有些浏览器不能全部支持.下面是一些h5在表单和input标签上的一些改动. <!D ...

  6. random随机模块,time时间模块

    random /随机模块: 作用: 在某个范围内取到每一个值得概率是相通的. 一.随机小数 random.random() import random print(random.random())  ...

  7. 实现asp.net mvc页面二级缓存,提高访问性能

    实现的mvc二级缓存的类 //Asp.Net MVC视图页面二级缓存 public class TwoLevelViewCache : IViewLocationCache { private rea ...

  8. Xshell调节字体大小和样式

    有时候没有看着字体太小的,好难受, 调节字体大小: ALT+P快捷键打开

  9. python中TCP和UDP区别

    TCP(Transmission Control Protocol)可靠的.面向连接的协议(eg:打电话).传输效率低全双工通信(发送缓存&接收缓存).面向字节流.使用TCP的应用:Web浏览 ...

  10. Symfony3 查询搜索功能DQL语句like查询

    //前台页面代码 <form method="GET" action="{{ path('staff_index') }}" name="sea ...