业务里的方法
public void delbatch(String ids) throws Exception {
String hql = "insert into 表名 where id号 in ("+ids;
System.out.println(hql);
iempDao.executeUpdate(hql);
}
再在在Action里写
/* 批量增加*/
public ActionForward delbatch(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
// 提交过来的请求字符串
String id = request.getParameter("id");
// 最后个,改成)
StringBuffer sb = new StringBuffer(id);
sb.setCharAt(sb.length() - 1, ')');
// 调用业务
try {
iempService.inbatch(sb.toString());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return mapping.findForward("index");
//return getall(mapping, form, request, response); }
页面你可以这样构建:
//批量增加
function inbatch()
{
//判断是否选定
var size = $(":checked").size();
if (size==0)
{
alert("请选择先");
return ;
}
//构造url
var url = "${pageContext.request.contextPath}/emp.do?action=inbatch&id=";
$(":checked").each(
function(){
url=url+this.value+",";
}
);
location = url;
}
分析下:在页面你先在每个id前面放个复选框用来勾选你要传过去的id号,当你点批量增加时再调用我给你的这个函数,注意改地址!!!我这里的函数也是jquery做的,如果不熟悉可用常用的JavaScript。StringBuffer是为了构建hql里的语句,也就是,那个反小括号。
public void delbatch(String ids) throws Exception {
String hql = "insert into 表名 where id号 in ("+ids;
System.out.println(hql);
iempDao.executeUpdate(hql);
}
再在在Action里写
/* 批量增加*/
public ActionForward delbatch(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
// 提交过来的请求字符串
String id = request.getParameter("id");
// 最后个,改成)
StringBuffer sb = new StringBuffer(id);
sb.setCharAt(sb.length() - 1, ')');
// 调用业务
try {
iempService.inbatch(sb.toString());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return mapping.findForward("index");
//return getall(mapping, form, request, response); }
页面你可以这样构建:
//批量增加
function inbatch()
{
//判断是否选定
var size = $(":checked").size();
if (size==0)
{
alert("请选择先");
return ;
}
//构造url
var url = "${pageContext.request.contextPath}/emp.do?action=inbatch&id=";
$(":checked").each(
function(){
url=url+this.value+",";
}
);
location = url;
}
分析下:在页面你先在每个id前面放个复选框用来勾选你要传过去的id号,当你点批量增加时再调用我给你的这个函数,注意改地址!!!我这里的函数也是jquery做的,如果不熟悉可用常用的JavaScript。StringBuffer是为了构建hql里的语句,也就是,那个反小括号。
addBatch(String sql)
将给定的 SQL 命令添加到此 Statement 对象的当前命令列表中。
insert into table_a
select id,name
form (select 1 as Id,'pxp' as name Union
select 2 ,'pxp2' Union
select 3 ,'pxp3'
略.................
)