資料字典的設計--1.首頁功能實現,字典--1

來源:互聯網
上載者:User

資料字典的設計--1.首頁功能實現,字典--1

  在項目開發中常常會看見一些下拉框選項,比如性別、人員學曆等等。這些都是通過資料字典表來維護的,即在資料庫建立一個資料字典表,將資料分類和詳細資料儲存在一張表中,實現無限極樹形節點,實現基於global的查詢。

 資料字典的作用:

 

資料庫的設計:

 

#資料字典CREATE TABLE Elec_SystemDDL(SeqID INT NOT NULL,          #主鍵ID(自增長)Keyword VARCHAR(20)   NULL,  #資料類型DdlCode INT  NULL,           #資料項目的codeDdlName VARCHAR(50)  NULL    #資料項目的value) 

 

建立相應JavaBean和xml對應檔:

  1.建立Elec_SystemDDL.java檔案

@SuppressWarnings("serial")public class ElecSytemDDL implements Serializable{    private Integer seqID;    private String keyword;    private Integer ddlCode;    private String ddlName;        public Integer getSeqID() {        return seqID;    }    public void setSeqID(Integer seqID) {        this.seqID = seqID;    }    public String getKeyword() {        return keyword;    }    public void setKeyword(String keyword) {        this.keyword = keyword;    }    public Integer getDdlCode() {        return ddlCode;    }    public void setDdlCode(Integer ddlCode) {        this.ddlCode = ddlCode;    }    public String getDdlName() {        return ddlName;    }    public void setDdlName(String ddlName) {        this.ddlName = ddlName;    }    }

  2.建立對應的hbm.xml檔案 ElecSystemDDL.hbm.xml

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE hibernate-mapping PUBLIC     "-//Hibernate/Hibernate Mapping DTD 3.0//EN"    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"><hibernate-mapping package="cn.elec.domain"><class name="ElecSystemDDL" table="Elec_SystemDDL"><id name="seqID" type="integer" column="seqID"><generator class="increment"></generator></id><property name="keyword" type="string" column="keyword"></property><property name="ddlCode" type="integer" column="ddlCode"></property><property name="ddlName" type="string" column="ddlName"></property></class></hibernate-mapping>

  3.在hibernate.cfg.xml檔案中添加:

<mapping resource="ElecSystemDDL.hbm.xml檔案路徑名"/>

 

建立DAO介面及其實作類別:

  1.建立DAO介面: IElecSystemDDLDao.java

public interface IElecSystemDDLDao extends ICommonDao<ElecSystemDDL> {public static final String SERVICE_NAME="cn.elec.dao.imp.ElecSystemDDLImpl";}

  2.建立實作類別:ElecSystemDDLDaoImpl.java

/** * @Repository * 相當於在spring中定義:<bean id="elecTextDaoImpl" class="com. **.ElecTextDaoImpl"> */@Repository(IElecSystemDDLDao.SERVICE_NAME)public class ElecSystemDDLDaoImpl extends CommonDaoImpl<ElecSystemDDL> implements IElecSystemDDLDao{}

 

建立Service介面及實作類別:

  1.建立Service介面:IElecSystemDDLService.java

public interface IElecSystemDDLService {    public static final String SERVICE_NAME="com.elec.service.impl.ElecSystemDDLServiceImpl";}

  2.建立實作類別:ElecSystemDDLServiceImpl.java

//事務控制:spring的聲明交易處理,在service層添加@Transactional@Service(IElecSystemDDLService.SERVICE_NAME)@Transactional(readOnly=true)public class ElecSystemDDLServiceImpl implements IElecSystemDDLService {    /*資料字典Dao*/    @Resource(name=IElecSystemDDLDao.SERVICE_NAME)    IElecSystemDDLDao elecSystemDDLDao;}

 

建立Action類:ElecSystemDDLAction.java

public class ElecSystemDDLAction extends BaseAction<ElecSystemDDL>{ElecSystemDDL elecSystemDDL=this.getModel();//注入資料字典service@Resource(name=IElecSystemDDLService.SERVICE_NAME)IElecSystemDDLService elecSystemDDLService;/**  * @Name: home* @Description: 跳轉到資料字典頁面*  @Parameters: 無* @Return: String:跳轉到system/dictionaryIndex.jsp*/public String home(){  return "home";}}

  其中BaseAction是對泛型執行個體化方法進行封裝的類。

 

配置struts.xml:

<action name="elecSystemDDLAction_*" class="elecSystemDDLAction" method="{1}">       <result name="home">/WEB-INF/page/system/dictionaryIndex.jsp</result>
</action>

 

修改script/menuDate.js中的url:

{            mid:'aq',            pid:'am',            name:'資料字典維護',            icon:'../images/MenuIcon/shujuzidianguanli.gif',            target:'mainFrame',            /*url:'../system/dictionaryIndex.jsp',*/            url:'../system/elecSystemDDLAction_home.do',            isParent:false}

啟動Tomcat伺服器,頁面展示:

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.