javaweb 項(xiàng)目初始配置的方法步驟_第1頁(yè)
javaweb 項(xiàng)目初始配置的方法步驟_第2頁(yè)
javaweb 項(xiàng)目初始配置的方法步驟_第3頁(yè)
javaweb 項(xiàng)目初始配置的方法步驟_第4頁(yè)
javaweb 項(xiàng)目初始配置的方法步驟_第5頁(yè)
已閱讀5頁(yè),還剩4頁(yè)未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

第javaweb項(xiàng)目初始配置的方法步驟目錄項(xiàng)目初始流程:數(shù)據(jù)庫(kù)的建立于一開(kāi)始的分層:perties:首先創(chuàng)建數(shù)據(jù)庫(kù)連接的工具類:DBUtil1:得到配置文件對(duì)象:2:獲取數(shù)據(jù)庫(kù)連接:3:關(guān)閉資源:DBUtil類全部代碼:使用日志:

項(xiàng)目初始流程:

首先說(shuō)一下pom.xml文件的依賴:

dependencies

!--junit測(cè)試--

dependency

groupIdjunit/groupId

artifactIdjunit/artifactId

version4.12/version

scopetest/scope

/dependency

!--webservlet--

dependency

groupIdjavax.servlet/groupId

artifactIdjavax.servlet-api/artifactId

version4.0.1/version

scopeprovided/scope

/dependency

!--日志打印相關(guān)的jar--

dependency

groupIdorg.slf4j/groupId

artifactIdslf4j-log4j12/artifactId

version1.7.2/version

/dependency

dependency

groupIdorg.slf4j/groupId

artifactIdslf4j-api/artifactId

version1.7.2/version

/dependency

!--mysql驅(qū)動(dòng)包--

dependency

groupIdmysql/groupId

artifactIdmysql-connector-java/artifactId

version8.0.19/version

/dependency

!--json依賴--

dependency

groupIdcom.alibaba/groupId

artifactIdfastjson/artifactId

version1.2.62/version

/dependency

!--hutool工具集--

dependency

groupIdcn.hutool/groupId

artifactIdhutool-all/artifactId

version5.4.7/version

/dependency

!--commons-io依賴--

dependency

groupIdcommons-io/groupId

artifactIdcommons-io/artifactId

version2.4/version

/dependency

!--添加百度編輯器ueditor支持--

dependency

groupIdcommons-fileupload/groupId

artifactIdcommons-fileupload/artifactId

version1.3.1/version

/dependency

!--jstl依賴--

dependency

groupIdjavax.servlet/groupId

artifactIdjstl/artifactId

version1.2/version

/dependency

!--lombok插件--

dependency

groupIdjectlombok/groupId

artifactIdlombok/artifactId

version1.18.12/version

scopeprovided/scope

/dependency

/dependencies

build

finalNamelezijie-note/finalName

plugins

!--編譯環(huán)境插件--

plugin

groupIdorg.apache.maven.plugins/groupId

artifactIdmaven-compiler-plugin/artifactId

version2.3.2/version

configuration

source1.8/source

target1.8/target

encodingUTF-8/encoding

/configuration

/plugin

!--Tomcat插件--

plugin

groupIdorg.apache.tomcat.maven/groupId

artifactIdtomcat7-maven-plugin/artifactId

version2.1/version

configuration

port8080/port!--啟動(dòng)端口默認(rèn):8080--

path/note/path!--項(xiàng)目的站點(diǎn)名,即對(duì)外訪問(wèn)路徑--

servertomcat7/server!--服務(wù)器名稱--

/configuration

/plugin

/plugins

/build

/project

數(shù)據(jù)庫(kù)的建立于一開(kāi)始的分層:

perties:

#連接MYSQL數(shù)據(jù)庫(kù)的配置文件注:等號(hào)的前后不要寫空格

#驅(qū)動(dòng)名

jdbcName=com.mysql.cj.jdbc.Driver

#數(shù)據(jù)庫(kù)連接(db_lezijie_note是數(shù)據(jù)庫(kù)的名稱)

dbUrl=jdbc:mysql://localhost:3306/db_lezijie_noteuseUnicode=truecharacterEncoding=utf8serverTimezone=GMT%2B8useSSL=false

