我有一个 Java/J2EE 设计模式问题
问题陈述::
假设有2个文件如下
XYZ.properties file --> name = value pair
abc.xml file --> attribute=value pair.
以上两个文件都有 <name,value>
对。
问题是“设计一个组件/jsp页面,以便您可以读取、编辑、保存属性文件或xml文件的名称、值对。?”
那么您建议我应该在 Java 中使用哪种设计模式?
然后,名称、值对被获取并显示在另一个 jsp 页面中,我应该能够在其中读取、编辑、保存名称、值对,这样
1>读取操作结果为读取名称、值对
2>编辑操作结果编辑名称、值对
3>保存操作会将相应名称、值对的值保存到数据库中,从而更新属性/xml 文件。
**My Initial Analysis** : i would use a Factory design pattern since i have 2 files which have name,value pairs and at run time decide which one to choose depending on the name of file invoked,Once done i would pass the parameters to jsp file for Read,edit and save operation.Save would save the name,value pair to Database but i dont know how will it update the corresponding value for that name in either the property/xml file as well.
我的理解正确吗?如果没有,请在java中提供相同的设计/解决方案,以便对“.properties文件”或“.xml文件”中的对执行读取、编辑、保存操作?
最佳答案
这看起来像是家庭作业。 在不透露太多信息的情况下,Properties 可以读取/写入 .properties 和 .xml 文件,更多信息请参见 http://download.oracle.com/javase/7/docs/api/java/util/Properties.html 。
关于java - Java 中的设计模式问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4545505/