今天在搭建框架环境的时候出现以下错误:
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.jt.mapper.UserMapper.selectList] with root cause
浏览显示错误信息如下:
一般情况下,出现这种错误大多是注解类没配好的问题:
但是我检查了各类注解后,发现都没问题,那么问题出在哪呢?我也是百思不得其解,偶然间发现,在mapper层的接口中继承了BaseMapper,但是却没有指定其泛型:
指定泛型后,再次调试:结果成功
这里说下各层对应的基本注解情况:
启动类:(注意启动类位置不要错,与同包下的子包同级)
@SpringBootApplication
@MapperScan(“*****”)
Controller层:
@RestController(等价于以前的@Controller+@ResponseBody)
@Autowired(注入service层接口)
Service层:(实现类,接口加@Mapper或者直接在主类加一个:@MapperScan(“****”))
@Service(交给spring容器管理)
Mapper层
@Mapper或者直接在主类加一个@MapperScan(“****”))