针对自学项目《O2O商城项目》遇到的问题
昨晚搞了四五个小时没弄明白
今天上午,发现原因有两个
原因一:未加上springMVC注解声明对应的文件信息
原因二:Tomcat中Application context路径映射,配置错误(这里我的理解Application context在ssm项目中即为spring容器)
访问下面下面listArea()方法时
我输入的url地址是,http://localhost:8080/o2o/superadmin/listarea
经过测试发现,tomcat中applicatin context 对应的映射没有更改
将"/o2o_war_exploded"改为“/o2o”之后,就可以了。
进一步思考
我们知道 Spring会过滤出添加了@Controller的Bean,会将
Controller中所有添加了注解@RequestMapping的方法解析出来,封装成RequestMappingInfo存储到 RequestMappingHandlerMapping中的mappingRegistry。 后续请求到达时,会从mappingRegistry中查找能够处理该请求的方法。
回到本问题,http://localhost:8080/o2o/superadmin/listarea 就是一个请求
这里的“/o2o ”对应spring容器,spring容器中管理着所有的Bean,spring会根据“/superadmin/listarea”找到mappingResgistry中对应的listArea()方法,从而完成请求的处理。