<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高清免费波多| 亚洲国产精品人人做人人爱| 一区二区三区免费视频网站 | 久久久久亚洲Av片无码v| 国产免费内射又粗又爽密桃视频| 国产亚洲日韩在线三区| 日韩电影免费在线观看网站| 亚洲AV无码久久精品成人| 久久国产色AV免费看| 亚洲国产成人在线视频| 成人人免费夜夜视频观看| 337P日本欧洲亚洲大胆艺术图 | 久久久高清免费视频| 亚洲一区免费视频| 国产在线98福利播放视频免费 | 四虎影视成人永久免费观看视频| 亚洲色欲或者高潮影院| 青青青青青青久久久免费观看| 深夜A级毛片视频免费| 久久被窝电影亚洲爽爽爽| 24小时日本电影免费看| 亚洲精品无码专区| 国产成人A亚洲精V品无码| 一级毛片免费不卡在线| 中文有码亚洲制服av片| 亚洲人成国产精品无码| 国产精品成人观看视频免费| 日韩在线视频免费| 亚洲中文字幕无码av在线| 亚洲成?v人片天堂网无码| 99视频免费播放| 美女扒开屁股让男人桶爽免费|