1. 程式人生 > >電力項目十五--數據字典

電力項目十五--數據字典

clas true bsp 配置 for source interface read -i

數據字典的作用:

1.貫穿系統的所有數據項,開發過程中,動態的維護系統數據項:

2.保證數據的錄入安全,業務表使用數據字典的時候,存放的是數據項的編號,而不是數據項的值。

3.方便系統的統計。

1.數據庫的設計:

#數據字典

create table Elec_SystemDDL(

  seqID INT NOT NULL primary key, #主鍵ID(自增長)

  keyword VARCHAR(20) NULL, #數據類型

  ddlCode INT NULL, #數據項的code

  ddlName VARCHAR(50) NULL #數據項的value

);

創建Elec_SystemDDL.java文件

package com.itheima.elec.bean;

import java.io.Serializable;

@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; } }

創建對應的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>
        <class name="com.itheima.elec.bean.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>
    

然後在hibernate.cfg.xml文件中添加文件

    <mapping resource="com/itheima/elec/bean/ElecSystemDDL.hbm.xml"/>

IElecSystemDDL.java

package com.itheima.elec.dao;

import com.itheima.elec.bean.ElecSystemDDL;

public interface IElecSystemDDLDao extends ICommonDao<ElecSystemDDL> {
    public static final String SERVICE_NAME = "com.itheima.elec.dao.impl.ElecSystemDDLDaoImpl";

    
}

ElecSystemDDLDaoImpl.java

package com.itheima.elec.dao.impl;
import org.springframework.stereotype.Repository;

import com.itheima.elec.bean.ElecSystemDDL;
import com.itheima.elec.dao.IElecSystemDDLDao;

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

}

IElecSystemDDLService.java

package com.itheima.elec.service;

import java.util.List;

import com.itheima.elec.bean.ElecSystemDDL;

public interface IElecSystemDDLService {

    public static final String SERVICE_NAME="com.itheima.elec.service.impl.ElecSystemDDLServiceImpl";
}

ElecSystemDDLServiceImpl.java

package com.itheima.elec.service.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.itheima.elec.dao.IElecSystemDDLDao;
import com.itheima.elec.service.IElecSystemDDLService;
//事務控制:spring的聲明事務處理,[email protected]
@Service(IElecSystemDDLService.SERVICE_NAME)
@Transactional(readOnly=true)
public class ElecSystemDDLServiceImpl implements IElecSystemDDLService {

    /*數據字典Dao*/
    @Resource(name=IElecSystemDDLDao.SERVICE_NAME)
    IElecSystemDDLDao elecSystemDDLDao;


}

ElecSystemDDLAction.java

package com.itheima.elec.web.action;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.itheima.elec.bean.ElecSystemDDL;
import com.itheima.elec.service.IElecSystemDDLService;
import com.itheima.elec.service.IElecTextService;

@SuppressWarnings("serial")
@Controller("elecSystemDDLAction")
@Scope(value="prototype")
public class ElecSystemDDLAction extends BaseAction<ElecSystemDDL>{

    ElecSystemDDL elecSystemDDL = this.getModel();
    
    //註入Service
    @Resource(name=IElecSystemDDLService.SERVICE_NAME)
    IElecSystemDDLService elecSystemDDLService;
    
/**
 * 數據字典的首頁顯示
 * 跳轉到:/system/dictionIndex.jsp頁面
 */
public String home(){
    return "home";
}

}

struts.xml

<action name="elecSystemDDLAction_*" class="elecSystemDDLAction" method="{1}">
                <result name="home">/WEB-INF/page/system/dictionaryIndex.jsp</result>
                <result name="save" type="redirectAction">
                    <param name="actionName">elecCommonMsgAction_home.do</param>
                </result>
                <result name="actingView">/WEB-INF/page/system/actingView.jsp</result>
        </action>

寫完了dao,service,action,然後配置struts.xml

然後修改script/menuDate.js中的配置

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

啟動,頁面顯示:

技術分享

電力項目十五--數據字典