JEECMS의 Entity 및 Dao 구성 프로세스

4361 단어
1.com.jeecms.cms.entity.member 쓰기 엔티티 클래스Portlet.java*는 기본 구조 함수를 포함해야 합니다
package com.jeecms.cms.entity.member;

public class Portlet {

    private Integer id;
    private String name;
    private String url;
    private String mark;

    public Portlet () {
       super();
    }

    public Portlet(int id,String name,String url,String mark){

       this.id=id;
       this.name=name;
       this.url=url;
       this.mark = mark;
    }

    //  get/set
}

2.com.jeecms.cms.entity.member.hbm에서 대응하는hibernate 프로필Portlet을 씁니다.hbm.xml
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="com.jeecms.cms.entity.member">
    <class name="Portlet" table="jc_portlet">
       <meta attribute="sync-DAO">false</meta>
       <id name="id" type="java.lang.Integer" column="portlet_id"><generator class="assigned"/></id>
       <property name="name" column="name" type="string" not-null="false" length="255"/>
       <property name="url" column="url" type="string" not-null="false" length="255"/>
       <property name="mark" column="mark" type="string" not-null="false" length="255"/>
    </class>

</hibernate-mapping>

3.com.jeecms.cms.dao.member 쓰기 DAO 클래스PortletDao.java,hibernate DAO 기본 클래스를 계승하는 HibernateBaseDao
package com.jeecms.cms.dao.member;

import java.util.ArrayList;
import java.util.List;
import com.jeecms.cms.entity.member.Portlet;
import com.jeecms.common.hibernate3.HibernateBaseDao;

public class PortletDao extends HibernateBaseDao<Portlet, Integer>{     

       //  portlet       

public List<Portlet> getPortletList(String potletIdStr, int iid){

       System.out.println("PortletDao:"+potletIdStr);
       List<Portlet> portlets=new ArrayList<Portlet>();
       String[] pids = potletIdStr.split(";");
       String[] mpids=pids[iid].split(",");

       for(String mpid : mpids){

           if(!mpid.equals("")){
              Portlet p = findById(Integer.parseInt(mpid));
              System.out.println(p.getName());
              portlets.add(p);
           }
       }
       return portlets;
    }

    public Portlet findById(Integer id){
       Portlet entity = get(id);
       return entity;
    }

    public Portlet save(Portlet p){
       getSession().save(p);
       return p;
    }

public Portlet deleteById(Integer id){

       Portlet entity = super.get(id);
       if (entity != null) {
           getSession().delete(entity);
       }
       return entity;

    }

    @Override

    protected Class<Portlet> getEntityClass() {
       return Portlet.class;
    }

}

4. 만약.hbm.xml 패키지는 응용 프로그램-context에서 새로 만듭니다.xml에 새 설정
<property name="mappingLocations">

<list>
<value>classpath*:/com/jeecms/core/entity/hbm/*.hbm.xml</value>
<value>classpath*:/com/jeecms/cms/entity/main/hbm/*.hbm.xml</value>
<value>classpath*:/com/jeecms/cms/entity/assist/hbm/*.hbm.xml</value>
<value>classpath*:/com/jeecms/cms/entity/member/hbm/*.hbm.xml</value>
</list>

</property>

5.jeecms-context에서xml 구성 DAO 클래스 객체
<bean id="portletDao" class="com.jeecms.cms.dao.member.PortletDao"/>

6.
필요한 경우
DAO
클래스 대상의 위치, 탭을 사용하여 자동으로 불러오기
@Autowired
PortletDao portletDao;

좋은 웹페이지 즐겨찾기