OA项目1:环境搭建之数据库创建与环境添加
首注:本学习教程为 传智播客汤阳光 一 指定数据库:Mysql database:oa 建库语句:create database oa default character set utf8 二 指定ide开发工具:MyEclipse 项目名称:新建web工程,名字为:OA,并设置项目工程编码:utf-8 环境所用主要技术框架:JU
首注:本学习教程为传智播客汤阳光
一 指定数据库:Mysql
database:oa
建库语句:create database oa default character set utf8
二 指定ide开发工具:MyEclipse
项目名称:新建web工程,名字为:OA,并设置项目工程编码:utf-8
环境所用主要技术框架:JUnit4,Struts2.3.15.1,Hibernate3.6,Spring2.5.6,jQuery,……
三 添加框架环境:
1.添加JUnit环境:
右击项目名称 --> Build Path --> Add Libraries --> JUnit,点击next,选择版本为JUnit 4,点击finish。完成JUnit环境添加。
2.添加Struts2.3.15.1环境:
添加jar包:
事先到官网下载好对应版本的项目环境,解压后打开进入apps文件夹里,用好压工具打开struts2-blank.war,点击WEB-INF,
将lib下面的jar包全部复制到我们OA项目的lib下面。
添加配置文件:
用好压工具打开struts2-blank.war,点击WEB-INF,将src --> java下面的struts.xml拷贝到我们OA项目的src下面。然后将
struts.xml里的内容修改为如下内容:
<span> 1</span> <span></span><span>xml version="1.0" encoding="UTF-8" </span><span>?></span> <span> 2</span> <span><span>DOCTYPE struts PUBLIC </span><span> 3</span> <span> "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" </span><span> 4</span> <span> "http://struts.apache.org/dtds/struts-2.3.dtd"</span><span>></span> <span> 5</span> <span> 6</span> <span><span>struts</span><span>></span> <span> 7</span> <span> 8</span> <span><!--</span><span> 设置为开发者模式 </span><span>--></span> <span> 9</span> <span><span>constant </span><span>name</span><span>="struts.devMode"</span><span> value</span><span>="true"</span> <span>/></span> <span>10</span> <span><!--</span><span> 把扩展名设置为.action,如name里的内容记不住,请在core包里的default.properties里面找 </span><span>--></span> <span>11</span> <span><span>constant </span><span>name</span><span>="struts.action.extension"</span><span> value</span><span>="action"</span> <span>/></span> <span>12</span> <span><!--</span><span> 把主题设置为simple,如name里的内容记不住,请在core包里的default.properties里面找 </span><span>--></span> <span>13</span> <span><span>constant </span><span>name</span><span>="struts.ui.theme"</span><span> value</span><span>="simple"</span> <span>/></span> <span>14</span> <span>15</span> <span><span>package </span><span>name</span><span>="default"</span><span> namespace</span><span>="/"</span><span> extends</span><span>="struts-default"</span><span>></span> <span>16</span> <span>17</span> <span></span><span>package</span><span>></span> <span>18</span> <span>19</span> <span><!--</span><span> Add packages here </span><span>--></span> <span>20</span> <span>21</span> <span></span><span>struts</span><span>></span></span></span></span></span></span></span>
如果xml的代码不提示,在我们下载的项目包里面找,具体位置为:struts-2.3.15.1/src/core/src/main/resources/struts-2.3.dtd。
然后配置到myeclipse里面即可。
用好压工具打开struts2-blank.war,点击WEB-INF,将web.xml里面的以下内容拷贝到我们的web.xml里面:
<span> 1</span> <span><span>filter</span><span>></span> <span> 2</span> <span> 3</span> <span><span>filter-name</span><span>></span>struts2<span></span><span>filter-name</span><span>></span> <span> 4</span> <span> 5</span> <span><span>filter-class</span><span>></span>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter<span></span><span>filter-class</span><span>></span> <span> 6</span> <span> 7</span> <span></span><span>filter</span><span>></span> <span> 8</span> <span> 9</span> <span>10</span> <span>11</span> <span><span>filter-mapping</span><span>></span> <span>12</span> <span>13</span> <span><span>filter-name</span><span>></span>struts2<span></span><span>filter-name</span><span>></span> <span>14</span> <span>15</span> <span><span>url-pattern</span><span>></span>/*<span></span><span>url-pattern</span><span>></span> <span>16</span> <span>17</span> <span></span><span>filter-mapping</span><span>></span></span></span></span></span></span></span>
3.添加hibernate3.6的环境:
添加jar包:
1)添加核心包:hibernate3.jar
2)项目包里lib文件夹下面:required里面全部jar包,jpa文件夹里面全部jar包,optional文件夹里c3p0包。
3)mysql驱动包。
添加配置文件:
1)添加hibernate.cfg.xml,具体模板内容如下(在项目环境添加完成之后再做修改):
<span> 1</span> <span><span>DOCTYPE hibernate-configuration PUBLIC </span><span> 2</span> <span> "-//Hibernate/Hibernate Configuration DTD 3.0//EN" </span><span> 3</span> <span> "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"</span><span>></span> <span> 4</span> <span> 5</span> <span><span>hibernate-configuration</span><span>></span> <span> 6</span> <span><span>session-factory </span><span>name</span><span>="foo"</span><span>></span> <span> 7</span> <span><!--</span><span> 显示sql </span><span>--></span> <span> 8</span> <span><span>property </span><span>name</span><span>="show_sql"</span><span>></span>true<span></span><span>property</span><span>></span> <span> 9</span> <span>10</span> <span><span>property </span><span>name</span><span>="hbm2ddl.auto"</span><span>></span>update<span></span><span>property</span><span>></span> <span>11</span> <span><!--</span><span> mysql方言 </span><span>--></span> <span>12</span> <span><span>property </span><span>name</span><span>="dialect"</span><span>></span>org.hibernate.dialect.MySQL5Dialect<span></span><span>property</span><span>></span> <span>13</span> <span><!--</span><span> 数据库连接信息 </span><span>--></span> <span>14</span> <span><!--</span><span> 数据库驱动 </span><span>--></span> <span>15</span> <span><span>property </span><span>name</span><span>="connection.driver_class"</span><span>></span>com.mysql.jdbc.Driver<span></span><span>property</span><span>></span> <span>16</span> <span><span>property </span><span>name</span><span>="connection.url"</span><span>></span>jdbc:mysql:///oa<span></span><span>property</span><span>></span> <span>17</span> <span><span>property </span><span>name</span><span>="connection.username"</span><span>></span>root<span></span><span>property</span><span>></span> <span>18</span> <span><span>property </span><span>name</span><span>="connection.password"</span><span>></span>root<span></span><span>property</span><span>></span> <span>19</span> <span><!--</span><span> 导入映射文件 </span><span>20</span> <span> <mapping resource="org/hibernate/test/legacy/Simple.hbm.xml"/> </span><span>--></span> <span>21</span> <span></span><span>session-factory</span><span>></span> <span>22</span> <span></span><span>hibernate-configuration</span><span>></span></span></span></span></span></span></span></span></span></span></span>
2)添加XX.hbm.xml模板,内容如下(具体代码开发时添加修改):
<span>1</span> <span></span><span>xml version="1.0"</span><span>?></span> <span>2</span> <span><span>DOCTYPE hibernate-mapping PUBLIC </span><span>3</span> <span> "-//Hibernate/Hibernate Mapping DTD 3.0//EN" </span><span>4</span> <span> "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"</span><span>></span> <span>5</span> <span>6</span> <span><span>hibernate-mapping </span><span>package</span><span>="org.hibernate.test.typedmanytoone"</span><span>></span> <span>7</span> <span>8</span> <span></span><span>hibernate-mapping</span><span>></span></span></span>
4.添加Spring2.5.6开发环境:
添加jar包:
1)核心包:
spring.jar
2)依赖包:
spring2.5.6/lib/aspectj下面所有jar包
spring2.5.6/lib/lib/cglib下面的jar包
spring2.5.6/lib/jakarta-commons/commons-logging.jar(如已经添加就不需要了)
添加配置文件applicationConxt.xml,模板内容如下(具体内容在ssh整合时完善):
<span> 1</span> <span></span><span>xml version="1.0" encoding="UTF-8"</span><span>?></span> <span> 2</span> <span><!--</span> <span> 3</span> <span> - Middle tier application context definition for the image database. </span><span> 4</span> <span>--></span> <span> 5</span> <span><span>beans </span><span>xmlns</span><span>="http://www.springframework.org/schema/beans"</span> <span> 6</span> <span> xmlns:xsi</span><span>="http://www.w3.org/2001/XMLSchema-instance"</span> <span> 7</span> <span> xmlns:context</span><span>="http://www.springframework.org/schema/context"</span> <span> 8</span> <span> xmlns:tx</span><span>="http://www.springframework.org/schema/tx"</span> <span> 9</span> <span> xsi:schemaLocation</span><span>="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd </span><span>10</span> <span> http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd </span><span>11</span> <span> http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"</span><span>></span> <span>12</span> <span>13</span> <span><!--</span><span> 自动扫描与装配bean </span><span>--></span> <span>14</span> <span><span>context:component-scan </span><span>base-package</span><span>="cn.clear.oa"</span><span>></span><span>context:component-scan</span><span>></span> <span>15</span> <span>16</span> <span>17</span> <span></span><span>beans</span><span>></span></span></span>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

To handle database connection errors in PHP, you can use the following steps: Use mysqli_connect_errno() to obtain the error code. Use mysqli_connect_error() to get the error message. By capturing and logging these error messages, database connection issues can be easily identified and resolved, ensuring the smooth running of your application.

Using the database callback function in Golang can achieve: executing custom code after the specified database operation is completed. Add custom behavior through separate functions without writing additional code. Callback functions are available for insert, update, delete, and query operations. You must use the sql.Exec, sql.QueryRow, or sql.Query function to use the callback function.

JSON data can be saved into a MySQL database by using the gjson library or the json.Unmarshal function. The gjson library provides convenience methods to parse JSON fields, and the json.Unmarshal function requires a target type pointer to unmarshal JSON data. Both methods require preparing SQL statements and performing insert operations to persist the data into the database.

Through the Go standard library database/sql package, you can connect to remote databases such as MySQL, PostgreSQL or SQLite: create a connection string containing database connection information. Use the sql.Open() function to open a database connection. Perform database operations such as SQL queries and insert operations. Use defer to close the database connection to release resources.

PHP database connection guide: MySQL: Install the MySQLi extension and create a connection (servername, username, password, dbname). PostgreSQL: Install the PgSQL extension and create a connection (host, dbname, user, password). Oracle: Install the OracleOCI8 extension and create a connection (servername, username, password). Practical case: Obtain MySQL data, PostgreSQL query, OracleOCI8 update record.

Use the DataAccessObjects (DAO) library in C++ to connect and operate the database, including establishing database connections, executing SQL queries, inserting new records and updating existing records. The specific steps are: 1. Include necessary library statements; 2. Open the database file; 3. Create a Recordset object to execute SQL queries or manipulate data; 4. Traverse the results or update records according to specific needs.
