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

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

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

    甜咖啡

    我的IT空間

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

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

    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 復(fù)合為一個主鍵

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

    Custrich.java   內(nèi)容如下

    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  內(nèi)容如下:

    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方法是用來控制主鍵內(nèi)容不能為空和不能重復(fù)的。

    3.Custrich.hbm.xml的配置內(nèi)容為:

    <?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中設(shè)置的數(shù)據(jù)庫查詢結(jié)果集,這里就不詳述啦

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


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


    網(wǎng)站導(dǎo)航:
     

    導(dǎo)航

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

    統(tǒng)計

    常用鏈接

    留言簿(1)

    我參與的團隊

    隨筆檔案

    搜索

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 亚洲毛片αv无线播放一区| 国产免费一区二区视频| 欧美日韩国产免费一区二区三区| 亚洲电影一区二区三区| 两个人看的www高清免费视频| 国产精品xxxx国产喷水亚洲国产精品无码久久一区 | 亚洲欧洲日本在线观看| 国产一卡2卡3卡4卡无卡免费视频| 亚洲欧洲中文日产| 亚洲AV美女一区二区三区| 国产免费一区二区视频| 亚洲综合一区二区精品久久| 日本zzzzwww大片免费| 涩涩色中文综合亚洲| 国产精品嫩草影院免费| 国产成人高清亚洲一区久久| 亚洲精品国产福利一二区| a级毛片免费播放| 亚洲福利一区二区三区| 大学生高清一级毛片免费| 免费亚洲视频在线观看| 自拍偷自拍亚洲精品情侣| 久久免费观看国产精品| 国产成人精品日本亚洲专| 免费在线观看黄色毛片| 精品国产麻豆免费人成网站| 亚洲性色高清完整版在线观看| 国产高清视频在线免费观看| 国产vA免费精品高清在线观看| 亚洲av丰满熟妇在线播放| 成年在线网站免费观看无广告 | 亚洲区小说区图片区QVOD| xxxx日本免费| 美国免费高清一级毛片| 无码乱人伦一区二区亚洲一 | 亚洲偷自拍拍综合网| 最近2019免费中文字幕6| 亚洲av综合日韩| 久久久国产精品亚洲一区| 午夜男人一级毛片免费 | 一级一看免费完整版毛片|