月考總結:增刪改查的速度真垃圾,12點半結束的考試15點半終於調錯調完了… 啊 賊垃圾。
總結一下問題:
1) 多表聯查的 update方法不熟練,浪費時間;
public interface GoodsDAO {
List<Goods> FindGoodListByStatus(int status);
List<Goods> FindGoodListByDistrict(int districtnum);
int update(Goods g);
}
/**
* 更新 district 以外的內容
*/
@Override
public int update(Goods g) {
StringBuffer sql = new StringBuffer("update goods set ");
sql.append("goods_name=?,goods_price=?,goods_count=?,bill_status=? ");
sql.append("where id=?");
Object[] param = {g.getName(),g.getPrice(),g.getCount(),g.getStatus().getStatus(),g.getId()};
int num = executeUpdate(sql.toString(),param);
if(rs!=null){
System.out.println("更新成功!");
}else{
System.out.println("更新失敗!");
}
return num;
}
public class Update {
public static void main(String[] args) {
GoodsDAO dao = new GoodsIMP();
Goods goods1 = dao.FindGoodsById(10);
// 根據id獲取 goods1的 對象
BillStatus status = new BillStatus(0);
// 設置 BillStatus 對象(爲了添加goods的status參數)
Goods goods = new Goods(goods1.getId(),"啦啦",status,100,10,goods1.getTime());
// goods1.getTime()是獲取時間,修改方法不需要修改 time,延續本身的 time
int num = dao.update(goods);
if(num>0){
System.out.println("成功!");
}else{
System.out.println("失敗了!");
}
}
}
2) 後臺獲取了 getParameter(“id”),但是前臺沒有寫 name,於是報null 異常
<td>商品編號</td>
<td><input type="text" value="<%=request.getAttribute("id")%>" name="id"></td>
3)在獲取 statusList 時,居然腦抽使用了
List<BillStatus> statusList = new ArrayList<BillStatus>();
這個創建的是空 list 啊!!!
應該調用 FindList 的方法:
List<BillStatus> statusList = bill.SFindStatus();
4) 默認訂單狀態的顯示
<td>訂單狀態</td>
<td>
<select name="status">
<%
// 獲得 statusList
List<BillStatus> statusList = (List<BillStatus>)request.getAttribute("statusList");
// 獲得 後臺中特定對象的BillStatus 對象
BillStatus mystatus = (BillStatus)request.getAttribute("bill_status");
for(BillStatus s:statusList){
// 如果statusList中 s 的狀態數字等於mystatus的狀態數字,就選定狀態,剩餘都沒有選中
if(s.getStatus()==mystatus.getStatus()){
%>
<option value="<%=s.getStatus()%>" selected><%=s.getStatusName()%></option>
<%
}else {
%>
<option value="<%=s.getStatus()%>"><%=s.getStatusName()%></option>
<%
}
}
%>
</select>
</td>
5)要分清是FindByStatus 還是 FindByDistrict
List<Goods> FindGoodListByStatus(int status);
List<Goods> FindGoodListByDistrict(int districtnum);