#數(shù)據(jù)庫(kù)的連接賬號(hào)(賬號(hào)基本上都是root)

dbName=root

#數(shù)據(jù)庫(kù)的連接密碼(每個(gè)人的數(shù)據(jù)庫(kù)密碼可能不一致,需要修改)

dbPwd=root

首先創(chuàng)建數(shù)據(jù)庫(kù)連接的工具類:DBUtil

1:得到配置文件對(duì)象:

*得到配置文件對(duì)象

privatestaticPropertiesproperties=newProperties();

static{

try{

//加載配置文件(輸入流)

InputStreamin=DBUtil.class.getClassLoader().getResourceAsStream("perties");

//通過(guò)load()方法將數(shù)日六的內(nèi)容加載到配置文件對(duì)象中

properties.load(in);

//通過(guò)配置文件對(duì)象的getProperty()方法獲取驅(qū)動(dòng)名,拿到驅(qū)動(dòng)名之后加載驅(qū)動(dòng)

Class.forName(properties.getProperty("jdbcName"));

}catch(Exceptione){

e.printStackTrace();

2:獲取數(shù)據(jù)庫(kù)連接:

*獲取數(shù)據(jù)庫(kù)連接

*@return

publicstaticConnectiongetConnection(){

Connectionconnection=null;

try{

//得到數(shù)據(jù)庫(kù)鏈接的相關(guān)性息

StringdbUrl=properties.getProperty("dbUrl");

StringdbName=properties.getProperty("dbName");

StringdbPwd=properties.getProperty("dbPwd");

connection=DriverManager.getConnection(dbUrl,dbName,dbPwd);

}catch(SQLExceptionthrowables){

throwables.printStackTrace();

returnconnection;

3:關(guān)閉資源:

*關(guān)閉資源

*@paramresultSet

*@parampreparedStatement

*@paramconnection

publicstaticvoidclose(ResultSetresultSet,

PreparedStatementpreparedStatement,

Connectionconnection){

//判斷資源對(duì)象如果不為空則關(guān)閉

try{

if(resultSet!=null){

resultSet.close();

if(preparedStatement!=null){

preparedStatement.close();

if(connection!=null){

connection.close();

}catch(SQLExceptionthrowables){

throwables.printStackTrace();

DBUtil類全部代碼:

packagecom.ftzlovedsj.util;

importjava.io.IOException;

importjava.io.InputStream;

importjava.sql.*;

importjava.util.Properties;

*@author${范濤之}

*@Description

*@create2025-11-1419:02

publicclassDBUtil{

*得到配置文件對(duì)象

privatestaticPropertiesproperties=newProperties();

static{

try{

//加載配置文件(輸入流)

InputStreamin=DBUtil.class.getClassLoader().getResourceAsStream("perties");

//通過(guò)load()方法將數(shù)日六的內(nèi)容加載到配置文件對(duì)象中

properties.load(in);

//通過(guò)配置文件對(duì)象的getProperty()方法獲取驅(qū)動(dòng)名,拿到驅(qū)動(dòng)名之后加載驅(qū)動(dòng)

Class.forName(properties.getProperty("jdbcName"));

}catch(Exceptione){

e.printStackTrace();

*獲取數(shù)據(jù)庫(kù)連接

*@return

publicstaticConnectiongetConnection(){

Connectionconnection=null;

try{

//得到數(shù)據(jù)庫(kù)鏈接的相關(guān)性息

StringdbUrl=properties.getProperty("dbUrl");

StringdbName=properties.getProperty("dbName");

StringdbPwd=properties.getProperty("dbPwd");

connection=DriverManager.getConnection(dbUrl,dbName,dbPwd);

}catch(SQLExceptionthrowables){

throwables.printStackTrace();

returnconnection;

*關(guān)閉資源

*@paramresultSet

*@parampreparedStatement

*@paramconnection

publicstaticvoidclose(ResultSetresultSet,

PreparedStatementpreparedStatement,

Connectionconnection){

//判斷資源對(duì)象如果不為空則關(guān)閉

try{

if(resultSet!=null){

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論