我有在朗姆酒时需要动态值的构造函数,并且想知道它是否
仍然可以使用依赖注入。请让我知道在这种情况下如何使用 spring 进行依赖注入。
public class User {
private String username;
private int userid;
User(String username, int userid) {
this.username = username;
this.userid = userid;
}
public String toString() {
return "username" + userid;
}
}
public class Superuser {
private User user;
public daomethod() {
//some data access code that gets the username and id ......
// now i need to pass this username and user id to the User constructor
user.toString();**
}
}