av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

您的位置:首頁技術文章
文章詳情頁

java - springmvc 無法掃描到controller層

瀏覽:113日期:2024-01-29 11:15:04

問題描述

各種404,請求/user/showUser不能進入controller,整了一天,快瘋了,求組各位大神!直接上代碼項目結構:java - springmvc 無法掃描到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' xmlns:web='http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd' xsi:schemaLocation='http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd' version='3.0'> <display-name>Archetype Created Web Application</display-name> <!-- Spring 配置文件路徑,此處可將Spring MVC的相關配置內容配置到Spring的配置文件applicationContext.xml中,共享同一個配置文件即可 --> <context-param><param-name>contextConfigLocation</param-name><param-value>classpath:applicationContext.xml</param-value> </context-param> <!-- Spring 監聽器 配置 --> <listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <listener><listener-class>org.springframework.web.context.request.RequestContextListener</listener-class> </listener> <!-- 字符集 過濾器 --> <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><init-param> <param-name>forceEncoding</param-name> <param-value>true</param-value></init-param> </filter> <filter-mapping><filter-name>CharacterEncodingFilter</filter-name><url-pattern>/*</url-pattern> </filter-mapping> <!-- Spring mvc 配置,配置文件名稱默認為{servlet-name}-servlet.xml,路徑默認在/WEB-INF/下 --> <servlet><servlet-name>springmvc</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:springmvc/spring-mvc.xml</param-value></init-param><load-on-startup>1</load-on-startup><async-supported>true</async-supported> </servlet> <servlet-mapping><servlet-name>springmvc</servlet-name><url-pattern>/</url-pattern> </servlet-mapping><welcome-file-list><welcome-file>index.html</welcome-file> </welcome-file-list></web-app>

applicationContent.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:p='http://www.springframework.org/schema/p' 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-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd'> <mvc:annotation-driven /> <!-- 自動掃描 --> < <context:component-scan base-package='com.chs'><context:exclude-filter type='annotation' expression='org.springframework.stereotype.Controller' /> </context:component-scan <!-- 引入配置文件 --> <bean class='org.springframework.beans.factory.config.PropertyPlaceholderConfigurer'><property name='location' value='classpath:dataSource.properties' /> </bean> <bean destroy-method='close'><property name='driverClassName' value='${driver}' /><property name='url' value='${url}' /><property name='username' value='${username}' /><property name='password' value='${password}' /><!-- 初始化連接大小 --><property name='initialSize' value='${initialSize}'></property><!-- 連接池最大數量 --><property name='maxActive' value='${maxActive}'></property><!-- 連接池最大空閑 --><property name='maxIdle' value='${maxIdle}'></property><!-- 連接池最小空閑 --><property name='minIdle' value='${minIdle}'></property><!-- 獲取連接最大等待時間 --><property name='maxWait' value='${maxWait}'></property> </bean> <!-- spring和MyBatis完美整合,不需要mybatis的配置映射文件 --> <bean class='org.mybatis.spring.SqlSessionFactoryBean'><property name='dataSource' ref='dataSource' /><!-- 自動掃描mapping.xml文件 --><property name='mapperLocations' value='classpath:mybatisMappingConfig/*.xml'></property> </bean> <!-- DAO接口所在包名,Spring會自動查找其下的類 --> <bean class='org.mybatis.spring.mapper.MapperScannerConfigurer'><property name='basePackage' value='com.chs.dao' /><property name='sqlSessionFactoryBeanName' value='sqlSessionFactory'></property> </bean> <!-- (事務管理)transaction manager, use JtaTransactionManager for global tx --> <bean class='org.springframework.jdbc.datasource.DataSourceTransactionManager'><property name='dataSource' ref='dataSource' /> </bean></beans>

spring-mvc.xml<?xml version='1.0' encoding='UTF-8'?><beans xmlns='http://www.springframework.org/schema/beans'

xmlns:mvc='http://www.springframework.org/schema/mvc' xmlns:context='http://www.springframework.org/schema/context'xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:p='http://www.springframework.org/schema/p'xsi:schemaLocation='http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd'><!-- 添加注解驅動 --><mvc:annotation-driven /><!-- 自動掃描該包,使SpringMVC認為包下用了@controller注解的類是控制器 --><context:component-scan base-package='com.chs.controller' use-default-filters='false'> <context:include-filter type='annotation'expression='org.springframework.stereotype.Controller' /></context:component-scan><!--避免IE執行AJAX時,返回JSON出現下載文件 --><bean class='org.springframework.http.converter.json.MappingJacksonHttpMessageConverter'> <property name='supportedMediaTypes'><list> <value>text/html;charset=UTF-8</value></list> </property></bean><!-- 啟動SpringMVC的注解功能,完成請求和注解POJO的映射 --><bean class='org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter'> <property name='messageConverters'><list> <ref bean='mappingJacksonHttpMessageConverter' /> <!-- JSON轉換器 --></list> </property></bean>

<bean class='org.springframework.web.servlet.view.InternalResourceViewResolver'> <property name='order' value='10'></property> <property name='prefix' value='/WEB-INF/page/'></property> <property name='suffix' value='.html'></property> <property name='contentType' value='text/html;charset=utf-8'></property></bean><!-- ===================================================== --><!-- ViewResolver For FreeMarker --><!-- ===================================================== --><bean class='org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver'> <property name='order' value='0' /> <property name='suffix' value='.html' /> <property name='contentType' value='text/html;charset=utf-8' /> <property name='viewClass'><value>org.springframework.web.servlet.view.freemarker.FreeMarkerView</value> </property></bean><!-- ===================================================== --><!-- ViewResolver For FreeMarkerConfigurer --><!-- ===================================================== --><bean class='org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer'> <property name='templateLoaderPath'><value>/WEB-INF/page/</value> </property> <property name='freemarkerSettings'><!-- 設置FreeMarker環境屬性 --><props> <prop key='template_update_delay'>5</prop><!--刷新模板的周期,單位為秒 --> <prop key='default_encoding'>UTF-8</prop><!--模板的編碼格式 --> <prop key='locale'>UTF-8</prop><!-- 本地化設置 --> <prop key='datetime_format'>yyyy-MM-dd HH:mm:ss</prop> <prop key='time_format'>HH:mm:ss</prop> <prop key='number_format'>0.####</prop> <prop key='boolean_format'>true,false</prop> <prop key='whitespace_stripping'>true</prop> <prop key='tag_syntax'>auto_detect</prop> <prop key='url_escaping_charset'>UTF-8</prop></props> </property></bean><!-- 處理靜態資源 --><mvc:resources mapping='/css/**/' location='/css/' /><mvc:resources mapping='/imgages/**/' location='/imgges/' /><mvc:resources mapping='/js/**/' location='/js/' /><!-- 文件上傳配置 --><bean class='org.springframework.web.multipart.commons.CommonsMultipartResolver'> <!-- 默認編碼 --> <property name='defaultEncoding' value='UTF-8' /> <!-- 上傳文件大小限制為31M,31*1024*1024 --> <property name='maxUploadSize' value='32505856' /> <!-- 內存中的最大值 --> <property name='maxInMemorySize' value='4096' /></bean>

