色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

您的位置:首頁技術(shù)文章
文章詳情頁

java - springmvc 無法掃描到controller層

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

問題描述

各種404,請(qǐng)求/user/showUser不能進(jìn)入controller,整了一天,快瘋了,求組各位大神!直接上代碼項(xiàng)目結(jié)構(gòu):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的相關(guān)配置內(nèi)容配置到Spring的配置文件applicationContext.xml中,共享同一個(gè)配置文件即可 --> <context-param><param-name>contextConfigLocation</param-name><param-value>classpath:applicationContext.xml</param-value> </context-param> <!-- Spring 監(jiān)聽器 配置 --> <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 配置,配置文件名稱默認(rèn)為{servlet-name}-servlet.xml,路徑默認(rèn)在/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 /> <!-- 自動(dòng)掃描 --> < <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><!-- 連接池最大數(shù)量 --><property name='maxActive' value='${maxActive}'></property><!-- 連接池最大空閑 --><property name='maxIdle' value='${maxIdle}'></property><!-- 連接池最小空閑 --><property name='minIdle' value='${minIdle}'></property><!-- 獲取連接最大等待時(shí)間 --><property name='maxWait' value='${maxWait}'></property> </bean> <!-- spring和MyBatis完美整合,不需要mybatis的配置映射文件 --> <bean class='org.mybatis.spring.SqlSessionFactoryBean'><property name='dataSource' ref='dataSource' /><!-- 自動(dòng)掃描mapping.xml文件 --><property name='mapperLocations' value='classpath:mybatisMappingConfig/*.xml'></property> </bean> <!-- DAO接口所在包名,Spring會(huì)自動(dòng)查找其下的類 --> <bean class='org.mybatis.spring.mapper.MapperScannerConfigurer'><property name='basePackage' value='com.chs.dao' /><property name='sqlSessionFactoryBeanName' value='sqlSessionFactory'></property> </bean> <!-- (事務(wù)管理)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'><!-- 添加注解驅(qū)動(dòng) --><mvc:annotation-driven /><!-- 自動(dòng)掃描該包,使SpringMVC認(rèn)為包下用了@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執(zhí)行AJAX時(shí),返回JSON出現(xiàn)下載文件 --><bean class='org.springframework.http.converter.json.MappingJacksonHttpMessageConverter'> <property name='supportedMediaTypes'><list> <value>text/html;charset=UTF-8</value></list> </property></bean><!-- 啟動(dòng)SpringMVC的注解功能,完成請(qǐng)求和注解POJO的映射 --><bean class='org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter'> <property name='messageConverters'><list> <ref bean='mappingJacksonHttpMessageConverter' /> <!-- JSON轉(zhuǎn)換器 --></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'><!-- 設(shè)置FreeMarker環(huán)境屬性 --><props> <prop key='template_update_delay'>5</prop><!--刷新模板的周期,單位為秒 --> <prop key='default_encoding'>UTF-8</prop><!--模板的編碼格式 --> <prop key='locale'>UTF-8</prop><!-- 本地化設(shè)置 --> <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><!-- 處理靜態(tài)資源 --><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'> <!-- 默認(rèn)編碼 --> <property name='defaultEncoding' value='UTF-8' /> <!-- 上傳文件大小限制為31M,31*1024*1024 --> <property name='maxUploadSize' value='32505856' /> <!-- 內(nèi)存中的最大值 --> <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:

會(huì)不會(huì)是jsp里的請(qǐng)求路徑問題,建議試下改成絕對(duì)路徑試下

標(biāo)簽: java
相關(guān)文章:
主站蜘蛛池模板: 成年人免费小视频 | 成人国产在线观看 | 成人午夜久久精品 | 久久久久免费视频 | 国产毛片一级 | 国产一区二 | 爽死你个放荡粗暴小淫货双女视频 | 女人成午夜大片7777在线 | 日韩综合 | 在线视频观看免费视频18 | 99草精品视频 | 国产午夜在线观看视频播放 | 欧美人成毛片在线播放 | 欧洲欧美成人免费大片 | 亚洲国产区 | 久草视频免费在线播放 | 日韩在线视频一区二区三区 | 拍拍拍又黄又爽无挡视频免费 | 欧美aaa视频| 国产三级精品美女三级 | 怡红院免费在线视频 | 亚洲综合网在线观看首页 | 久久久久琪琪去精品色村长 | 亚洲人成在线免费观看 | 日本国产免费一区不卡在线 | 精品在线看 | 男女同床爽爽视频免费 | 亚洲国产成人在线视频 | 91久久香蕉国产线看 | 国产亚洲精品久久综合影院 | 日韩国产精品99久久久久久 | 成人123| 男女国产一级毛片 | 国产精品秦先生手机在线 | 亚洲精品一区二区手机在线 | 亚洲国产精品综合久久 | 日韩在线视频不卡一区二区三区 | 5388国产亚洲欧美在线观看 | 日本天堂网在线 | 久久骚 | 极品丝袜高跟91白沙发在线 |