现在评论区找了一遍大家的解决方法,但是要么不适合我,要么没有成效,所有还是请老师帮忙看一下是是什么错误
在Dao验证和Service验证都没有问题
因此贴一下spring-web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
<!-- 配置SpringMVC -->
<!-- 1.开启SpringMVC注解模式 -->
<mvc:annotation-driven />
<!-- 2.静态资源默认servlet配置 (1)加入对静态资源的处理:js,gif,png (2)允许使用"/"做整体映射 -->
<mvc:resources mapping="/resources/**" location="/resources" />
<mvc:default-servlet-handler />
<!-- 3.定义视图解析器 -->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/html/"></property>
<property name="suffix" value=".html"></property>
</bean>
<!-- 文件上传解析器 -->
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="defaultEncoding" value="utf-8"></property>
<!-- 1024 * 1024 * 20 = 20M -->
<property name="maxUploadSize" value="20971520"></property>
<property name="maxInMemorySize" value="20971520"></property>
</bean>
<!-- 4.扫描web相关的bean -->
<context:component-scan base-package="com.imooc.o2o.web" />
<!-- 5.权限拦截器 -->
</beans>
其中,/rescources/报红色
由于我是idea环境,因此访问url时不需要加上o2o,访问http://localhost:8080/superadmin/listarea
结果如下:
我的tomcat版本为9.0
AreaController如下:除了list变量名修改为了areaList,其余都一样,修改成list也是一样的错误,因此应该与此无关
package com.imooc.o2o.web.superadmin;
import com.imooc.o2o.entity.Area;
import com.imooc.o2o.service.AreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 想要调用Controller层的方法,就需要为其添加一个url路径
*/
@Controller
@RequestMapping("/superadmin")
public class AreaController {
@Autowired
private AreaService areaService;
/**
* 将返回值自动转为json对象返回给前端@RequestBody
*/
@RequestMapping(value = "/listarea",method = RequestMethod.GET)
@ResponseBody
public Map<String,Object> listArea()
{
Map<String,Object> modelMap= new HashMap<String, Object>();
List<Area> areaList=new ArrayList<Area>();
try
{
areaList=areaService.getAreaList();
modelMap.put("rows",areaList);
modelMap.put("total",areaList.size());
}
catch (Exception e)
{
e.printStackTrace();
modelMap.put("success",false);
modelMap.put("errMsg",false);
}
return modelMap;
}
}
SSM商铺V1.0,解决毕设痛点;SpringBoot商铺V2.0,满足工作刚需
了解课程