从index.jsp 点击跳转链接,但是一直没有反应,也没有404 400什么的,就一直加载,然后不动了 QWQ
感觉该配置的也配置了
public interface UserMapper {
List<User> selectAll();
}
@Controller
public class UserController {
@Autowired
private UserService userService;
@RequestMapping(value = "/selectAll.do")
public ModelAndView selectAll(){
System.out.println("success~~~");
ModelAndView mv = new ModelAndView();
List<User> users = userService.selectAll();
System.out.println("haha");
mv.addObject("users",users);
mv.setViewName("/user_list.jsp");
return mv;
}
}
@Service("accountService")
public class UserServiceImpl implements UserService {
//private UserMapper userMapper = SqlSessionUtil.openSession().getMapper(UserMapper.class);
@Autowired
private UserMapper userMapper;
@Override
public List<User> selectAll() {
List<User> users = userMapper.selectAll();
System.out.println("lllll~");
return users;
}
}
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<body>
<h2><a href="selectAll.do" method="post">查看所有User</a> </h2>
</body>
</html>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>success</title>
</head>
<body>
<h1>success!!!</h1>
<%--<c:forEach items="${users}" var="user">--%>
<%-- <tr>--%>
<%-- <td>${users.id}</td>--%>
<%-- <td>${users.name}</td>--%>
<%-- <td>${users.email}</td>--%>
<%-- </tr>--%>
<%--</c:forEach>--%>
id: ${users.id}
name:${users.name}}
</body>
</html>
springmvc.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.xsd">
<!--开启注解扫描,只扫描controller-->
<context:component-scan base-package="com.dj.controller"/>
<!--添加处理器映射器-->
<!-- <bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"/>-->
<!--添加处理器适配器-->
<!-- <bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"/>-->
<!-- <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"/>-->
<!--配置视图解析器-->
<bean id="internalResourceViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="suffix" value=".jsp"/>
<property name="prefix" value="/WEB-INF/view/"/>
</bean>
<!--过滤静态资源-->
<!-- <mvc:resources mapping="/css/**" location="/css/"/>-->
<!-- <mvc:resources mapping="/images/**" location="/images/"/>-->
<!-- <mvc:resources mapping="/js/**" location="/js/"/>-->
<!--开启springmvc注解支持-->
<mvc:annotation-driven/>
<!-- 配置默认的servlet处理静态资源:在 WEB 容器启动的时候会在上下文中定义一个 DefaultServletHttpRequestHandler,
它会对DispatcherServlet的请求进行处理,如果该请求已经作了映射,
那么会接着交给后台对应的处理程序,
如果没有作映射,就交给 WEB 应用服务器默认的 Servlet 处理,
从而找到对应的静态资源,只有再找不到资源时才会报错。
-->
<mvc:default-servlet-handler/>
</beans>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
<!--配置Spring的编码过滤器-->
<filter>
<filter-name>characterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<!--设置项目中使用的字符编码-->
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
<!--强制请求对象(HttpServletRequest)使用encoding编码的值-->
<init-param>
<param-name>forceRequestEncoding</param-name>
<param-value>true</param-value>
</init-param>
<!--强制应答对象(HttpServletResponse)-->
<init-param>
<param-name>forceResponseEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>characterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- <filter>-->
<!-- <filter-name>HiddenHttpMethodFilter</filter-name>-->
<!-- <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>-->
<!-- </filter>-->
<!-- <filter-mapping>-->
<!-- <filter-name>HiddenHttpMethodFilter</filter-name>-->
<!-- <url-pattern>/</url-pattern>-->
<!-- </filter-mapping>-->
<!-- 配置springmvc的前端控制器-->
<servlet>
<servlet-name>DispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- 设置springmvc配置文件的位置和名称-->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:springmvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>DispatcherServlet</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<!--配置spring监听器,Spring提供了监听器ContextLoaderListener,
实现ServletContextListener接口,可监听
ServletContext的状态,在web服务器的启动,读取Spring的配置文件,创建Spring的IOC容器。 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- 配置spring配置文件自定义的位置和名称-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring.xml</param-value>
</context-param>
</web-app>
spring.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:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
<!--扫描组件(除控制层)-->
<context:component-scan base-package="com.dj">
<!-- 按照注解进行排除,标注了指定注解的组件不要扫描 -->
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
<!-- 指定排除某个具体的类,按照类排除 -->
<!-- <context:exclude-filter type="assignable" expression="com.dj.controller.UserController"/>-->
</context:component-scan>
<context:property-placeholder location="classpath:jdbc.properties"/>
<!-- 配置数据源-->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
<property name="driverClassName" value="${jdbc.driver}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
<!-- 配置事务管理器 -->
<!-- <bean id="transactionManager"-->
<!-- class="org.springframework.jdbc.datasource.DataSourceTransactionManager">-->
<!-- <property name="dataSource" ref="dataSource"/>-->
<!-- </bean>-->
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<!--开启事务注解-->
<tx:annotation-driven transaction-manager="txManager"/>
<bean class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- 设置MyBatis的核心配置文件的路径 -->
<property name="configLocation" value="classpath:mybatis-config.xml"/>
<!-- 设置数据源 -->
<property name="dataSource" ref="dataSource"/>
<!-- 设置类型别名,默认为类名 -->
<property name="typeAliasesPackage" value="com.dj.beans"/>
<!-- 设置映射文件所在的包,只有在映射文件的包和mapper接口的包不一致时需要设置 -->
<!--引入分页插件-->
</bean>
<!--
配置mapper接口的扫描配置,由mybatis-spring提供,可以将指定包下所有的mapper接口创建动态代理,
并将这些动态代理作为IOC容器的bean管理,可以直接在Spring的IOC中获取Mapper接口了。
-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.dj.mappers"/>
</bean>
</beans>