문제

다음 데이터가 있습니다.

User   System    SubSystem
user1  System1   SubSystem1
user2  System1   SubSystem2
user3  N/A       N/A

또한 사용자로부터 시스템/서브 시스템 튜플을 결정할 수 있어야합니다. 시스템을 재건하고 재배치하지 않고 언제든지 사용자를 추가 할 수 있어야합니다.

데이터베이스가 최선의 선택이라는 것을 알고 있지만 데이터베이스 테이블을 사용할 수 없습니다.

나는 현재 해시 맵을 사용하여 매핑했지만 하드 코딩을 원하지 않습니다. 나는 Properties 파일을 사용하는 것에 대해 생각하고 있었지만 그것을 구현하는 방법을 시각화 할 수는 없습니다. 다른 사람이 제안이 있습니까?

중요하지는 않지만 Weblogic 10.3에서 Java를 사용하고 있습니다.

도움이 되었습니까?

해결책

I would go for something as simple as :

user1 = userValue
user1.system = systemValue
user1.system.subsystem= subsystemValue
user2 = userValue
user2.system = systemValue
user2.system.subsystem= subsystemValue

user(id) is used as "primary" key in your properties, and a very simple concatenation of your fields to store your table values. I use this very often : trust me, it's much more powerfull than it may appear :)

다른 팁

You could do this using a HashMap (as you do now) and store it using XStream.

XStream allows you to serialise/deserialise Java objects to/from readable/editable XML. You can then write this to (say) a filesystem, and the result is editable by hand.

The downside is that it's a serialisation in XML of a Java object, so not as immediately obvious as a properties file to edit. However it's still very readable, and easily understood by anyone remotely technical. Whether this is an appropriate solution depends on the audience of this file.

Sounds like something you could very well use YAML for..
SnakeYAML looks to be a workable Java implementation.

For this project i've gone with the solution proposed by Olivier. Some project contrainst (legacy of the project) prevent me for going with a probably better solution of using XStream.

Thx for the feed back guys

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top