三大框架反反復復搭了很多次,雖然每次都能搭起來,但是效率不高。最近重新搭了一次,理順了思路,整理了需要注意的地方,分享出來。
工具:Eclipse(jdk 1.7) spring和hibernate版本均為4.0以上
推薦使用maven構建項目,相比自己手動導入jar包要方便很多。
1.新建一個maven web項目
(沒用過maven的可以i先去了解一下)
注意點:使用Eclipse創建的maven工程文件結構可能不太正確,需要自己手動創建文件夾。
正確的文件結構:
-src
---main
------java(class文件)
------resources(配置文件)
------webapp(web文件)
---test(測試文件)
------java
------resources
2.pom文件,導入jar包
導入jar包也是框架整合中比較麻煩的點,常常會導入太多不相關的包,但由于不熟悉又不敢刪掉,于是jar
包越導越多,到最后框架是搭起來,但jar包卻導了十幾二十個。
注意點:這里建議的做法是當你不熟悉框架需要導入什么jar包時,可以先導入核心包,然后當運行項目時提示NotFoundClass時,再根據錯誤提示添加相關的依賴,這樣就不會導入多余的jar包。
推薦可以到該網站上去搜索你需要的依賴:https://mvnrepository.com/
pom文件:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
< project xmlns = "http://maven.apache.org/POM/4.0.0" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation = "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" > < modelVersion >4.0.0</ modelVersion > < groupId >hcoding</ groupId > < artifactId >MyWebDemo</ artifactId > < packaging >war</ packaging > < version >0.0.1-SNAPSHOT</ version > < name >MyWebDemo Maven Webapp</ name > < url >http://maven.apache.org</ url > < dependencies > < dependency > < groupId >junit</ groupId > < artifactId >junit</ artifactId > < version >3.8.1</ version > < scope >test</ scope > </ dependency > <!-- spring start --> < dependency > < groupId >org.springframework</ groupId > < artifactId >spring-context</ artifactId > < version >4.3.9.RELEASE</ version > </ dependency > < dependency > < groupId >org.springframework</ groupId > < artifactId >spring-core</ artifactId > < version >4.3.9.RELEASE</ version > </ dependency > < dependency > < groupId >org.springframework</ groupId > < artifactId >spring-beans</ artifactId > < version >4.3.9.RELEASE</ version > </ dependency > < dependency > < groupId >org.springframework</ groupId > < artifactId >spring-web</ artifactId > < version >4.3.9.RELEASE</ version > </ dependency > < dependency > < groupId >org.springframework</ groupId > < artifactId >spring-aspects</ artifactId > < version >4.3.9.RELEASE</ version > </ dependency > < dependency > < groupId >org.springframework</ groupId > < artifactId >spring-orm</ artifactId > < version >4.3.9.RELEASE</ version > </ dependency > <!-- spring end --> <!-- springmvc start --> < dependency > < groupId >org.springframework</ groupId > < artifactId >spring-webmvc</ artifactId > < version >4.3.9.RELEASE</ version > </ dependency > <!-- springmvc end --> <!-- loging start --> < dependency > < groupId >org.slf4j</ groupId > < artifactId >slf4j-api</ artifactId > < version >1.7.6</ version > </ dependency > <!-- loging end --> < dependency > < groupId >aspectj</ groupId > < artifactId >aspectjrt</ artifactId > < version >1.5.3</ version > </ dependency > < dependency > < groupId >org.aspectj</ groupId > < artifactId >aspectjtools</ artifactId > < version >1.8.7</ version > </ dependency > < dependency > < groupId >javax.servlet</ groupId > < artifactId >jstl</ artifactId > < version >1.2</ version > < scope >runtime</ scope > </ dependency > < dependency > < groupId >javax.annotation</ groupId > < artifactId >javax.annotation-api</ artifactId > < version >1.2</ version > </ dependency > < dependency > < groupId >javax.servlet</ groupId > < artifactId >servlet-api</ artifactId > < version >2.5</ version > </ dependency > <!-- hibernate start --> < dependency > < groupId >org.hibernate</ groupId > < artifactId >hibernate-core</ artifactId > < version >4.2.3.Final</ version > </ dependency > <!-- hibernate end --> <!--c3p0 start --> < dependency > < groupId >c3p0</ groupId > < artifactId >c3p0</ artifactId > < version >0.9.1.2</ version > </ dependency > <!-- c3p0 end --> <!-- mysql start--> < dependency > < groupId >mysql</ groupId > < artifactId >mysql-connector-java</ artifactId > < version >5.1.35</ version > </ dependency > <!-- mysql end--> </ dependencies > < build > < finalName >MyWebDemo</ finalName > </ build > </ project > |
其中,注釋塊 <spring> <springmvc> <hibernate>中的依賴導入了框架核心jar包,我們可以提前導入,其他的我們可以根據提示或者需求進行改動。
比如,我的項目中使用的是mysql數據庫和c3p0數據源,所以引入MySQL和c3p0的依賴,如果你使用的是其他數據庫和數據源就需要做相應的修改。
pom文件中為注釋的部分則是在項目運行時提示的jar包缺失引入的依賴,有的是spring框架依賴的包,有的則是servlet或者jsp依賴的,如果第一次搭建時不熟悉可以先不導入,等報錯時再引入依賴,這樣也可以加深理解。
3.配置文件
這是框架整合最重要的部分。配置文件除了web.xml之外都放在main/resources文件夾中,當然你也可以放在其他自己新建的文件夾下,不過配置文件地址要做相應的修改,這個等會詳細說。
配置文件的配置,很多框架整合的教程都不太一樣的,這里給出我自己的配置方法和做法。
配置文件主要分為四個:web.xm , beans.xml , spring-mvc.xml , datasource.xml 。
配置步驟分為兩步,spring-mvc和spring的整合,hibernate和spring的整合,最后再運行項目。(這也是效率比較高的做法,分開整合,這樣即使運行項目有報錯也比較好找,而且分部整合不容易亂)
接下來就開始具體配置。
4.spring-mvc和spring整合
這是spring-mvc.xml配置文件:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
< beans xmlns = "http://www.springframework.org/schema/beans" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns:context = "http://www.springframework.org/schema/context" xmlns:mvc = "http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd"> < mvc:annotation-driven /> < context:component-scan base-package = "com.hcoding.demo" > < context:include-filter type = "annotation" expression = "org.springframework.stereotype.Controller" /> <!-- 排除@service注解的類 --> < context:exclude-filter type = "annotation" expression = "org.springframework.stereotype.Service" /> </ context:component-scan > <!-- 對模型視圖名稱的解析,在請求時模型視圖名稱添加前后綴 --> < bean id = "viewResolver" class = "org.springframework.web.servlet.view.InternalResourceViewResolver" > < property name = "viewClass" value = "org.springframework.web.servlet.view.JstlView" /> < property name = "prefix" value = "demo/" /> <!-- 前綴 --> < property name = "suffix" value = ".jsp" /> <!-- 后綴 --> </ bean > <!-- 對靜態資源的映射--> < mvc:resources mapping = "/js/**" location = "/resources/js/" /> < mvc:resources mapping = "/css/**" location = "/resources/css/" /> < mvc:resources mapping = "/img/**" location = "/resources/img/" /> </ beans > |
這是spring-mvc基本的配置,主要是對請求和靜態資源映射的配置。
注意點:
1.需要特別注意的是掃描包時要排除service層的類,不然在整合hibernate后,項目運行時會報錯。
具體原因看一下這篇文章
2.然后就是如果你的包名和結構不一樣的,那么掃描的包地址也要記得更換。
然后是web.xml配置文件:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" > < web-app > < display-name >MyWebDemo</ display-name > <!-- 統一編碼 解決中文亂碼問題--> < filter > < filter-name >charsetEncoding</ filter-name > < filter-class >org.springframework.web.filter.CharacterEncodingFilter</ filter-class > < init-param > < param-name >encoding</ param-name > < param-value >UTF-8</ param-value > </ init-param > < init-param > < param-name >forceEncoding</ param-name > < param-value >true</ param-value > </ init-param > </ filter > < filter-mapping > < filter-name >charsetEncoding</ filter-name > < url-pattern >/*</ url-pattern > </ filter-mapping > <!-- spring MVC 配置--> < servlet > < servlet-name >spring</ servlet-name > < servlet-class >org.springframework.web.servlet.DispatcherServlet</ servlet-class > < init-param > < param-name >contextConfigLocation</ param-name > <!-- 此處指向的的是SpringMVC的配置文件 如果配置文件地址和名稱不一樣需要更改--> < param-value >classpath:spring-mvc.xml</ param-value > </ init-param > <!--配置容器在啟動的時候就加載這個servlet并實例化--> < load-on-startup >1</ load-on-startup > </ servlet > < servlet-mapping > < servlet-name >spring</ servlet-name > < url-pattern >/</ url-pattern > </ servlet-mapping > <!-- spring MVC config end--> </ web-app > |
將spring-mvc配置文件加到web.xml中,當服務器啟動項目時,才會加載springmvc。配置完成后寫個例子測試一下。
此時的項目結構:
-src
---main
------java(class文件)
----------com.hcoding.controller
----------com.hcoding.service
----------com.hcoding.dao
----------com.hcoding.model
------resources(配置文件)
----------spring-mvc.xml
------webapp(web文件)
----------demo(jsp文件)
----------resources(靜態資源文件:css,js,img)
----------WEB-INF (web相關配置文件)
先在controller包中創建DemoController,class:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
package com.hcoding.demo.controller; import java.util.HashMap; import java.util.Map; import java.util.concurrent.TimeUnit; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; import com.alibaba.fastjson.JSON; import com.hcoding.demo.model.People; import com.hcoding.demo.service.DemoService; @Controller public class DemoController{ @RequestMapping ( "/test" ) public String test(){ return "test" ; } } |
然后在demo文件夾中創建demo.jsp:
1
2
3
4
5
6
7
8
9
10
11
|
<%@ page language="java" contentType="text/html; UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> < html > < head > < meta http-equiv = "Content-Type" content = "text/html; charset=utf-8" > < title >Insert title here</ title > </ head > < body > < p >這是測試頁面。</ p > </ html > |
啟動項目,在瀏覽器中輸入地址:http://localhost:8080/(項目名)/test 。成功可以看到頁面。
5.spring和hibernate整合
datasource.xml配置文件:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
<? xml version = "1.0" encoding = "UTF-8" ?> < beans xmlns = "http://www.springframework.org/schema/beans" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns:jee = "http://www.springframework.org/schema/jee" xmlns:tx = "http://www.springframework.org/schema/tx" xmlns:context = "http://www.springframework.org/schema/context" xmlns:aop = "http://www.springframework.org/schema/aop" xsi:schemaLocation=" http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd"> <!--配置數據源 這里是使用的是c3p0連接池--> < bean id = "dataSource" class = "com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method = "close" > < property name = "driverClass" value = "${jdbc.driver}" /> <!--數據庫連接驅動--> < property name = "jdbcUrl" value = "${jdbc.url}" /> <!--數據庫地址--> < property name = "user" value = "${jdbc.username}" /> <!--用戶名--> < property name = "password" value = "${jdbc.password}" /> <!--密碼--> < property name = "maxPoolSize" value = "40" /> <!--最大連接數--> < property name = "minPoolSize" value = "1" /> <!--最小連接數--> < property name = "initialPoolSize" value = "10" /> <!--初始化連接池內的數據庫連接--> < property name = "maxIdleTime" value = "20" /> <!--最大空閑時間--> </ bean > <!--配置session工廠--> < bean id = "sessionFactory" class = "org.springframework.orm.hibernate4.LocalSessionFactoryBean" > < property name = "dataSource" ref = "dataSource" /> < property name = "packagesToScan" value = "com.hcoding.demo" /> < property name = "hibernateProperties" > < props >38 < prop key = "hibernate.hbm2ddl.auto" >${hibernate.hbm2ddl.auto}</ prop > <!--hibernate根據實體自動生成數據庫表--> < prop key = "hibernate.dialect" >${hibernate.dialect}</ prop > <!--指定數據庫方言--> < prop key = "hibernate.show_sql" >${hibernate.show_sql}</ prop > <!--在控制臺顯示執行的數據庫操作語句--> < prop key = "hibernate.format_sql" >${hibernate.format_sql}</ prop > <!--在控制臺顯示執行的數據哭操作語句(格式)--> </ props > </ property > </ bean > <!-- 事務配置 聲明式事務--> < bean id = "transactionManager" class = "org.springframework.orm.hibernate4.HibernateTransactionManager" > < property name = "sessionFactory" ref = "sessionFactory" /> </ bean > <!-- 使用annotation定義事務 --> < tx:annotation-driven transaction-manager = "transactionManager" /> </ beans > |
datasource.properties文件:
1
2
3
4
5
6
7
8
9
10
|
# database connection config jdbc.driver = com.mysql.jdbc.Driver jdbc.url = jdbc:mysql://localhost:3306/demo?useUnicode= true &characterEncoding=utf-8 jdbc.username = root jdbc. password = 123456 #hibernate config hibernate.dialect = org.hibernate.dialect.MySQLDialect hibernate.show_sql = true hibernate.format_sql = true hibernate.hbm2ddl.auto = update |
beans.xml文件:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
<? xml version = "1.0" encoding = "UTF-8" ?> < beans xmlns = "http://www.springframework.org/schema/beans" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns:context = "http://www.springframework.org/schema/context" xmlns:p = "http://www.springframework.org/schema/p" xmlns:cache = "http://www.springframework.org/schema/cache" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-3.1.xsd"> <!-- 注解 --> < context:annotation-config /> <!--掃描--> < context:component-scan base-package = "com.hcoding.demo" > < context:exclude-filter type = "annotation" expression = "org.springframework.stereotype.Controller" /> </ context:component-scan > <!-- 導入多個Properties配置文件 --> < bean id = "propertyConfigurer" class = "org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" > < property name = "locations" > < list > <!--要是有多個配置文件,只需在這里繼續添加即可 --> < value >classpath:datasource.properties</ value > </ list > </ property > </ bean > 31 <!-- 加載數據源組件 --> 32 < import resource = "classpath:datasource.xml" />33 34 </ beans > |
注意點:在xml導入properties文件是比較常見,將一些相關的配置數據寫到properyties文件中也是常用的方法,利于修改。
常見的另一種導入propertise的方法:在<context:property-placeholder location="classpath:/datasource.properties" />。這種方法spring默認值只導入一個properties,
當有多個properties文件需要導入時,則需要使用另一種方法:
1
2
3
4
5
6
7
8
9
10
|
<!-- 導入多個Properties配置文件 --> < bean id = "propertyConfigurer" class = "org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" > < property name = "locations" > < list > <!--要是有多個配置文件,只需在這里繼續添加即可 --> < value >classpath:datasource.properties</ value > < value >classpath:redis.properties</ value > </ list > </ property > </ bean > |
個人比較推薦這種,隨著項目擴展,需要導入的配置增多,肯定不止一個properties文件,這種方法更通用。
注意點:datasource.properties文件中的數據庫地址,用戶和密碼根據自己的情況做相應的修改。
修改之前的web.xml文件:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" > < web-app > < display-name >MyWebDemo</ display-name > <!-- 統一編碼 解決中文亂碼問題--> < filter > < filter-name >charsetEncoding</ filter-name > < filter-class >org.springframework.web.filter.CharacterEncodingFilter</ filter-class > < init-param > < param-name >encoding</ param-name > < param-value >UTF-8</ param-value > </ init-param > < init-param > < param-name >forceEncoding</ param-name > < param-value >true</ param-value > </ init-param > </ filter > < filter-mapping > < filter-name >charsetEncoding</ filter-name > < url-pattern >/*</ url-pattern > </ filter-mapping > <!-- spring MVC 配置--> < servlet > < servlet-name >spring</ servlet-name > < servlet-class >org.springframework.web.servlet.DispatcherServlet</ servlet-class > < init-param > < param-name >contextConfigLocation</ param-name > <!-- 此處指向的的是SpringMVC的配置文件 --> < param-value >classpath:spring-mvc.xml</ param-value > </ init-param > <!--配置容器在啟動的時候就加載這個servlet并實例化--> < load-on-startup >1</ load-on-startup > </ servlet > < servlet-mapping > < servlet-name >spring</ servlet-name > < url-pattern >/</ url-pattern > </ servlet-mapping > <!-- spring MVC config end--> <!-- 加載spring配置文件 --> < context-param > < param-name >contextConfigLocation</ param-name > < param-value >classpath:beans.xml</ param-value > </ context-param > <!-- listener --> < listener > < listener-class >org.springframework.web.context.ContextLoaderListener</ listener-class > </ listener > </ web-app > |
這就是spring整合hibernate所需要配置的四個文件。文件的加載順序和包含關系:web.xml→bans.xml→datasource.xml→datasource.properties
注意點:如果你的配置文件名稱和存放位置不同,那么你也需要相應的修改。
注意點:一定要記得配置事務,否則操作數據庫時項目可能不會報錯,但數據庫中的數據將不會更新(刪除或者修改)。具體可以自行百度事務相關的知識。
配置完成后寫個例子測試一下。
在model包中創建People.class:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
package com.hcoding.demo.model; import java.util.Set; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.Table; import javax.persistence.Transient; @Entity @Table (name= "people" ) public class People { @Id @Column (name= "ID" ) private int id; @Column (name= "name" ) private String name; @Column (name= "sex" ) private String sex; public void setName(String name) { this .name = name; } public String getSex() { return sex; } public void setSex(String sex) { this .sex = sex; } } |
并在數據庫創建people表格,添加相應的字段。
然后在dao包中創建DemoDao.class:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
package com.hcoding.demo.dao; import javax.annotation.Resource; import org.hibernate.SessionFactory; import org.springframework.stereotype.Repository; import com.hcoding.demo.model.People; @Repository ( "demoDao" ) public class DemoDao extends BaseSupportDao{ @Resource (name= "sessionFactory" ) private SessionFactory sessionFactory; /** * 保存對象 * @param p * @return */ public People save(People p){ return (People) sessionFactory.getCurrentSession().save(p); } } |
在service包中創建DemoServic.class:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
package com.hcoding.demo.service; import java.util.HashSet; import java.util.Set; import javax.annotation.Resource; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.hcoding.demo.dao.DemoDao; import com.hcoding.demo.model.Book; import com.hcoding.demo.model.People; @Service ( "demoService" ) public class DemoService { @Resource (name= "demoDao" ) private DemoDao demoDao;; @Transactional public void save(People p){ demoDao.save(p); } public People newPeople(){ People p= new People(); p.setName( "小白" ); p.setSex( "男" ); return p; } } |
注意點:在save方法上加@Transactional注解來開啟事務。
在DemoController.class中調用save方法保存數據:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
package com.hcoding.demo.controller; import java.util.HashMap; import java.util.Map; import java.util.concurrent.TimeUnit; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; import com.alibaba.fastjson.JSON; import com.hcoding.demo.model.People; import com.hcoding.demo.service.DemoService; @Controller public class DemoController{ @Resource (name= "demoService" ) private DemoService demoService; @RequestMapping ( "/test" ) public String test(){ People p=demoService.newPeople(); demoService.save(p); return "test" ; } } |
啟動服務器,訪問項目。刷新數據庫,如果數據保存到數據庫中了,說明框架搭建完成。
6.總結
以上就是框架整合的全過程,也是自己看了很多教程和自己搭了很多遍后整理的,基本上配置文件是比較整潔,沒有多余的內容(因為很容易由于不懂原理,依樣畫葫蘆莫名其妙寫了些沒有的內容進去),大部分內容也有說明作用,也說了一些需要注意的,我自己犯過錯地方。
當然,如果你是第一次搭建框架,那么問題遠沒有那么少,遇到問題就多百度吧,當然,在這之前對于spring框架還是要多了解一點會更利于學習。另外,項目是全注解的,所以對注解不太了解也可以自行百度一下。
以上為個人經驗,希望能給大家一個參考,也希望大家多多支持服務器之家。
原文鏈接:https://www.cnblogs.com/xuezhajun/p/7687230.html