properties

Java 读取 .properties 配置文件

拈花ヽ惹草 提交于 2020-03-12 10:16:32
    java 开发中,经常要读取 properties 配置文件,下面介绍几种读取方式:     1、基于 InputStream 读取配置文件     该方式的优点在于可以读取任意路径下的配置文件      Properties properties = new Properties(); // 使用InPutStream流读取properties文件 BufferedReader bufferedReader = new BufferedReader(new FileReader("D:\\work\\ott-monitor\\src\\main\\resources\\jdbc.properties")); properties.load(bufferedReader); // 获取key对应的value值 String driver = properties.getProperty("datasource.mysql.driver"); System.out.println(driver);     jdbc.properties内容        2、当配置文件放在src/main/resources的目录下时,只能使用Class.getResourceAsStream()方法来加载     当工程部署到Tomcat中时,也应该用这种方式      import

Java读取.properties文件

℡╲_俬逩灬. 提交于 2020-03-12 10:13:31
例 1: 创建一个 config 文件夹 config 文件夹中有一个 Properties.properties 文件 内容为 : capitalLetter=ABCDE smallLetter=abcde 注意:config文件夹与包含Test类的包为同一级 import java.io.IOException; import java.util.Properties; public class Test { public static void main(String[] args) { Properties props=new Properties(); //创建配置文件对应的对象 try { props.load(Test.class.getResourceAsStream("config/Properties.properties")); //指定需要读取文件的位置 System.out.println("从配置文件中读取的大写字母"+props.getProperty("capitalLetter")); System.out.println("从配置文件中读取的小写字母"+props.getProperty("smallLetter")); } catch (IOException e) { e.printStackTrace(); } } } 输出:

Mybatis-配置解析

白昼怎懂夜的黑 提交于 2020-03-12 10:11:51
1.配置解析 1.核心配置文件 mybatis-config.xml MyBatis 的配置文件包含了会深深影响 MyBatis 行为的设置和属性信息。 配置文档的顶层结构如下: configuration(配置) properties(属性) settings(设置) typeAliases(类型别名) typeHandlers(类型处理器) objectFactory(对象工厂) plugins(插件) environments (环境配置) environment(环境变量) transactionManager(事务管理器) dataSource(数据源) databaseIdProvider(数据库厂商标识) mappers(映射器) 2.environments-环境配置 MyBatis 可以配置成适应多种环境, 不过要记住:尽管可以配置多个环境,但每个 SqlSessionFactory 实例只能选择一种环境。 注意一些关键点: 默认使用的环境 ID(比如:default=“development”)。 每个 environment 元素定义的环境 ID(比如:id=“development”)。 事务管理器的配置(比如:type=“JDBC”)。 数据源的配置(比如:type=“POOLED”) 可以设置多套运行环境,但只能同时使用一套

反射属性值记录

狂风中的少年 提交于 2020-03-12 06:54:23
1 /// <summary> 2 /// 通过遍历属性输出属性和值 3 /// </summary> 4 /// <param name="item"></param> 5 public IList<ActionModelPropertyModel> GetProperty<T>(T item) 6 { 7 8 System.Reflection.PropertyInfo[] properties = item.GetType().GetProperties(); 9 var data = from propertyInfo in properties 10 select new ActionModelPropertyModel() 11 { 12 13 PropertyName = propertyInfo.Name, 14 PropertyValue = propertyInfo.GetValue(item).ToString(), 15 PropertyType = propertyInfo.PropertyType.ToString() 16 }; 17 return data.ToList(); 18 } 19 /// <summary> 20 /// todo 在Type实例化之前是没有Value的 21 /// </summary> 22 /// <param

银联网关跳转支付 学习记录1

|▌冷眼眸甩不掉的悲伤 提交于 2020-03-12 01:13:26
最近在做一个项目,里面涉及到了支付功能,使用的是银联的在线支付功能(网关跳转支付)。银联给的例子很坑爹,简单的代码注释了一大堆,关键的部分一点儿注释都没有,很多工具类还没有源码。所以学习起来比较吃力。而网上这方面的资料有相对比较少,仅有的一些资料也比较陈旧。所以我打算记录一下我的学习记录,说不定会对别人也有一些帮助。 下载银联Demo 我做的是银联的网关跳转支付功能,用户在我的网页上点击跳转按钮以后会跳转到银联在线支付页面,支付完用户可以点击返回商家回到我们的网站(但是他可以不点,直接关闭页面),然后我们的服务器后台会接受银联的用户付款的通知,再更新自己数据库的功能。 银联技术服务的首页地址是 https://open.unionpay.com/ajweb/index 很多资料可以在这里找到。 我下载的Demo在这里 https://open.unionpay.com/ajweb/help/file/techFile?cateLog=Sample_code 这里有很多资料都可以选择。但是其实很多是重复的,很多是用不到的(对于我做的功能来说)。所以选择自己需要的就可以了。我选择的是 下载资源类别里的开发包菜单(左侧菜单) 下面的 跳转网关支付产品技术开发包 。 我写这个项目的时候银联版本是2015-07-29的1.11版本(够新了吧(⊙﹏⊙)) 里面乱糟糟的一大堆东西。。。。

JavaIO - Properties集合

南笙酒味 提交于 2020-03-11 13:55:30
Properties集合是双列集合 1,该集合中的键和值都是字符串类型 2,集合中的数据可以保存到流中或者从流中获取 通常该集合操作以键值对形式存在的配置文件。 ● 获取输入流方法: FileInputStream fis = new FileInputStream(properties文件路径); InputStream is = 类名.class.getClassLoader().getResourceAsStream(properties文件名); ● 常用方法: void load(InputStream in):从(文件)流中获取键值对信息,必须是字符串形式的键值对。 String getProperty(String Key):用指定的键在此属性列表中搜索属性,也就是通过Key得到Key所对应的Value。 void setProperty(String Key,String Value):存储元素,调用HashTable的put方法 void store(OutputStream out,String comments):将集合中的键值对数据写入输出流。comments文档注释 void list(PrintStream out):将集合中的键值输出到指定的输出流中 void clear():清空集合中所有键值对。 Set<String>

jquery1.6中的.prop()和.attr()异同

坚强是说给别人听的谎言 提交于 2020-03-11 06:25:12
最近在iteye的新闻中看到jQuery已经更新到了1.6.1。和之前版本的最大变化是增加了.prop方法。但是.prop()方法和.attr()方法,单从字面上很难区分。在汉语中properties和attributes都有表示“属性”的意思。 下面根据这篇博文( javascript:mctmp(0); ),简要翻译了.prop()和.attr()的用法: 1、从1.5.2升级到1.6.1 通过介绍新方法.prop()以及.attr()方法的改变,jQuery1.6.1引起了一场关于attributes和properties之间有何区别和联系的激烈讨论。同时,1.6.1也解决了一些向后兼容性问题。当从1.5.2升级到1.6.1时,你不必修改任何attribute代码。 下面是关于jQuery1.6和1.6.1中Attributes模块变化的描述,以及.attr()方法和.prop()方法的首选使用。然而,正如前面所述,jQuery1.6.1允许你使用.attr()方法就像以前它被使用在所有的情况中一样。 2、发生了什么变化 Attributes模块的变化是移除了attributes和properties之间模棱两可的东西,但是在jQuery社区中引起了一些混乱,因为在1.6之前的所有版本中都使用一个方法(.attr())来处理attributes和properties。但是老的

java 读取配置文件的方式

百般思念 提交于 2020-03-10 22:16:07
方式一: //创建Properties对象 Properties prop = new Properties(); //读取classPath中的properties文件 prop.load(ConsumerController.class.getClassLoader().getResourceAsStream("bean.properties")); //根据键取出值 String className = prop.getProperty("test");//读取bean.properties里面,test的值 ================================================================== 方式二: 使用工具类,将属性@Value("server.port)类似赋值,类加@Component以服务注入,获取内容时,只需要@Autowired服务工具类,调用属性 @Component @Data public class Student { @Value("${server.port}") private String port; } @Autowired private Student student; 使用时直接注入,然后调用属性值 =============================================

spring-boot以及spring-cloud接入nacos管理配置方案

只愿长相守 提交于 2020-03-10 20:42:26
应用接入nacos方案: SpringBoot接入nacos( nacos-config-spring-boot-starter0.2.4 版本以下 ) 引入依赖 <dependency> <groupId> com.alibaba.boot </groupId> <artifactId> nacos-config-spring-boot-starter </artifactId> <version> 0.2.2 </version> </dependency> <dependency> <groupId> com.alibaba.nacos </groupId> <artifactId> nacos-spring-context </artifactId> <version> 0.2.2-RC1 </version> </dependency> 启动类添加注解 @EnableNacosConfig ( globalProperties = @NacosProperties ( serverAddr = "${spring.cloud.nacos.config.server-addr}" , namespace = "${spring.cloud.nacos.config.namespace}" )) @NacosPropertySource ( dataId = "" ,

tomcat的request和response小案例

拥有回忆 提交于 2020-03-09 17:51:22
1.传统方式读取文件 @Test public void test() throws IOException { //创建输入流,关联文件 InputStream is = new FileInputStream("src/demo.properties"); Properties pro = new Properties(); //加载到对象 pro.load(is); //根据key拿到value String usernmae = pro.getProperty("username"); String password = pro.getProperty("passwrod"); } 2.使用getRequestAsStream public class ServletContext1 extends HttpServlet { private static final long serialVersionUID = 1L; protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //ServletContext对象 ServletContext context = this