SSM学习遇到的问题(持续更新)

SSM学习遇到的问题(持续更新)

1.问题:使用ajax提交get请求总是返回error

解决方法:返回格式不正确,dataType如果为json,则需要后台返回的是json值。

2.问题:无法找到bean:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name

解决办法:由以上的错误的代码可以看到,我们出现此类bug的原因:找到不到对应的bean,bean注入失败。

注入失败的原因主要有:

(1)没有添加注解。例如:@Service @Autowared @Controller 

(2)错误的注入方法

(3)对于web.xml中监听器的xml配置错误。

所以我们要解决此问题,主要检查注解正确的添加,包引入是否正确,以及检查web.xml监听器的配置。 

1 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'studentListController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.cason.serviceimpl.StudentBeanServiceImpl com.cason.controller.StudentListController.studentBeanImpl; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.cason.serviceimpl.StudentBeanServiceImpl] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
error

 3.问题:

java.lang.IllegalStateException: Optional int parameter 'id' is not present but cannot be translated into a null value due to being declared as a primitive type. Consider declaring it as object wrapper for the corresponding primitive type.

解决办法:如果参数是非必须的,则会赋值为null,因此参数应该是一个object,它才能接受这个null值。而上面代码参数page 的类型 为 int,它接受不了null值。

      解决办法就是将    int  转换成包装类型    integer 



posted @ 2019-01-03 16:23  carsonwuu  阅读(447)  评论(0编辑  收藏  举报