1、栈溢出异常
解决问题
1、报错信息(java.lang.StackOverflowError)
只有这一句没有更多的信息了,Mybatis查询数据库出现的问题
问题会在Serviceimpl和接口对应的Mapper
我的问题在Serviceimpl
错误示范:
public List<Books> queryAllBook() { return queryAllBook(); }
在Service层调用dao层进行数据交互,这样就会反复调用自己栈溢出
Serviceimpl注入Mapper进行数据操作
private BookMapper bookMapper; public void setBookMapper(BookMapper bookMapper) { this.bookMapper = bookMapper; }
public List<Books> queryAllBook() { return bookMapper.queryAllBook(); }
Mapper出现的问题
<select id="queryBookById" resultType="Books" parameterType="int"> select * from ssmbuild.books where bookID=#{id} </select> <select id="queryAllBook" resultType="Books"> select * from ssmbuild.books </select>
返回值类型写错,参数类型写错
2、Parameter 'id' not found. Available parameters are [param1, bookID]
问题很显然注解@param配置的内容和传进去的参数名不一样
错误示范:
Books queryBookById(@Param("bookID") int id); List<Books> queryAllBook();
public Books queryBookById(int id) { return bookMapper.queryBookById(id); }
可以把上面改为id
或下面该为bookID
3、跳转500
报空指针异常
我的问题是所有的ApplicationContext分开写在web.inf下的整合出现问题
<servlet> <servlet-name>springmvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring-mvc.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet>
不能只导入Spring-MVC,需要导入全部
<servlet> <servlet-name>springmvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet>