MyEclipse中XML的智能提示和關於Spring 配置文件頭的一些記錄和解釋

一. 首先介紹XML文件的一些知識:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"

xmlns:context="http://www.springframework.org/schema/context"

xmlns:p="http://www.springframework.org/schema/p"

xmlns:mvc="http://www.springframework.org/schema/mvc"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd

http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd

http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd"

</beans>


XML Schema命名空間作用:
1、避免命名衝突,像Java中的package一樣

2、將不同作用的標籤分門別類(像Spring中的context命名空間針對組件的標籤)


代碼解釋:
1、xmlns="http://www.springframework.org/schema/beans"
聲明xml文件默認的命名空間,表示未使用其他命名空間的所有標籤的默認命名空間。

2、xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

聲明XML Schema 實例,聲明後就可以使用 schemaLocation 屬性了

3、xmlns:aop="http://www.springframework.org/schema/mvc"
聲明前綴爲mvc的命名空間,後面的URL用於標示命名空間的地址不會被解析器用於查找信息。其惟一的作用是賦予命名空間一個惟一的名稱。當命名空間被定義在元素的開始標籤中時,所有帶有相同前綴的子元素都會與同一個命名空間相關聯。

4、xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
這個從命名可以看出個大概,指定Schema的位置這個屬性必須結合命名空間使用。這個屬性有兩個值,第一個值表示需要使用的命名空間。第二個值表示供命名空間使用的 XML schema 的位置


所以我們需要什麼樣的標籤的時候,就引入什麼樣的命名空間和Schema 定義就可以了。

二. 如何在MyEclipse中進行導入呢:

首先選擇:【Window】-->【Preferences】-->【MyEclipse】-->【Files and Editors】-->【XML】-->【XML Catalog】選擇添加:

161224048712649.png161224253402661.png161224373403595.png161224490437787.png這樣以後再xml文件裏面寫頭就能夠出現只能提示了

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章