一般需要打印出来的时候需要重写toString方法
例如:User.java类
1 public class User { 2 3 private String name; 4 5 @Value(value="北京欢迎你",xxx="666") 6 private String address; 7 8 public String getName() { 9 return name; 10 } 11 public void setName(String name) { 12 this.name = name; 13 } 14 public String getAddress() { 15 return address; 16 } 17 public void setAddress(String address) { 18 this.address = address; 19 } 20 @Override 21 public String toString() { 22 return "User [name=" + name + ", address=" + address + "]"; 23 } 24 25 26 }
Main.java
1 public class Main { 2 3 public static void main(String[] args) { 4 User user = new User(); 5 System.out.println(user); 6 } 7 8 }
打印出的(因为没有赋值所以为空):