问题:调用的方法在一个接口类中,但我并没有注入那个被调用的类
解决:在UserEntity前加上@Autowired
@Controller
public class MainController {
// 自动装配数据库接口,不需要再写原始的Connection来操作数据库
@Autowired
UserRepository userRepository;
@RequestMapping(value = "/",method = RequestMethod.GET)
public String index(){
return "index";
}
@RequestMapping(value = "/admin/users",method = RequestMethod.GET)
public String getUsers(ModelMap modelMap){
List<UserEntity> userList = userRepository.findAll();
modelMap.addAttribute("userList", userList);
return "admin/users";
}
}