不熟悉的知识

      首先解决的页面的排版问题:使用了一个table来列举商品的信息,注意第一行的第一列属性中有rowspan属性,这个属性用来表示该列跨几行,在下边一个列属性中有colspan是跨几列的属性值。在这个中,我们定义了一个占据9行的一列用来显示我们的图像,图像调用了showImage的controller方法来显示图片。style属性来设置图片的长和宽,注意该项的写法,style="width:300px;height:400px"

<td rowspan="9" style="height:300px;width:400px;"><img alt="" src="showImage?pictureId=${commodityForm.pictureId}" style="height:300px;width:400px;"></td>

     

      在修改商品信息中,因为涉及到input的type为file标签,我们需要在对应的controller中加入参数:

@RequestParam(value = "file", required = false) MultipartFile file

@RequestParam(value = "attachments", required = false) MultipartFile attachments

      这两个参数value都是对应的input中的name属性,MultipartFile表明传入的是一个文件。在执行添加商品的service中,我们涉及了一个select,这个sql语句是执行了从数据库中自动生成一个pictureId.它的sql文写法如下:

<select id="getSeq" resultClass="java.lang.Integer">

SELECT _nextval('commodityId')

</select>

   在service中addCommodity的写法如下:

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;                                                       //插入失败

}


你可能感兴趣的:(不熟悉的知识)