@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. @Autowired
user
user
username
sex
@Value(value = "${user.userName}")
user.username
username
@Value("${user.sex}")
@Data comment
@Data
public class login{ private String id; private String name; private Integer age; }
Explanation: Although login
there is no written get(),set()
method, but @Data
notes will automatically help you configure get(),set()
method, login
dependency injection, the use login.set()
or login.get()
method is valid. `