ssm整合 jsp頁面跳轉請求controller沒有任何反應,直接輸入地址也沒有反應。
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>SSM</display-name>
<!-- 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>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- REST請求方式處理 -->
<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核心控制器DispatcherServlet -->
<servlet>
<servlet-name>DispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:springMVC.xml</param-value>
</init-param>
<!-- 將servlet加載時間提前到專案啟動時 -->
<load-on-startup>1</load-on-startup>
</servlet>
<serlet-mapping>
<servlet-name>DispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</serlet-mapping>
<!-- 整合spring和springMVC 配置spring監聽器-->
<!--自定義spring組態檔位置和名稱 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</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-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">
<!-- 掃描組件 -->
<context:component-scan base-package="myy.ssm">
<!--type="annotation"通過注解進行排除 -->
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
<!-- 引入資源檔案 -->
<context:property-placeholder location="classpath:jdbc.properties"/>
<!-- 管理mybatis里的資料源 -->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
<property name="driverClassName" value="https://bbs.csdn.net/topics/${jdbc.driver}"></property>
<property name="url" value="https://bbs.csdn.net/topics/${jdbc.url}"></property>
<property name="username" value="https://bbs.csdn.net/topics/${jdbc.username}"></property>
<property name="password" value="https://bbs.csdn.net/topics/${jdbc.password}"></property>
</bean>
<!-- 宣告事務管理器 -->
<bean id="dataSourceTransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<!-- 參考上面創建的資料源 -->
<property name="dataSource" ref="dataSource"></property>
</bean>
<!-- 開啟事務注解驅動 參考上邊id-->
<tx:annotation-driven transaction-manager="dataSourceTransactionManager"/>
<!-- 管理mybatis操作資料庫的會話物件Sqlsession -->
<bean class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- 設定mybatis核心組態檔的路徑 -->
<property name="configLocation" value="https://bbs.csdn.net/topics/classpath:mybatis-config.xml"></property>
<!-- 設定資料源 -->
<property name="dataSource" ref="dataSource"></property>
<!-- 設定型別別名 -->
<property name="typeAliasesPackage" value="https://bbs.csdn.net/topics/myy.ssm.bean"></property>
<!-- 設定映射檔案的路徑 -->
<property name="mapperLocations" value="https://bbs.csdn.net/topics/classpath:myy/ssm/mapper/*.xml"></property>
</bean>
<!--在所設定的包下,將所有介面生成,動態代理實作類,并由spring容器管理 只要這個bean被加載包下所有介面全部都會生成代理物件不需要getmapper -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="https://bbs.csdn.net/topics/myy.ssm.mapper"></property>
</bean>
</beans>
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/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
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-4.0.xsd">
<!-- 掃描控制層組件 -->
<context:component-scan base-package="myy.ssm.controller"></context:component-scan>
<!-- 配置視圖決議器 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="https://bbs.csdn.net/WEB-INF/view/"></property>
<property name="suffix" value="https://bbs.csdn.net/topics/.jsp"></property>
<!-- 可配置多個 通過這個配置優先級 -->
<!-- <property name="order"></property>-->
</bean>
<!-- 默認的servlet -->
<mvc:default-servlet-handler/>
<!-- MVC驅動 -->
<mvc:annotation-driven/>
</beans>
mybatis-congfig.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<settings>
<setting name="cacheEnabled" value="https://bbs.csdn.net/topics/true"/><!-- 開啟全域快取 -->
<setting name="mapUnderscoreToCamelCase" value="https://bbs.csdn.net/topics/true"/>
<setting name="jdbcTypeForNull" value="https://bbs.csdn.net/topics/NULL"/>
<!-- 我們需要使用得屬性不管默認值是什莫 都寫出來,防止版本更新帶來問題 -->
<!-- 懶加載 用什么加載什么 -->
<setting name="lazyLoadingEnabled" value="https://bbs.csdn.net/topics/true"/>
<!-- 按需加載如果是true則全部加載 -->
<setting name="aggressiveLazyLoading" value="https://bbs.csdn.net/topics/false"/>
</settings>
<!-- 分頁插件 -->
<plugins>
<plugin interceptor="com.github.pagehelper.PageInterceptor"></plugin>
</plugins>
</configuration>
controller包
package myy.ssm.controller;
import java.util.List;
import java.util.Map;
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 myy.ssm.bean.Emp;
import myy.ssm.service.EmpService;
@Controller
public class EmpController {
@Autowired
private EmpService service;
@RequestMapping(value = "/emps",method = RequestMethod.POST)
public String getAllEmp(Map<String,Object> map) {
System.out.println("1111");
List<Emp> empList = service.getAllEmp();
map.put("empList", empList);
System.out.println("11111111");
return "list";
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/71443.html
標籤:Eclipse
上一篇:Birt報表問題
下一篇:求解