</beans>

controller

package com.chs.controller;import java.util.Map;import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping;import com.chs.base.util.ReflectionUtil;import com.chs.model.User;import com.chs.service.IUserService; @Controller @RequestMapping('/user') public class UserController { @Resource private IUserService userService;@RequestMapping('/showUser') public String toIndex(HttpServletRequest request,Model model){ System.out.println('------------------------'); Map<String, Object> paramMap = ReflectionUtil.po2Map(request); User user = this.userService.getUserById(paramMap); return 'showUser'; } }

問題解答

回答1:

會不會是jsp里的請求路徑問題,建議試下改成絕對路徑試下

標簽: java
相關文章:
主站蜘蛛池模板: 日韩久久精品 | av日韩高清 | 日韩美女一区二区三区在线观看 | 99精品国自产在线 | 婷婷丁香在线视频 | 伊人91在线| 在线色网 | 91精品国产综合久久久动漫日韩 | 亚洲淫视频 | 成人免费看黄 | 亚洲精品视频在线 | 亚州精品天堂中文字幕 | 97人人超碰 | 久久久久久久一区二区三区 | 亚洲一一在线 | 国产精品一区二区久久精品爱微奶 | 日本一区二区不卡 | 一级毛片免费视频 | 成人午夜网站 | 狠狠干天天干 | 国产精品日日做人人爱 | 四虎影音| 久久久久免费精品国产 | 日韩中文av在线 | 免费在线黄色av | 国产精品一区三区 | 精品视频在线观看 | 国产黄色一级片 | 视频一区在线 | 中文字幕高清av | 无码一区二区三区视频 | 免费a大片| 欧美精品电影一区 | 国产精品99久久久久久动医院 | 国产成人精品999在线观看 | 久久久成人动漫 | 人人干人人干人人 | 国产精品区一区二区三区 | 日韩亚洲欧美综合 | 欧美精品久久久久久 | 天天躁日日躁性色aⅴ电影 免费在线观看成年人视频 国产欧美精品 |