首页 > 代码库 > 011杰信-创建购销合同Excel报表系列-3-建立合同货物(修改,删除):合同货物表是购销合同表的子表

011杰信-创建购销合同Excel报表系列-3-建立合同货物(修改,删除):合同货物表是购销合同表的子表

前面的一篇文章做的是修改删除,这篇文章做的是合同货物的修改和删除。

业务功能如下:

技术分享

进入上面页面后,有删除和修改两个链接。项目结构如下:

技术分享

技术分享

 

上面的红色框框就是这个功能的代码结构:

我们还是按照Mapper.xml文件->Dao层->Service层->控制层。

 

 

 

COntractProductMapper.xml代码如下:

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"><mapper namespace="cn.itcast.jk.mapper.ContractProductMapper"><resultMap type="cn.itcast.jk.domain.ContractProduct" id="contractProductRM"><id  property="id" column="CONTRACT_PRODUCT_ID"/><result property="contractid" column="CONTRACT_ID"/><result property="factoryid" column="FACTORY_ID"/><result property="factoryname" column="FACTORY_NAME"/><result property="productno" column="PRODUCT_NO"/><result property="productimage" column="PRODUCT_IMAGE"/><result property="productdesc" column="PRODUCT_DESC"/><result property="cnumber" column="CNUMBER"/><result property="outnumber" column="OUT_NUMBER"/><result property="loadingrate" column="LOADING_RATE"/><result property="boxnum" column="BOX_NUM"/><result property="packingunit" column="PACKING_UNIT"/><result property="price" column="PRICE"/><result property="amount" column="AMOUNT"/><result property="finished" column="FINISHED"/><result property="exts" column="CONTRACT_ID"/><result property="orderno" column="CONTRACT_ID"/></resultMap><!-- 开始写sql语句 --><select id="find"  parameterType="map"  resultMap="contractProductRM" >select * from contract_product_c where 1=1<if test="contractId != null">and CONTRACT_ID=#{contractId}</if></select><!-- 取一个数据 --><select id="get" parameterType="string"  resultMap="contractProductRM"><!-- 这个pid可以随便取的 -->select * from contract_product_c where CONTRACT_PRODUCT_ID=#{pid}</select><insert id="insert" parameterType="cn.itcast.jk.domain.ContractProduct">insert into contract_product_c(CONTRACT_PRODUCT_ID,CONTRACT_ID,FACTORY_ID,FACTORY_NAME,PRODUCT_NO,PRODUCT_IMAGE,PRODUCT_DESC,CNUMBER,OUT_NUMBER,LOADING_RATE,BOX_NUM,PACKING_UNIT,PRICE,AMOUNT,FINISHED,EXTS,ORDER_NO)values(<!-- 因为 id,contractid,factoryid肯定不能为空,所以jdbcType就不用写了。-->#{id},#{contractid},#{factoryid},#{factoryname,jdbcType=VARCHAR},#{productno,jdbcType=VARCHAR},#{productimage,jdbcType=VARCHAR},#{productdesc,jdbcType=VARCHAR},#{cnumber,jdbcType=INTEGER},#{outnumber,jdbcType=INTEGER},#{loadingrate,jdbcType=VARCHAR},#{boxnum,jdbcType=INTEGER},#{packingunit,jdbcType=VARCHAR},#{price,jdbcType=VARCHAR},#{amount,jdbcType=VARCHAR},#{finished,jdbcType=INTEGER},#{exts,jdbcType=VARCHAR},#{orderno,jdbcType=INTEGER})</insert><!-- 修改合同货物 --><update id="update" parameterType="cn.itcast.jk.domain.ContractProduct">update contract_product_c <set><if test="factoryname!=null">FACTORY_NAME=#{factoryname}</if><if test="productno!=null">PRODUCT_NO=#{productno}</if><if test="productimage!=null">PRODUCT_IMAGE=#{productimage}</if><if test="productdesc!=null">PRODUCT_DESC=#{productdesc}</if><if test="cnumber!=null">CNUMBER=#{cnumber}</if><if test="outnumber!=null">OUT_NUMBER=#{outnumber}</if><if test="loadingrate!=null">LOADING_RATE=#{loadingrate}</if><if test="boxnum!=null">BOX_NUM=#{boxnum}</if><if test="packingunit!=null">PACKING_UNIT=#{packingunit}</if><if test="price!=null">PRICE=#{price}</if><if test="amount!=null">AMOUNT=#{amount}</if><if test="finished!=null">FINISHED=#{finished}</if><if test="exts!=null">EXTS=#{exts}</if><if test="orderno!=null">ORDER_NO=#{orderno}</if></set><!-- 这里的id是 ContractProduct这个类里面的id-->where CONTRACT_PRODUCT_ID=#{id}</update><!-- 删除合同货物  --><delete id="deleteById" parameterType="string" >delete from  contract_product_c where CONTRACT_PRODUCT_ID=#{id}</delete></mapper>

