一、SSM整合的CRUD操作
本节操作除了需配置事务管理外,不需要配置额外的配置内容。基本都是jsp页面的js操作和后台代码操作。
二、配置内容
事务的配置
在applicationContext-dao.xml中配置
<!-- 定义事务管理器 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<!-- 注解驱动,启动注解 -->
<tx:annotation-driven transaction-manager="transactionManager"/>
在Service的实现类记得添加事务注解
三、后台操作
3.1 增加操作
3.1.1 JSP页面修改
在数据表格的工具栏上增加添加操作按钮
$(function(){
// alert(1);
$('#dg').datagrid({
url:'${pageContext.request.contextPath }/productList',
columns:[[
{field:'pName',title:'商品名称',width:160,sortable:true},
{field:'pPrice',title:'商品单价',width:160,sortable:true},
{field:'xxx',title:'操作',width:180,align:'center',formatter: function(value,row,index){
return "<a href='#' onclick='edit(" + row.pId + ")'>修改</a> | <a href='#' onclick='del(" + row.pId + ")'>删除</a>";
}
}
]],
//显示斑马线
striped:true,
//显示分页工具条
pagination:true,
//自定义pagesize
pageList:[3,5,10],
pageSize:5,
//数据表格的工具栏
toolbar: [{
iconCls: 'icon-add',
handler: function(){
$("#winAdd").window('open');
}
}]
});
});
表格中增加隐藏的新增商品表格填写属性内容
<h1>商品管理页面</h1>
<table id="dg" style="width:500px;"></table>
<!-- 添加商品的表单,默认隐藏 -->
<div id="winAdd" class="easyui-window" title="添加商品" style="width:600px;height:400px"
data-options="iconCls:'icon-save',modal:true,closed:true">
<form id="formAdd" method="post">
<table cellSapcing=0 cellPadding