error:org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.NullPointerException

问题:调用的方法在一个接口类中,但我并没有注入那个被调用的类
解决:在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";

    }

}
原文地址:https://www.cnblogs.com/xym4869/p/8478113.html