使用springboot 时contraller中findById 方法报错问题

版权声明:未经允许,不得转载 https://blog.csdn.net/ZPJeck/article/details/84073507

在书写springboot的contraller时 出现了 findByIdfindOne 报错出红。

经过查找一番资料后,发现spring boot 2版本中所用的查询是   findById();  并且在使用的时候会加上一个get()方法

代码如下:

 @Autowired
    private UserRepository userRepository;

    @RequestMapping(value = "/fone/{id}")
    public User selectOne(@PathVariable("id") Integer id){
        User user = new User();

        //userRepository.findOne(id);
        //userRepository.findOne(user);
        user = userRepository.findById(id).get();
        System.out.println(user);
        return user;
    }

这样查询数据便会成功。


猜你喜欢

转载自blog.csdn.net/ZPJeck/article/details/84073507
今日推荐