pageEncoding="utf-8"%>
Connection ct = null;
PreparedStatement ps = null;
ResultSet rs = null;
String DRIVER = "com.mysql.jdbc.Driver";
String URL = "jdbc:mysql://localhost:3306/smg";
String USERNAME = "root";
String PASSWD = "root";
List orderDetailList = new ArrayList();
String doflag = request.getParameter("doflag");
if(doflag==null||doflag.length()==0) {
try {
Class.forName(DRIVER);
ct = DriverManager.getConnection(URL, USERNAME, PASSWD);
String orderIds = request.getParameter("orderIds");
if(null != orderIds && !orderIds.isEmpty()) {
System.out.println(orderIds.length());
System.out.println(orderIds);
StringBuilder sb = new StringBuilder();
String str = "(";
for(int i=0;i
if(',' != orderIds.charAt(i)) {
sb.append(orderIds.charAt(i));
if(i == orderIds.length() - 1) {
str = str + "'"+sb+"'";
}
} else {
str = str + "'"+sb+"'" + ",";
sb = new StringBuilder();
}
}
str = str + ")";
System.out.println(str);
//查出所有orderId对应的列 表
String sql = "select * from ordDetail where orderId in " +str;
ps = ct.prepareStatement(sql);
rs = ps.executeQuery();
while(rs.next()) {
OrderDetail orderDetail = new OrderDetail();
orderDetail.setId(rs.getInt("id"));
orderDetail.setOrderId(rs.getString("orderId"));
orderDetail.setName(rs.getString("name"));
orderDetail.setAddress(rs.getString("address"));
orderDetail.setFlag(rs.getInt("flag"));
orderDetailList.add(orderDetail);
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
}
} else if("update".equals(doflag)) {
try {
Class.forName(DRIVER);
ct = DriverManager.getConnection(URL, USERNAME, PASSWD);
//根据获取的flag判断是否提交并获取提交的checkbox
String ids[] = request.getParameterValues("mycheckbox");
//拼接sql语句
StringBuilder sb = new StringBuilder();
String str = "";
if(null != ids && ids.length != 0) {
sb.append("(");
for(String id : ids) {
sb.append("'"+id+"'");
sb.append(",");
}
str = sb.substring(0,sb.length()-1).toString();
str = str + ")";
//根据id更新数据
String sqlStr = "update ordDetail set flag = 1 - flag where id in "+str;
System.out.println(sqlStr);
ps = ct.prepareStatement(sqlStr);
ps.execute();
request.setAttribute("resultflag", "save" );
}
} catch(Exception e) {
request.setAttribute("resultflag", "error");
e.printStackTrace();
}
}
%>
function onload(){
var flag = '';
alert(flag);
if(flag == 'error')
{
window.returnValue=flag;
window.close();
}
else if (flag == 'save')
{
window.returnValue=flag;
window.close();
}
}
function onsubmit(){
//document.getElementById("save").doflag.value='save';
document.getElementById("save").submit();
return false;
}
function oncancel(){
window.returnValue="cancel";
window.close();
}
//全选
function doallcheck(){
var allche = document.getElementById("allid");
var che = document.getElementsByName("mycheckbox");
if(allche.checked == true){
for(var i=0;i
che[i].checked="checked";
}
}else{
for(var i=0;i
che[i].checked=false;
}
}
}
function doclickcheck(obj) {
if(obj.checked==false){
var allche = document.getElementById("allid");
allche.checked = false;
}
}
我的订单
orderId | name | address |
---|
if(null != orderDetailList && orderDetailList.size() != 0) {
for(OrderDetail orderDetail : orderDetailList) {
%>
if(orderDetail.getFlag() == 1) {
%>
} else if(orderDetail.getFlag() == 0) {
%>
}
%>
}
}
%>