zoukankan      html  css  js  c++  java
  • 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";
    
        }
    
    }
  • 相关阅读:
    table布局与div布局
    HTML一般标签
    jquery
    PDO对象
    分页例题
    投票练习
    封装 链接数据库类
    访问数据方法
    面相对象多态
    面向对象
  • 原文地址:https://www.cnblogs.com/xym4869/p/8478113.html
Copyright © 2011-2022 走看看