当前位置: 首页 > 工具软件 > Dorado7 > 使用案例 >

dorado 7 数据库配置

葛胡媚
2023-12-01

dorado 7数据配置

前端是通过model生成的datatype调用数据库,后台是调用dao进行数据库增删修改。
dorado 7 是采取SpringMVC+hibernate模式,数据库连接是基于hibernate方法,内部封装一些配置方法,使其配置方法简化。
数据配置必需要有对应的jdbc文件引入对应包MySQL的jdbc文件包下载地址

第一步:新建dbtool文件
第二步:dbtool文件 右键选择import数据库
第三步:dbtool文件右键选择javaBean文件到entity实体中,
第四步:新建Dao文件
第五步:配置appcontext 添加(以MySQL为例)

<context:component-scan base-package="基础包名" />

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
        destroy-method="close">
        <property name="driverClassName" value="${jdbc.driver}" />
        <property name="url"
            value="jdbc:mysql:${jdbc.url}?useUnicode=true&amp;characterEncoding=utf8" />
        <property name="username" value="${jdbc.userName}" />
        <property name="password" value="${jdbc.password}" />
        <property name="minIdle" value="${jdbc.minIdle}" />
        <property name="maxActive" value="${jdbc.maxActive}" />
    </bean>

    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="entityInterceptor" ref="dorado.unByteCodeProxyInterceptor" />
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">${hibernate.dialect}</prop>
                <prop key="hibernate.show_sql">${hibernate.showSql}</prop>
                <prop key="hibernate.format_sql">${hibernate.formatSql}</prop>
            </props>
        </property>
        <property name="packagesToScan">
            <list>
                <value>com/***/entity(实体所在包名路径)</value>
            </list>
        </property>
    </bean>

    <bean id="transactionManager"
        class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>
    <tx:annotation-driven transaction-manager="transactionManager"
        proxy-target-class="true" />

configure.properties添加配置

#数据库配置信息
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=//localhost:3306/表名
jdbc.userName=账号
jdbc.password=密码
jdbc.minIdle=10
jdbc.maxActive=50

hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
hibernate.showSql=true
hibernate.formatSql=true

第七步 修改web.xml

 <?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <listener>
            <listener-class>com.bstek.dorado.web.servlet.SpringContextLoaderListener</listener-class>
    </listener>
    <filter>
        <filter-name>OpenSessionInViewFilter</filter-name>  
                <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
        <init-param>
            <param-name>excludeSuffixs</param-name>
            <param-value>js,css,jpg,gif,png</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>OpenSessionInViewFilter</filter-name>
        <url-pattern>*.d</url-pattern>
    </filter-mapping>
    <filter-mapping>
        <filter-name>OpenSessionInViewFilter</filter-name>
        <url-pattern>/dorado/*</url-pattern>
    </filter-mapping>
    <servlet>
        <servlet-name>doradoServlet</servlet-name>
        <servlet-class>com.bstek.dorado.web.servlet.DoradoServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>doradoServlet</servlet-name>
        <url-pattern>*.d</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>doradoServlet</servlet-name>
        <url-pattern>*.dpkg</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>doradoServlet</servlet-name>
        <url-pattern>/dorado/*</url-pattern>
    </servlet-mapping>
</web-app>

第八步 准备model
注意 :model的包名要和配置里面信息一致

参考:

官方案例说明:http://wiki.bsdn.org/pages/viewpage.action?pageId=43909432

 类似资料: