java el json_Spring: 读取 .properties 文件地址,json转java对象,el使用java类方法相关 (十三)...

本文介绍了在Java中读取.src/main/resources下的.properties文件的方法,包括获取键值对以及修改键值对。同时讲解了如何将JSON字符串转化为Java对象,处理日期类型,并在Spring中进行数据提交的RequestMapping方法。注意EL表达式调用Java类方法时的规范和可能出现的错误。
摘要由CSDN通过智能技术生成

1. 在Java中获取 .properties 文件的路径 (src/main/resources 下)

ProjectName

|---src/main/java

|---src/main/resources

|---test.properties

packagexxx.yyy;public classUtils {private String filePath = Utils.class.getClassLoader().getResource("test.properties").getPath();

}

2. 获取 .properties Key所对应的值

publicString getPropertyConfig(String key) {

Resource resource= new ClassPathResource("test.properties");

Properties props= null;try{

props=PropertiesLoaderUtils.loadProperties(resource);

}catch(IOException e) {

e.printStackTrace();

}returnprops.getProperty(key);

}

3. 第二种获取 .properties Key 对应值方法

public staticString getValueByKey(String key, String filePath) {

Properties pps= newProperties();try{

InputStream in= new BufferedInputStream (newFileInputStream(filePath));

pps.load(in);

String value=pps.getProperty(key);

System.out.println(key+ " = " +value);returnvalue;

}catch(IOException e) {

e.printStackTrace();return null;

}

}

4. 写入修改 .properties 健值对方法 [单健]

public static void WriteProperties (String filePath, String pKey, String pValue) throwsIOException {

Properties pps= newProperties();

InputStream in=

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值