首先解決的頁面的排版問題:使用了一個table來列舉商品的信息,注意第一行的第一列屬性中有rowspan屬性,這個屬性用來表示該列跨幾行,在下邊一個列屬性中有colspan是跨幾列的屬性值。在這個中,咱們定義了一個佔據9行的一列用來顯示咱們的圖像,圖像調用了showImage的controller方法來顯示圖片。style屬性來設置圖片的長和寬,注意該項的寫法,style="width:300px;height:400px"java
<td rowspan="9" style="height:300px;width:400px;"><img alt="" src="showImage?pictureId=${commodityForm.pictureId}" style="height:300px;width:400px;"></td>sql
在修改商品信息中,由於涉及到input的type爲file標籤,咱們須要在對應的controller中加入參數:數據庫
@RequestParam(value = "file", required = false) MultipartFile fileui
@RequestParam(value = "attachments", required = false) MultipartFile attachmentsspa
這兩個參數value都是對應的input中的name屬性,MultipartFile代表傳入的是一個文件。在執行添加商品的service中,咱們涉及了一個select,這個sql語句是執行了從數據庫中自動生成一個pictureId.它的sql文寫法以下:orm
<select id="getSeq" resultClass="java.lang.Integer">圖片
SELECT _nextval('commodityId')ip
</select>ci
在service中addCommodity的寫法以下:get
public boolean addCommodity(CommodityForm frm) {
Integer sequee = queryDao.executeForObject("Commodity.getSeq", null, Integer.class);
//獲得一個自增的commundityId;
String commodityId = frm.getUpdateTime().substring(0, 4) + String.format("%011d", sequee);
//C
frm.setCommodityId(commodityId);
if (frm.getPicture().length != 0) { //能夠獲得圖片
frm.setPictureId(commodityId);
int picResult = updateDao.execute("Commodity.addPicture", frm); //插入圖片
if (picResult != 1) {
return false;
}
}
int result = updateDao.execute("Commodity.addCommodity", frm);//插入除圖片外的其餘數據
if (result == 1) { //插入成功
return true;
}
return false; //插入失敗
}