+-
private static final ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
private static final UserService userService = (UserService) ctx.getBean("userService");
@RequestMapping(value = "/api/test", method = RequestMethod.GET)
public String index(Long id, Map<String, Object> map) {
map.put("id", id);
User user = userService.get(id);
map.put("user", user);
return "api/test";
}
private
上加 static
和final
和不加有什么区别没
这是三个完全不同用途的关键字。
public
、private
、protected
决定可见性。
static
决定是否静态,即需要通过某一具体实例才能访问、还是通过类型直接就可以访问。
final
决定是否只读。
三个其实是不相关的关键字
private 代表访问限制,私有访问
static 代码静态修饰,让你可以直接通过类名.变量名访问
final 代表最终,不可修改