解决方案 »
- 为什么要在JUnit SetUp方法中创建对象,在SetUp之前可以吗?
- java.sql.SQLException: Io exception: Broken pipe 问题,请帮忙看看
- 飞思在线的网站是不是挂了?
- Hibernate中如何将自定义类型映射成ORACLE数据库中的基本类型
- 实体BEAN,消息BEAN,会话BEAN有什么区别?有状态和无状态BEAN的区别?
- 关于页面刷新的问题,在线等
- Hibernate疑难问题两则
- 搞过自动生成class文件的进
- 100分请教开发工具一问题
- 关于webServices客户端
- java 如何读取MP3比特率 、时间长度等信息
- java程序执行trace
if (null != this.id) {
this.employeeManager.deleteEmployee(this.id);
} else {
if (ids.length > 0) {
for (Long id : ids) {
this.employeeManager.deleteEmployee(id);
}
}
}
if (this.employeeManager.listEmployee().size() > 0) {
return SUCCESS;
} else {
return INPUT;
} }3、列表页面:list.jsphttp://blog.csdn.net/cai5/article/details/6565523查看以上内容
jsp页面
<script>
function actions() {
var d=0;
for(var i=0;i <document.myForm.elements.length;i++)
{
var e=document.myForm.elements[i];
if(e.type=='checkbox'&& e.checked)
{
d=1;
break;
}
}
if(d==0)
{ alert("没有选择");
}else
{ if(confirm("您确定要删除这些记录吗?")){
document.myForm.submit();
}
}
}
</script>
<form action="delNewsBatch.action" name="myForm" method="post">
<a href="javascript:actions()">
批量删除</a>
<input type="checkbox" name="id" value="<%=list.get(i).getId() %>">
</form>
struts2的action方法
/**
* 请求delNewsBatch处理函数 ,批量删除新闻
* @return
* @throws Exception
*/
public String delNewsBatch() throws Exception{ String[] arr =(String [])ActionContext.getContext().getParameters().get("id");
if(arr!=null){
int[] arrId = new int[arr.length];
for (int i = 0; i < arr.length; i++) {
arrId[i] = Integer.parseInt(arr[i]);
}
newsService.delNews(arrId);
}
return SUCCESS;
}spring和hibernat我就不写了,传入参数是一个数组,循环删除就ok了,没什么难度了。
jsp:
在action里面就是获取不到页面传来的ids,不知道哪里出了毛病
1:在Bean中多加一个属性.Integer [] ids;
2:页面中 <input type="checkbox" name="bean.ids" value="${bean.id}"/>
3:action中有bean的成员变量,会自动获得你页面上选中的复选框,封装到ids的数组中
4:把数组编程字符串 str =“1,2,3”
5:delete ..... where id in (str).
hibernate写下呗。。万分感谢
{
newsDao.delNews(arrId);
}
hibernate的dao类方法 /**
* 根据新闻id,批量删除新闻
* @param id
*/
public void delNews(int[] id) {
for (int i = 0; i < id.length; i++) {
int newsid = id[i];
News news=getHibernateTemplate()
.get(News.class , newsid);
if(news!=null)
getHibernateTemplate().delete(news);}
}
} 代码写的有点乱,马上要放假回家了,自己随便写的几句,你凑合着看把。主要看思路
jsp:<input type="checkbox" name="ids" value="${article.id}">
action:public String del()
{
HttpServletRequest quest = ServletActionContext.getRequest();
String[] str = request.getParameterValues(ids);
System.out.println(str);
}
这样写的话,想在action输出ids的值,运行之后页面报错:java.util.Hashtable.get(Hashtable.java:334)
页面的checkbox的name 你定义好 在action 定义同样的变量名数组来获取生成setter getter例如:
<input type="checkbox" name="ids" value="1" >
<input type="checkbox" name="ids" value="2" >
<input type="checkbox" name="ids" value="3" >
action中:
private int[] ids; //setter getterservice:
直接把数组 传递过去
void deleteAll(int[] ids );dao:
StringBuffer sb= new StringBuffer();
for (int i = 0; i < ids.length; i++) {
if (i != 0) {
sb.append(",");
} sb.append(ids[i]);
}getHibernateTemplate().bulkUpdate("delete from"+反射得到的表名+ "where id in ("+sb.toString()+")");
org.springframework.orm.hibernate3.HibernateQueryException: unexpected char: '@' [delete from com.pojo.TArticle01 where id in([I@12c7d13)]; nested exception is org.hibernate.QueryException: unexpected char: '@' [delete from com.pojo.TArticle01 where id in([I@12c7d13)]用您这个方法写的报这个错、。好像是要数据类型转换?具体怎么解决
action里输出ids的值为[I@12c7d13
StringBuffer sb = new StringBuffer();
for(int i=0;i<ids.length;i++)
{
if(i!=0)
{
sb.append(",");
}
sb.append(ids[i]);
}
System.out.println("-------"+ids);
getHibernateTemplate().bulkUpdate("delete from TArticle01 where id in("+ids+")");
System.out.println(ids+"=====");
}
这是dao的Impl方法。我试着用了splint分割符,还是不行。
你这拼凑完sb 用得却是 ids。
public void delAll(int[] ids) {StringBuffer sb = new StringBuffer();
for(int i=0;i<ids.length;i++)
{
if(i!=ids.length-1)
{
sb.append(",");
}
sb.append(ids[i]);
}
String sql = "delete from TArticle01 where id in("+sb.toString()+")";
getHibernateTemplate().bulkUpdate(sql );
System.out.println("执行的sql为:"+sql );}
Hibernate: delete from comp.dbo.t_ARTICLE_01 where ID in (0)
执行的sql为delete from TArticle01 where id in(0)
控制台打印出了这两句话,sql为0,没有接收到?
2:页面中 <input type="checkbox" name="bean.ids" value="${bean.id}"/>
3:action中有bean的成员变量,会自动获得你页面上选中的复选框,封装到ids的数组中
4:把数组编程字符串 str =“1,2,3”
public void delAll(int[] ids)
{
String str =null;
for(int i=0;i<ids.length;i++)
{
if(i!=ids.length-1){
str+=",";
}
str+=ids[i].toString();
}
String sql = "delete from TArticle01 where id in("+str+")";
getHibernateTemplate().bulkUpdate(sql );
System.out.println("执行的sql为:"+sql );
}
借用了xiaozhongmiaoyun 和sd4000784 的思路。