オンライン試験システム(1) - 構築するためのシステムの開発環境

ディレクトリ

1.プロジェクトのアーキテクチャ

         1.1新しいプロジェクトの試験を作成します。

1.2関連するプロファイルとjarパッケージをインポート

2.ビルドキット


1.プロジェクトのアーキテクチャ

1.1新しいプロジェクトの試験を作成します。

プロジェクト型の動的Webプロジェクト、動的Webバージョン2.5。

 

1.2関連するプロファイルとjarパッケージをインポート

(srcディレクトリ内)の設定ファイルがあります:

hibernate.cfg.xmlの:

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>

    <session-factory>

        <!--数据库连接设置 -->
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="connection.url"><![CDATA[jdbc:mysql://localhost:3306/db_exam?useUnicode=true&characterEncoding=utf8]]></property>
        <property name="connection.username">root</property>
        <property name="connection.password">123456</property>

       
        <!-- 方言 -->
        <property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>

        <!-- 把session绑定到当前线程中 -->
        <property name="current_session_context_class">thread</property>

        <!-- 控制台显示SQL -->
        <property name="show_sql">true</property>

        <!-- 自动表更新 -->
        <property name="hbm2ddl.auto">update</property>
        
       
    </session-factory>

</hibernate-configuration>

struts.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
    "http://struts.apache.org/dtds/struts-2.3.dtd">

<struts>

	
	<package name="studentInfo" namespace="/" extends="struts-default">
		
		
		
	</package>
	

     
</struts>

また、設定ファイルを変更する必要がありますweb.xmlの支柱。 

web.xmlの:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>Exam</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  
  <filter>
        <filter-name>StrutsPrepareAndExecuteFilter</filter-name>
		<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
  </filter>
  <filter-mapping>
	   <filter-name>StrutsPrepareAndExecuteFilter</filter-name>
	   <url-pattern>/*</url-pattern>
  </filter-mapping>
</web-app>

(下のlibフォルダでWebコンテンツ上)が関連のjarパッケージ:

これらは、支柱のコアであり、そうでジャー・パッケージ、並びにMySQLのドライバパッケージを休止状態、及び、 

 

2.ビルドキット

 キットの確立com.java.utilを

そして、の設立HibernateUtilののツール:

package com.java.util;

import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;

public class HibernateUtil {

	//获取SessionFactory的方法
	private static SessionFactory buildSessionFactory(){
		//实例化配置文件
		Configuration configuration=new Configuration().configure();
		//实例化服务注册
		ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
		//获取session工厂
		return configuration.buildSessionFactory(serviceRegistry);
	}
	
	//设置静态字段
	private static final SessionFactory sessionFactory=buildSessionFactory();
	
	//获取当前的单例SessionFactory,提供对外的接口
	public static SessionFactory getSessionFactory(){
		return sessionFactory;
	}
	
	//测试是否成功
	public static void main(String[] args) {
		HibernateUtil.getSessionFactory();
	}
}

ここでは、データベース内のデータベースを構築しdb_examを進めたいです。

我々はそれを実行してテストすることができます。

これはHibernateUtilのは、首尾よく成功を構築するための環境を実行して表しています。

 

おすすめ

転載: blog.csdn.net/qq_37084904/article/details/89846049