Dao层:就是基础的BaseDaoImpl.java

package cn.itcast.jk.dao.impl;import java.io.Serializable;import java.util.List;import java.util.Map;import org.apache.ibatis.session.SqlSessionFactory;import org.mybatis.spring.support.SqlSessionDaoSupport;import org.springframework.beans.factory.annotation.Autowired;import cn.itcast.jk.dao.BaseDao;import cn.itcast.jk.pagination.Page;public abstract class BaseDaoImpl<T> extends SqlSessionDaoSupport implements BaseDao<T>{    @Autowired    //mybatis-spring 1.0无需此方法;mybatis-spring1.2必须注入。    public void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory){        super.setSqlSessionFactory(sqlSessionFactory);    }               private String ns;        //命名空间    public String getNs() {        return ns;    }    public void setNs(String ns) {        this.ns = ns;    }        public List<T> findPage(Page page){        List<T> oList = this.getSqlSession().selectList(ns + ".findPage", page);        return oList;    }    public List<T> find(Map map) {        List<T> oList = this.getSqlSession().selectList(ns + ".find", map);        return oList;    }    public T get(Serializable id) {        return this.getSqlSession().selectOne(ns + ".get", id);    }    public void insert(T entity) {        this.getSqlSession().insert(ns + ".insert", entity);    }    public void update(T entity) {        this.getSqlSession().update(ns + ".update", entity);    }    public void deleteById(Serializable id) {        this.getSqlSession().delete(ns + ".deleteById", id);    }    public void delete(Serializable[] ids) {        this.getSqlSession().delete(ns + ".delete", ids);    }}

然后在ContractProductDaoImpl.java中写:

package cn.itcast.jk.dao.impl;import java.io.Serializable;import java.util.List;import java.util.Map;import org.springframework.stereotype.Repository;import cn.itcast.jk.dao.ContractProductDao;import cn.itcast.jk.domain.ContractProduct;import cn.itcast.jk.pagination.Page;@Repositorypublic class ContractProductDaoImpl extends BaseDaoImpl<ContractProduct> implements ContractProductDao  {    public ContractProductDaoImpl()    {        super.setNs("cn.itcast.jk.mapper.ContractProductMapper");                    }}

 

Service层:

ContractProductServiceImpl.java:

package cn.itcast.jk.service.impl;import java.io.Serializable;import java.util.List;import java.util.Map;import java.util.UUID;import javax.annotation.Resource;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Service;import cn.itcast.jk.dao.ContractProductDao;import cn.itcast.jk.domain.Contract;import cn.itcast.jk.domain.ContractProduct;import cn.itcast.jk.pagination.Page;import cn.itcast.jk.service.ContractProductService;@Servicepublic class ContractProductServiceImpl implements ContractProductService{    @Resource    ContractProductDao contractProductDao;@Overridepublic List<ContractProduct> findPage(Page page) {    return contractProductDao.findPage(page);}@Overridepublic List<ContractProduct> find(Map paraMap) {    return contractProductDao.find(paraMap);}@Overridepublic ContractProduct get(Serializable id) {    return contractProductDao.get(id);}@Overridepublic void insert(ContractProduct contractproduct) {    contractproduct.setId(UUID.randomUUID().toString());    contractProductDao.insert(contractproduct);    }@Overridepublic void update(ContractProduct contractproduct) {    contractProductDao.update(contractproduct);}@Overridepublic void deleteById(Serializable id) {    contractProductDao.deleteById(id);}@Overridepublic void delete(Serializable[] ids) {    contractProductDao.delete(ids);}    }

 

页面层:

新增页面(包含了修改和删除的链接)

jCOntractproductCreate.jsp:

<%@ page language="java" pageEncoding="UTF-8"%><%@ include file="../../base.jsp"%><html xmlns="http://www.w3.org/1999/xhtml"><head><title></title><!-- 设置 id为factoryname的input的值--><script type="text/javascript">function setfactoryName(val){var ere=document.getElementById("factoryname");ere.value=val;}</script> <!--  <script type="text/javascript" src="http://www.mamicode.com/js/datepicker/WdatePicker.js"></script> --></head><body>    <form method="post">    <input text="text" name="contractid" value="${contractId}">            <div id="menubar">            <div id="middleMenubar">                <div id="innerMenubar">                    <div id="navMenubar">                        <ul>                            <li id="save"><a href="#"                                onclick="formSubmit(‘insert.action‘,‘_self‘);">确定</a></li>                            <li id="back"><a href="list.action">返回</a></li>                        </ul>                    </div>                </div>            </div>        </div>        <div class="textbox" id="centerTextbox">            <div class="textbox-header">                <div class="textbox-inner-header">                    <div class="textbox-title">新增合同货物信息</div>                </div>            </div>            <div>                <div>                    <table class="commonTable" cellspacing="1">                        <tr>                            <td class="columnTitle_mustbe">厂家名称:</td>                            <td class="tableContent">                                                        <!-- <input type= name="factoryname" /> -->                            <!-- this.selectedIndex当前选中的索引值 -->                            <select  name="factoryid" onchange="setfactoryName(this.options[this.selectedIndex].text)">                            <option value="">--请选择--</option>                             <c:forEach items="${listfactory}" var="f">                               <option value="${f.id}">${f.factoryName }</option>                                                          </c:forEach>                                                                            </select>                            <input  type="hidden" id="factoryname" name="factoryname">                                                                                    </td>                                                                                                                <td class="columnTitle_mustbe">货号</td>                            <td class="tableContent"><input type="text" name="productno" /></td>                        </tr>                        <tr>                            <td class="columnTitle_mustbe">货物照片</td>                            <td class="tableContent"><input type="text" name="productimage" /></td>                            <td class="columnTitle_mustbe">货物描述</td>                            <td class="tableContent"><input type="text" name="productdesc" /></td>                        </tr>                        <tr>                            <td class="columnTitle_mustbe">数量</td>                            <td class="tableContent"><input type="text" name="cnumber" /></td>                                                    <td class="columnTitle_mustbe">实际出货数量</td>                            <td class="tableContent"><input type="text" name="outnumber" /></td>                        </tr>                        <tr>                            <td class="columnTitle_mustbe">装率</td>                            <td class="tableContent"><input type="text" name="loadingrate" /></td>                                                        <td class="columnTitle_mustbe">箱数</td>                        <td class="tableContent"><input type="text" name="boxnum" /></td>                        </tr>                        <tr>                                <td class="columnTitle_mustbe">包装单位</td>                            <td class="tableContent"><input type="text" name="packingunit" /></td>                            <td class="columnTitle_mustbe">单价</td>                            <td class="tableContent"><input type="text" name="price" /></td>                                                    </tr>                            <tr>                                <td class="columnTitle_mustbe">总金额</td>                            <td class="tableContent"><input type="text" name="amount" /></td>                            <td class="columnTitle_mustbe">是否出货完毕</td>                            <td class="tableContent"><input type="text" name="finished" /></td>                                                    </tr>                            <tr>                                <td class="columnTitle_mustbe">附件</td>                            <td class="tableContent"><input type="text" name="exts" /></td>                            <td class="columnTitle_mustbe">排序号</td>                    <td class="tableContent"><input type="text" name="orderno" /></td>                                                    </tr>                    </table>                </div>            </div>    </form>                <div class="eXtremeTable" ><table id="ec_table" class="tableRegion" width="98%" >    <thead>    <tr>        <td class="tableHeader"><input type="checkbox" name="selid" onclick="checkAll(‘id‘,this)"></td>        <td class="tableHeader">厂家名称</td>        <td class="tableHeader">货号</td>        <td class="tableHeader">数量</td>        <td class="tableHeader">实际出货数量</td>        <td class="tableHeader">装率</td>        <td class="tableHeader">箱数</td>        <td class="tableHeader">包装单位</td>        <td class="tableHeader">单价</td>        <td class="tableHeader">总金额</td>        <td class="tableHeader">操作</td>    </tr>    </thead>            <tbody class="tableBody" >    <!--var="o"的意思是给datalist取个别名,之后用起来就简单了-->    <c:forEach items="${datalist}" var="o" varStatus="status">    <tr class="odd" onm ouseover="this.className=‘highlight‘" onm ouseout="this.className=‘odd‘" >    <!-- 做了一个选择框 -->        <td><input type="checkbox" name="id" value="${o.id}"/></td>        <td>${status.index+1}</td>                <td>${o.factoryname}</td>        <td>${o.productno}</td>         <td>${o.cnumber}</td>         <td>${o.outnumber}</td>         <td>${o.loadingrate}</td>         <td>${o.boxnum}</td>         <td>${o.packingunit}</td>         <td>${o.price}</td>         <td>${o.amount}</td>          <td>          <a href="${ctx}/cargo/contractproduct/update.action?id=${o.id}">[修改]</a>             <a href="${ctx}/cargo/contractproduct/deleteByid.action?id=${o.id}&contractId=${o.contractid}">[删除]</a>          </td>          </tr>    </c:forEach>        </tbody></table></div></body></html>

 

更新页面:

<%@ page language="java" pageEncoding="UTF-8"%><%@ include file="../../base.jsp"%><html xmlns="http://www.w3.org/1999/xhtml"><head><title></title><!-- 设置 id为factoryname的input的值--><script type="text/javascript">function setfactoryName(val){var ere=document.getElementById("factoryname");ere.value=val;}</script> <!--  <script type="text/javascript" src="http://www.mamicode.com/js/datepicker/WdatePicker.js"></script> --></head><body>    <form method="post">    <input text="text" name="contractid" value="${contractId}">            <div id="menubar">            <div id="middleMenubar">                <div id="innerMenubar">                    <div id="navMenubar">                        <ul>                            <li id="save"><a href="#"                                onclick="formSubmit(‘update.action‘,‘_self‘);">确定</a></li>                            <li id="back"><a href="list.action">返回</a></li>                        </ul>                    </div>                </div>            </div>        </div>        <div class="textbox" id="centerTextbox">            <div class="textbox-header">                <div class="textbox-inner-header">                    <div class="textbox-title">更新合同货物信息</div>                </div>            </div>            <div>                <div>                    <table class="commonTable" cellspacing="1">                        <tr>                            <td class="columnTitle_mustbe">厂家名称:</td>                            <td class="tableContent">                                                        <!-- <input type= name="factoryname" /> -->                            <!-- this.selectedIndex当前选中的索引值 -->                            <select  name="factoryid" onchange="setfactoryName(this.options[this.selectedIndex].text)">                            <option value="">--请选择--</option>                             <c:forEach items="${listfactory}" var="f">                               <option value="${f.id}">${f.factoryName }</option>                             </c:forEach>                           </select>                            <input  type="hidden" id="factoryname" name="factoryname">                            </td>                                                                                                                <td class="columnTitle_mustbe">货号</td>                            <td class="tableContent"><input type="text" name="productno" value=${ obj.productno}/></td>                        </tr>                        <tr>                            <td class="columnTitle_mustbe">货物照片</td>                            <td class="tableContent"><input type="text" name="productimage" value=${ obj.productimage}/></td>                            <td class="columnTitle_mustbe">货物描述</td>                            <td class="tableContent">                            <textarea name="productDesc" style="height:120px;">${ obj.productdesc}</textarea>                            </td>                        </tr>                        <tr>                            <td class="columnTitle_mustbe">数量</td>                            <td class="tableContent"><input type="text" name="cnumber" value=${ obj.cnumber}/></td>                            <td class="columnTitle_mustbe">实际出货数量</td>                            <td class="tableContent"><input type="text" name="outnumber" value=${ obj.outnumber}/></td>                        </tr>                        <tr>                            <td class="columnTitle_mustbe">装率</td>                            <td class="tableContent"><input type="text" name="loadingrate" value=${ obj.loadingrate}/></td>                                                        <td class="columnTitle_mustbe">箱数</td>                        <td class="tableContent"><input type="text" name="boxnum" value=${ obj.boxnum}/></td>                        </tr>                        <tr>                                <td class="columnTitle_mustbe">包装单位</td>                            <td class="tableContent"><input type="text" name="packingunit" value=${ obj.packingunit}/></td>                            <td class="columnTitle_mustbe">单价</td>                            <td class="tableContent"><input type="text" name="price" value=${ obj.price}/></td>                                                    </tr>                            <tr>                                <td class="columnTitle_mustbe">总金额</td>                            <td class="tableContent"><input type="text" name="amount" value=${ obj.amount}/></td>                            <td class="columnTitle_mustbe">是否出货完毕</td>                            <td class="tableContent"><input type="text" name="finished" value=${ obj.finished} /></td>                                                    </tr>                            <tr>                                <td class="columnTitle_mustbe">附件</td>                            <td class="tableContent"><input type="text" name="exts" value=${ obj.exts}/></td>                            <td class="columnTitle_mustbe">排序号</td>                    <td class="tableContent"><input type="text" name="orderno" value=${ obj.orderno}/></td>                        </tr>                    </table>                </div>            </div>    </form>            </body></html>

 

 

 

运行一切OK.

 

011杰信-创建购销合同Excel报表系列-3-建立合同货物(修改,删除):合同货物表是购销合同表的子表