在使用hibernate或者spring的时候,我们往往通过配置文件配置数据库连接属性。但这次项目中并没有用到hibernate和spring,只用到了struts2。要如何实现通过读取文件配置获取属性值呢?

方式一:ResourceBundle这个类可是实现读取properties文件来获取值

在java中:

 



 

 在.properties文件中:

driverName=com.mysql.jdbc.Driver
url=xxxxx/:3307/9zgame?
user=root
password=xxxxxx

文件名字为:property_zh.properties。后zh根据Locale.CHINA一致的,如果Locale.ENGLISH,则文件名为:property_en.properties

 

方式二:使用commons组件。

需要使用jar包:commons-configuration-1.3.jar,commons-lang-2.3.jar,commons-collections.3.2.jar,commons-logging.jar


 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-13
  • 2021-09-21
  • 2021-11-14
猜你喜欢
  • 2022-12-23
  • 2022-02-11
  • 2022-01-26
  • 2021-11-13
  • 2021-06-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案