目录:DTD、Schema约束
dtd和Schema约束:http://blog.csdn.net/wust__wangfan/article/details/53187982
- DTD约束:
- dtd约束文件概念:DTD约束技术
- 编写dtd约束:.dtd文件:https://jingyan.baidu.com/article/a3a3f8113ebb168da2eb8adb.html
- 导入dtd约束的三种方式
- 内部导入
- 外部导入
- 互联网导入
- xml文件导入dtd约束的好处:1.编写出错会有提示;2.会有提示可用的标签有哪些
- 本地引入:
实例:mybatis引入dtd约束:
MyBatis的约束文件位置,都放在jar包里面,先添加mybatis依赖,刷新项目后可看到:
MyBatis 主配置文件 mybatis.xml:官网文档也有实例
将上面两个文件复制保存在本地。
然后 - 在线引入:
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> <!-- 这里写配置内容 --> </configuration>
MyBatis 映射文件 mapper.xml
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="命名空间"> <!-- SQL语句 --> </mapper>
- Schema约束
- Schema约束概念
- 编写Schema约束:.xsd文件
- 导入Schema约束的方式
- xml文件导入schema约束的好处:1.编写出错会有提示;2.会有提示可用的标签有哪些
- 实例:spring引入schema约束:以下四行是spring.xml文件的基石
spring约束大全:application.xml<?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:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> </beans>
- 练习1:在xml文件中添加spring aop 约束
- 第一步:项目添加spring-aop.jar包
- 第二步:在此jar下找到配置文件 - .xsd文件
- 第三步:打开spring-aop-2.0.xsd
- 第四步:在xml文件中添加3行
- 完成,可以使用spring aop提示了
- 第一步:项目添加spring-aop.jar包
- 练习2:在xml文件中添加 dubbo 约束(spring和dubbo整合,所以也是在sprign.xml文件中配置)
- 第一种:在线引用
<?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:dubbo="http://code.alibabatech.com/schema/dubbo" xsi:schemaLocation= "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd"> </beans>
- 第二种:本地引用
- 第一步:项目添加dubbo依赖
<dependency> <groupId>com.alibaba</groupId> <artifactId>dubbo</artifactId> <version>2.6.0</version> </dependency>
- 第二步:刷新项目后,查看jar所在位置如图所示
- 第三步:解压dubbo-2.8.4.jar,从meta-inf中找到dubbo.xsd
- 第四步:Eclipse中Window =>preferencr => xml => xml catalog添加catalog,如图所示,Location指向本机dubbo.xsd文件, Key是http://code.alibabatech.com/schema/dubbo/dubbo.xsd,key是从xml schemaLocation拷贝过来的。
- 第五步:在src\main\java下创建applicationContext.xml
<?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:dubbo="http://code.alibabatech.com/schema/dubbo" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd "> </beans>
- 第一步:项目添加dubbo依赖
- 第一种:在线引用