怎么做网站的百度排名,朝阳区建网站公司有帮云,设计网站建设,采购网1688Resources#xff08;com.ibatis.common.resource.*#xff09;
Resources 类为从类路径中加载资源#xff0c;提供了易于使用的方法。处理 ClassLoader 是一项
富于挑战的工作#xff0c;尤其是应用服务器/容器的情况下。
Resources 类试图简化这些工作#xff0c;Res…Resourcescom.ibatis.common.resource.*
Resources 类为从类路径中加载资源提供了易于使用的方法。处理 ClassLoader 是一项
富于挑战的工作尤其是应用服务器/容器的情况下。
Resources 类试图简化这些工作Resources 类常用于以下几种情况 1.从类路径加载 SQL Map 配置文件如 sqlMap-config.xml。 2. 从类路径加载 DAO Manager 配置文件如 dao.xml。 3. 从类路径加载各种.properties 文件。
加载一个资源有很多方式包括 1.对于简单的只读文本数据加载为 Reader。 Reader getResourceAsReader(String resource); 2. 对于简单的只读二进制或文本数据加载为 Stream。
Stream getResourceAsStream(String resource);
3.对于可读写的二进制或文本文件加载为 File。
File getResourceAsFile(String resource);
/4. 对于只读的配置属性文件加载为 Properties。
Properties getResourceAsProperties(String resource);
/5. 对于只读的通用资源加载为 URL。 按以上的顺序Resources 类加载资源的方法如下
Url getResourceAsUrl(String resource); 在以上每个方法中加载资源和加载 Resources 类的为同一个 ClassLoader或者如果 失败将使用系统的 ClassLoader。 在某些环境下比如某些应用服务器 ClassLoader 可能是个麻烦事您可以指定所使用的 ClassLoader比如使用加载应用的 ClassLoader。 上面每个方法都有相应把 ClassLoader 作为参数的方法。它们是
Reader getResourceAsReader (ClassLoader classLoader, String resource);
Stream getResourceAsStream (ClassLoader classLoader, String resource);
File getResourceAsFile (ClassLoader classLoader, String resource);
Properties getResourceAsProperties (ClassLoader classLoader, String resource);
Url getResourceAsUrl (ClassLoader classLoader, String resource);
以上方法的 resource 参数名称应该是全限定名加上全文件/资源名。 例如如果在类路径中有资源“com.domain.mypackage.MyPropertiesFile.properties”您使用下面的代码加载 String resource “com/domain/mypackage/MyPropertiesFile.properties”; Properties props Resources.getResourceAsProperties (resource); 同样地您可以从类路径加载 SQL Map 配置文件为一个 Reader。假设它在类路径的 properties 目录下properties.sqlMap-config.xml。 String resource “properties/sqlMap-config.xml”; Reader reader Resources.getResourceAsReader(resource); SqlMapClient sqlMap XmlSqlMapBuilder.buildSqlMap(reader);