Gaichifanla 2023-09-04 18:26 采纳率: 71.4%
浏览 21

mybatis注解使用报错是为什么

为什么报错


public interface UserService {
    User getUser();
}

public class UserServiceImpl implements UserService {

    @Resource
    private UserMapper userMapper;

    public User getUser(){
        return userMapper.getUser();
    }
}

@Mapper
public interface UserMapper {
    User getUser();
}

 public static void main(String[] args) {
        SpringApplication.run(SkyApplication.class, args);
        UserService userService=new UserServiceImpl();
        System.out.println(userService.getUser());
        log.info("server started");
    }

img


报错信息:

img

  • 写回答

4条回答 默认 最新

  • qq_37749055 2023-09-04 19:15
    关注

    UserMapper userMapper 没有注入成功

    评论

报告相同问题?

问题事件

  • 创建了问题 9月4日