<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    甜咖啡

    我的IT空間

    hibernate對于復合主鍵映射后 jsp中如何使用復合主鍵

    剛接觸java的ssh框架,有很多東西都不了解,最近遇到復合主鍵的問題,不知道在前臺jsp頁面中如何調用復合主鍵,網上查到了一篇博文(http://blog.csdn.net/ttaaoo36/archive/2010/07/26/5766810.aspx)解決了這個問題,現在也把我的內容貼出來。

    1.oracle中建表語句

    drop table CUSTRICH cascade constraints;

    /*==============================================================*/
    /* Table: CUSTRICH                                              */
    /*==============================================================*/
    create table CUSTRICH  (
       BRANCH_NO            CHAR(10)                        not null,
       YYYYMM               DATE                            not null,
       CNY_BAL              NUMBER,
       NONCNY_BAL           NUMBER,
       LOAN_TOT_CNY         NUMBER,
       LOAN_TOT_NONCNY      NUMBER,
       RICH_BALCASHUNIT     NUMBER,
       BDF10FR_TOT_BAL      NUMBER,
       FOUND_TOT            NUMBER,
       INSURANCEFEEAMT      NUMBER,
       CD03_CURR_BAL        NUMBER,
       FN1TON_COUNT         NUMBER,
       FNSETPLN_COUNT       NUMBER,
       TPCCACCBAL           NUMBER,
       APPLICATION_ID       NUMBER,
       JGDM                 NUMBER,
       ZCRMBHJ              NUMBER,
       "Reserve1"           NUMBER,
       ASSET_TOT_CNY        NUMBER,
       "Reserve3"           NUMBER,
       "Reserve4"           NUMBER,
       "Reserve5"           NUMBER,
       "Reserve6"           NUMBER,
       "Reserve7"           NUMBER,
       "Reserve8"           NUMBER,
       "Reserve9"           NUMBER,
       "Reserve10"          NUMBER,
       constraint PK_CUSTRICH primary key (BRANCH_NO, YYYYMM)
    );

    兩個字段branch_no 和yyyymm 復合為一個主鍵

    2. hibernate映射為兩個java類文件  :Custrich.java和 CustrichId.java

    Custrich.java   內容如下

    package com.hljzr.bean;

    import java.math.BigDecimal;

    /**
     * Custrich entity. @author MyEclipse Persistence Tools
     */

    public class Custrich implements java.io.Serializable {

     // Fields

     private CustrichId id;
     private BigDecimal cnyBal;
     private BigDecimal noncnyBal;
     private BigDecimal loanTotCny;
     private BigDecimal loanTotNoncny;
     private BigDecimal richBalcashunit;
     private BigDecimal bdf10frTotBal;
     private BigDecimal foundTot;
     private BigDecimal insurancefeeamt;
     private BigDecimal cd03CurrBal;
     private BigDecimal fn1tonCount;
     private BigDecimal fnsetplnCount;
     private BigDecimal tpccaccbal;
     private BigDecimal applicationId;
     private BigDecimal jgdm;
     private BigDecimal zcrmbhj;
     private BigDecimal reserve1;
     private BigDecimal assetTotCny;
     private BigDecimal reserve3;
     private BigDecimal reserve4;
     private BigDecimal reserve5;
     private BigDecimal reserve6;
     private BigDecimal reserve7;
     private BigDecimal reserve8;
     private BigDecimal reserve9;
     private BigDecimal reserve10;

     // Constructors

     /** default constructor */
     public Custrich() {
     }

     /** minimal constructor */
     public Custrich(CustrichId id) {
      this.id = id;
     }

     /** full constructor */
     public Custrich(CustrichId id, BigDecimal cnyBal, BigDecimal noncnyBal,
       BigDecimal loanTotCny, BigDecimal loanTotNoncny,
       BigDecimal richBalcashunit, BigDecimal bdf10frTotBal,
       BigDecimal foundTot, BigDecimal insurancefeeamt,
       BigDecimal cd03CurrBal, BigDecimal fn1tonCount,
       BigDecimal fnsetplnCount, BigDecimal tpccaccbal,
       BigDecimal applicationId, BigDecimal jgdm, BigDecimal zcrmbhj,
       BigDecimal reserve1, BigDecimal assetTotCny, BigDecimal reserve3,
       BigDecimal reserve4, BigDecimal reserve5, BigDecimal reserve6,
       BigDecimal reserve7, BigDecimal reserve8, BigDecimal reserve9,
       BigDecimal reserve10) {
      this.id = id;
      this.cnyBal = cnyBal;
      this.noncnyBal = noncnyBal;
      this.loanTotCny = loanTotCny;
      this.loanTotNoncny = loanTotNoncny;
      this.richBalcashunit = richBalcashunit;
      this.bdf10frTotBal = bdf10frTotBal;
      this.foundTot = foundTot;
      this.insurancefeeamt = insurancefeeamt;
      this.cd03CurrBal = cd03CurrBal;
      this.fn1tonCount = fn1tonCount;
      this.fnsetplnCount = fnsetplnCount;
      this.tpccaccbal = tpccaccbal;
      this.applicationId = applicationId;
      this.jgdm = jgdm;
      this.zcrmbhj = zcrmbhj;
      this.reserve1 = reserve1;
      this.assetTotCny = assetTotCny;
      this.reserve3 = reserve3;
      this.reserve4 = reserve4;
      this.reserve5 = reserve5;
      this.reserve6 = reserve6;
      this.reserve7 = reserve7;
      this.reserve8 = reserve8;
      this.reserve9 = reserve9;
      this.reserve10 = reserve10;
     }

     // Property accessors

     public CustrichId getId() {
      return this.id;
     }

     public void setId(CustrichId id) {
      this.id = id;
     }

     public BigDecimal getCnyBal() {
      return this.cnyBal;
     }

     public void setCnyBal(BigDecimal cnyBal) {
      this.cnyBal = cnyBal;
     }

     public BigDecimal getNoncnyBal() {
      return this.noncnyBal;
     }

     public void setNoncnyBal(BigDecimal noncnyBal) {
      this.noncnyBal = noncnyBal;
     }

     public BigDecimal getLoanTotCny() {
      return this.loanTotCny;
     }

     public void setLoanTotCny(BigDecimal loanTotCny) {
      this.loanTotCny = loanTotCny;
     }

     public BigDecimal getLoanTotNoncny() {
      return this.loanTotNoncny;
     }

     public void setLoanTotNoncny(BigDecimal loanTotNoncny) {
      this.loanTotNoncny = loanTotNoncny;
     }

     public BigDecimal getRichBalcashunit() {
      return this.richBalcashunit;
     }

     public void setRichBalcashunit(BigDecimal richBalcashunit) {
      this.richBalcashunit = richBalcashunit;
     }

     public BigDecimal getBdf10frTotBal() {
      return this.bdf10frTotBal;
     }

     public void setBdf10frTotBal(BigDecimal bdf10frTotBal) {
      this.bdf10frTotBal = bdf10frTotBal;
     }

     public BigDecimal getFoundTot() {
      return this.foundTot;
     }

     public void setFoundTot(BigDecimal foundTot) {
      this.foundTot = foundTot;
     }

     public BigDecimal getInsurancefeeamt() {
      return this.insurancefeeamt;
     }

     public void setInsurancefeeamt(BigDecimal insurancefeeamt) {
      this.insurancefeeamt = insurancefeeamt;
     }

     public BigDecimal getCd03CurrBal() {
      return this.cd03CurrBal;
     }

     public void setCd03CurrBal(BigDecimal cd03CurrBal) {
      this.cd03CurrBal = cd03CurrBal;
     }

     public BigDecimal getFn1tonCount() {
      return this.fn1tonCount;
     }

     public void setFn1tonCount(BigDecimal fn1tonCount) {
      this.fn1tonCount = fn1tonCount;
     }

     public BigDecimal getFnsetplnCount() {
      return this.fnsetplnCount;
     }

     public void setFnsetplnCount(BigDecimal fnsetplnCount) {
      this.fnsetplnCount = fnsetplnCount;
     }

     public BigDecimal getTpccaccbal() {
      return this.tpccaccbal;
     }

     public void setTpccaccbal(BigDecimal tpccaccbal) {
      this.tpccaccbal = tpccaccbal;
     }

     public BigDecimal getApplicationId() {
      return this.applicationId;
     }

     public void setApplicationId(BigDecimal applicationId) {
      this.applicationId = applicationId;
     }

     public BigDecimal getJgdm() {
      return this.jgdm;
     }

     public void setJgdm(BigDecimal jgdm) {
      this.jgdm = jgdm;
     }

     public BigDecimal getZcrmbhj() {
      return this.zcrmbhj;
     }

     public void setZcrmbhj(BigDecimal zcrmbhj) {
      this.zcrmbhj = zcrmbhj;
     }

     public BigDecimal getReserve1() {
      return this.reserve1;
     }

     public void setReserve1(BigDecimal reserve1) {
      this.reserve1 = reserve1;
     }

     public BigDecimal getAssetTotCny() {
      return this.assetTotCny;
     }

     public void setAssetTotCny(BigDecimal assetTotCny) {
      this.assetTotCny = assetTotCny;
     }

     public BigDecimal getReserve3() {
      return this.reserve3;
     }

     public void setReserve3(BigDecimal reserve3) {
      this.reserve3 = reserve3;
     }

     public BigDecimal getReserve4() {
      return this.reserve4;
     }

     public void setReserve4(BigDecimal reserve4) {
      this.reserve4 = reserve4;
     }

     public BigDecimal getReserve5() {
      return this.reserve5;
     }

     public void setReserve5(BigDecimal reserve5) {
      this.reserve5 = reserve5;
     }

     public BigDecimal getReserve6() {
      return this.reserve6;
     }

     public void setReserve6(BigDecimal reserve6) {
      this.reserve6 = reserve6;
     }

     public BigDecimal getReserve7() {
      return this.reserve7;
     }

     public void setReserve7(BigDecimal reserve7) {
      this.reserve7 = reserve7;
     }

     public BigDecimal getReserve8() {
      return this.reserve8;
     }

     public void setReserve8(BigDecimal reserve8) {
      this.reserve8 = reserve8;
     }

     public BigDecimal getReserve9() {
      return this.reserve9;
     }

     public void setReserve9(BigDecimal reserve9) {
      this.reserve9 = reserve9;
     }

     public BigDecimal getReserve10() {
      return this.reserve10;
     }

     public void setReserve10(BigDecimal reserve10) {
      this.reserve10 = reserve10;
     }

    }

    CustrichId.java  內容如下:

    package com.hljzr.bean;

    import java.util.Date;

    /**
     * CustrichId entity. @author MyEclipse Persistence Tools
     */

    public class CustrichId implements java.io.Serializable {

     // Fields

     private String branchNo;
     private Date yyyymm;

     // Constructors

     /** default constructor */
     public CustrichId() {
     }

     /** full constructor */
     public CustrichId(String branchNo, Date yyyymm) {
      this.branchNo = branchNo;
      this.yyyymm = yyyymm;
     }

     // Property accessors

     public String getBranchNo() {
      return this.branchNo;
     }

     public void setBranchNo(String branchNo) {
      this.branchNo = branchNo;
     }

     public Date getYyyymm() {
      return this.yyyymm;
     }

     public void setYyyymm(Date yyyymm) {
      this.yyyymm = yyyymm;
     }

     public boolean equals(Object other) {
      if ((this == other))
       return true;
      if ((other == null))
       return false;
      if (!(other instanceof CustrichId))
       return false;
      CustrichId castOther = (CustrichId) other;

      return ((this.getBranchNo() == castOther.getBranchNo()) || (this
        .getBranchNo() != null
        && castOther.getBranchNo() != null && this.getBranchNo()
        .equals(castOther.getBranchNo())))
        && ((this.getYyyymm() == castOther.getYyyymm()) || (this
          .getYyyymm() != null
          && castOther.getYyyymm() != null && this.getYyyymm()
          .equals(castOther.getYyyymm())));
     }

     public int hashCode() {
      int result = 17;

      result = 37 * result
        + (getBranchNo() == null ? 0 : this.getBranchNo().hashCode());
      result = 37 * result
        + (getYyyymm() == null ? 0 : this.getYyyymm().hashCode());
      return result;
     }

    }

    hashCode和equals方法是用來控制主鍵內容不能為空和不能重復的。

    3.Custrich.hbm.xml的配置內容為:

    <?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    " <!--
        Mapping file autogenerated by MyEclipse Persistence Tools
    -->
    <hibernate-mapping>
        <class name="com.hljzr.bean.Custrich" table="CUSTRICH" schema="YHXM">
            <composite-id name="id" class="com.hljzr.bean.CustrichId">
                <key-property name="branchNo" type="java.lang.String">
                    <column name="BRANCH_NO" length="10" />
                </key-property>
                <key-property name="yyyymm" type="java.util.Date">
                    <column name="YYYYMM" length="7" />
                </key-property>
            </composite-id>
            <property name="cnyBal" type="java.math.BigDecimal">
                <column name="CNY_BAL" precision="22" scale="0" />
            </property>
            <property name="noncnyBal" type="java.math.BigDecimal">
                <column name="NONCNY_BAL" precision="22" scale="0" />
            </property>
            <property name="loanTotCny" type="java.math.BigDecimal">
                <column name="LOAN_TOT_CNY" precision="22" scale="0" />
            </property>
            <property name="loanTotNoncny" type="java.math.BigDecimal">
                <column name="LOAN_TOT_NONCNY" precision="22" scale="0" />
            </property>
            <property name="richBalcashunit" type="java.math.BigDecimal">
                <column name="RICH_BALCASHUNIT" precision="22" scale="0" />
            </property>
            <property name="bdf10frTotBal" type="java.math.BigDecimal">
                <column name="BDF10FR_TOT_BAL" precision="22" scale="0" />
            </property>
            <property name="foundTot" type="java.math.BigDecimal">
                <column name="FOUND_TOT" precision="22" scale="0" />
            </property>
            <property name="insurancefeeamt" type="java.math.BigDecimal">
                <column name="INSURANCEFEEAMT" precision="22" scale="0" />
            </property>
            <property name="cd03CurrBal" type="java.math.BigDecimal">
                <column name="CD03_CURR_BAL" precision="22" scale="0" />
            </property>
            <property name="fn1tonCount" type="java.math.BigDecimal">
                <column name="FN1TON_COUNT" precision="22" scale="0" />
            </property>
            <property name="fnsetplnCount" type="java.math.BigDecimal">
                <column name="FNSETPLN_COUNT" precision="22" scale="0" />
            </property>
            <property name="tpccaccbal" type="java.math.BigDecimal">
                <column name="TPCCACCBAL" precision="22" scale="0" />
            </property>
            <property name="applicationId" type="java.math.BigDecimal">
                <column name="APPLICATION_ID" precision="22" scale="0" />
            </property>
            <property name="jgdm" type="java.math.BigDecimal">
                <column name="JGDM" precision="22" scale="0" />
            </property>
            <property name="zcrmbhj" type="java.math.BigDecimal">
                <column name="ZCRMBHJ" precision="22" scale="0" />
            </property>
            <property name="reserve1" type="java.math.BigDecimal">
                <column name="RESERVE1" precision="22" scale="0" />
            </property>
            <property name="assetTotCny" type="java.math.BigDecimal">
                <column name="ASSET_TOT_CNY" precision="22" scale="0" />
            </property>
            <property name="reserve3" type="java.math.BigDecimal">
                <column name="RESERVE3" precision="22" scale="0" />
            </property>
            <property name="reserve4" type="java.math.BigDecimal">
                <column name="RESERVE4" precision="22" scale="0" />
            </property>
            <property name="reserve5" type="java.math.BigDecimal">
                <column name="RESERVE5" precision="22" scale="0" />
            </property>
            <property name="reserve6" type="java.math.BigDecimal">
                <column name="RESERVE6" precision="22" scale="0" />
            </property>
            <property name="reserve7" type="java.math.BigDecimal">
                <column name="RESERVE7" precision="22" scale="0" />
            </property>
            <property name="reserve8" type="java.math.BigDecimal">
                <column name="RESERVE8" precision="22" scale="0" />
            </property>
            <property name="reserve9" type="java.math.BigDecimal">
                <column name="RESERVE9" precision="22" scale="0" />
            </property>
            <property name="reserve10" type="java.math.BigDecimal">
                <column name="RESERVE10" precision="22" scale="0" />
            </property>
        </class>
    </hibernate-mapping>
    4.在配置文件applicationContext-common.xml中mapping上面的映射文件

    <property name="mappingResources">
       <list>
        <value>com/hljzr/bean/Custrich.hbm.xml</value>
       </list>
      </property>
    5.在前臺jsp頁面中

     <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

        <c:if test="${!empty pm.list}">
         <c:set var = "sum" value = "0" />
        <c:forEach items="${pm.list}" var="cus">
         <tr>
          <td>
           ${cus.id.branchNo}    <!--如果寫成cus.branchNo就不對了-->
          </td>
          <td>
           ${cus.id.yyyymm}
          </td>
          <td>
           ${cus.insurancefeeamt}
          </td>
          <td>
           ${cus.foundTot}
          </td>
          <td>
           ${cus.foundTot}
          </td>
          <td>
           ${cus.foundTot}
          </td>
         </tr>
         <c:set value="${sum+cus.foundTot}" var="sum" />
        </c:forEach>
       </c:if>

    這里的pm是在action中設置的數據庫查詢結果集,這里就不詳述啦

    posted on 2011-03-26 23:38 甜咖啡 閱讀(579) 評論(0)  編輯  收藏


    只有注冊用戶登錄后才能發表評論。


    網站導航:
     

    導航

    <2011年3月>
    272812345
    6789101112
    13141516171819
    20212223242526
    272829303112
    3456789

    統計

    常用鏈接

    留言簿(1)

    我參與的團隊

    隨筆檔案

    搜索

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 免费A级毛片在线播放| 成年男女男精品免费视频网站| 成a人片亚洲日本久久| 久久综合久久综合亚洲| 亚洲av日韩专区在线观看| 亚洲精品偷拍视频免费观看| 在线播放免费人成毛片乱码| 91免费精品国自产拍在线不卡| 国产精品色午夜视频免费看| 亚洲国产日韩在线视频| 亚洲mv国产精品mv日本mv| 国产亚洲女在线线精品| 91av免费观看| 亚洲国产精品成人一区| 伊人久久综在合线亚洲2019| 337P日本欧洲亚洲大胆精品| 免费大香伊蕉在人线国产| 亚洲男女内射在线播放| 亚洲国产精品白丝在线观看| 又粗又长又爽又长黄免费视频| 久久久久高潮毛片免费全部播放| 亚洲综合激情九月婷婷| 国产免费无码一区二区| 国产青草视频免费观看97| 日韩在线视频免费| 337p日本欧洲亚洲大胆裸体艺术 | 大地资源网高清在线观看免费| 亚洲精品成人片在线播放| 永久在线免费观看| 亚洲真人日本在线| 老司机午夜免费视频| 99久久免费国产精品特黄| 亚洲国产aⅴ成人精品无吗| 16女性下面扒开无遮挡免费| 亚洲一卡二卡三卡四卡无卡麻豆| 国产一级淫片免费播放| 免费av片在线观看网站| 亚洲国产欧美一区二区三区| 亚洲精品无码Av人在线观看国产| 在线a免费观看最新网站| 日本永久免费a∨在线视频|