@Value annotations and notes @Data

@Value comment

service level code

@Service
public class HelloServiceImpl implements HelloService { @Autowired private MyConfig myConfig; @Value(value = "${user.userName}") private String userName; @Value("${user.sex}") private String sex; } 

Explanation: The comment has already contacted the relevant configuration file in, the presence of the relevant configuration file inside the configuration parameters and the presence of and elements, so can the value assigned to the current ; ibid. @Autowireduseruserusernamesex@Value(value = "${user.userName}")user.usernameusername@Value("${user.sex}")

@Data comment

@Data
public class login{ private String id; private String name; private Integer age; } 

Explanation: Although loginthere is no written get(),set()method, but @Datanotes will automatically help you configure get(),set()method, logindependency injection, the use login.set()or login.get()method is valid. `

Guess you like

Origin www.cnblogs.com/chengxiaodi/p/11324585.html