批量修改(前提要改都改)
<form action="/pams/updateAction.shtml?ation=update" method="post" onsubmit="return check()">
<table>
<tr>
<td>选择</td>
<td>是/否</td>
</tr>
<tr>
<logic:notEmpty name="ipList">
<logic:iterate id="itm" name="ipList">
<tr align="center" height="25">
<td class="tab1" valign="bottom">
<logic:equal name="itm" property="UNDEBIT_FLG" value="1">
<input type="checkbox" name="ar_id" value="<bean:write name="itm" property="ar_id"/>" checked="true">
</logic:equal>
<logic:equal name="itm" property="UNDEBIT_FLG" value="0">
<input type="checkbox" name="ar_id" value="<bean:write name="itm" property="ar_id"/>">
</logic:equal>
//有隐藏的形式(所有ARID的集合)
<input name="allarid" type="hidden" class="btn_2" value="<bean:write name="itm" property="ar_id"/>">
</td>
<td class="tab1" valign="bottom">
<logic:equal name="itm" property="NOENT_FLG" value="1">是</logic:equal>
<logic:equal name="itm" property="NOENT_FLG" value="0">否</logic:equal>
</td>
</tr>
</logic:iterate>
</logic:notEmpty>
</tr>
<tr>
<td align="left" valign="middle" height="28">
<input name="button3" type="button" class="btn_2" value="全选" onclick=selectAll()>
<input name="submit" type="submit" class="btn_2" value="修改无贷款户标志">
</td>
</tr>
</table>
</form>
<script language="javascript">
function selectAll(){
var ChkEls=document.getElementsByName("ar_id");
if(ChkEls.length!=0){
var count = 0;
for(var i=0;i< ChkEls.length;i++){
var oEl = ChkEls.item(i);
if (oEl.status==true){
count ++ ;
}
}
if(count==ChkEls.length){
for(var i=0;i< ChkEls.length;i++){
var oEl = ChkEls.item(i);
oEl.status=false;
}
}else {
for(var i=0;i< ChkEls.length;i++){
var oEl = ChkEls.item(i);
oEl.status=true;
}
}
}
}
function check(){
var ChkEls=document.getElementsByName("ar_id");
if(ChkEls.length==0){
alert("需要选择修改的记录!");
return false;
}
return true;
}
function back_qer(){
location.href = '<%=request.getAttribute("return")%>';
}
</script>
=========================================Action=============================================
public ActionForward update(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
// 机构号
String contain = request.getParameter("contain");
//单个部门号
String instno_Id[] = request.getParameterValues("instno_Id");
String id = "";
//机构----部门的所有号
String instnoId[] = request.getParameterValues("instnoId"); // 隐藏
String all_id = "";
String sql = null;
if (instno_Id != null && instno_Id.length > 0) {
for (int i = 0; i < instno_Id.length; i++) {
id = id + instno_Id[i];
if (i != instno_Id.length - 1) {
id = id + "','";
}
}
// 将对认定标志修改为1
sql = "update PAMS.ORG_MERCANT set MERCANT = '1' where instno in ('"
+ id + "')";
if (dao.update(sql) == 0) {
request.setAttribute("info", "对部门认定修改失败,请重新操作!");
}
}
// 格式化返回页所有的instnoId
for (int i = 0; i < instnoId.length; i++) {
all_id = all_id + instnoId[i];
if (i != instnoId.length - 1) {
all_id = all_id + "','";
}
}
// 将部门认定标志修改为0
String sql2 = "update PAMS.ORG_MERCANT set MERCANT = '0' where instno in ('"
+ all_id + "')";
if (instno_Id != null && instno_Id.length > 0) {
sql2 = sql2 + "and instno not in ('" + id + "')";
}
if (dao.update(sql2) == 0) {
request.setAttribute("info", "对部门认定修改失败,请重新操作!");
}
request.setAttribute("info", "对部门认定修改标志修改成功!");
//跳转到上面的那个方法来显示
request.setAttribute("result", "/pams/OrgMercant.shtml?action=OrgMercantlist&asptorgidt=" + contain);
return mapping.findForward("result");
==============================DAO============================
public int update(String sql){
Connection con = null;
ResultSet rs = null;
Statement stmt = null;
Session session = getSession();
int totalrows = 0;
try {
con=session.connection();
stmt=con.createStatement();
stmt.executeUpdate(sql);
stmt.close();
con.close();
} catch (Exception re) {
log.error("UNDEBIT_FLG_UPDATE failed", re);
return (int) 0;
}finally{
session.close();
}
return 1;//返回正常
}
========================================参考资料语句Action==========================
public ActionForward update(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
String newvalue = request.getParameter("newvalue");
String id = request.getParameter("id");
String opid = UserSession.getCurrentUserID(request.getSession());
String pageno = request.getParameter("ctlPageNo");
String urlParam = "&pageNo=" + CFormat.forbidNull(pageno);
try {
Double value = null;
if(!CFormat.isEmpty(newvalue))
value=Double.valueOf(newvalue.trim());
if (!CFormat.isEmpty(id)) {
ParamAgreedep p = (ParamAgreedep) this.dao
.findById(ParamAgreedep.class, id);
p.setFactrate(value);
p.setInputdate(DateTimeUtil.getDateString(DateTimeUtil
.getSqlDate(new java.util.Date()), "yyyyMMdd"));
p.setUserid(opid);
this.dao.attachDirty(p);
request.setAttribute("info", "修改参数成功!");
}
} catch (NumberFormatException nfe) {
request.setAttribute("info", "您输入了不合法的新参数值!");
request.setAttribute("historyBack", "true");
} catch (Exception ex) {
request.setAttribute("info", "修改参数失败,请重试!");
request.setAttribute("historyBack", "true");
}
request.setAttribute("result",
"/pams/xycksjll.shtml?action=list"+urlParam);
return mapping.findForward("result");
}
============================DAO==============
public Object findById(Class clazz, String key) {
log.debug("getting Object instance with id: " + key);
Object instance = null;
try {
instance = getHibernateTemplate().get(clazz,key);
return instance;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
}
public boolean attachDirty(Object instance) {
log.debug("attaching dirty Object instance");
boolean ok= false;
try {
getHibernateTemplate().update(instance);
ok=true;
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
return ok;
}
本文介绍了一种通过网页表单批量修改系统中特定标志的方法,并提供了实现代码示例,包括前端页面展示、全选功能、后端逻辑处理及数据库更新操作。
3232

被折叠的 条评论
为什么被折叠?



