gpt4 book ai didi

java常见的存储选项,没有数据库或文件系统

转载 作者:行者123 更新时间:2023-12-02 07:21:34 24 4
gpt4 key购买 nike

我正在设计一个银行 Web 应用程序,我想在其中存储一些共享的通用数据用户/ session 。我想保留数据,但没有任何使用数据库或文件系统的选项。要求是每当修改公共(public)数据时,所有人都应该立即看到它。我将不胜感激一些建议。

最佳答案

尝试使用POJO 。然后将所有 POJO 存储在列表或映射中。

例如

//this is your pojo
public class User{
private String name;
private int age;

public void setName(String name){
this.name = name;
}

public String getName(){
return this.name;
}

public void setAge(int age){
this.age = age;
}

public int getAge(){
return this.age;
}
}


public class TestUser{

public static void main(String args[]){
//to populate record, create object user
User user1 = new User();
user1.setName = "name1";
user1.setAge = "20";//then so on

//after creating object, store it in a <a href="http://tutorials.jenkov.com/java-collections/index.html"collection</a>. Depends on what you want.
List<User> myList = new ArrayList<User>();
//then add it to your collection
myList.add(user1); //and so on
//you can access now your record on your list
}
}

关于java常见的存储选项,没有数据库或文件系统,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14154033/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com