springMVC的配置,请大神们看看,有没有哪里有问题,我用Model做返回类型的时候总是映射到URL

项目结构

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_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>xnb_web_api</display-name>

    <context-param>
		<param-name>webAppRootKey</param-name>
		<param-value>
			xnb_web_api.root
		</param-value>
	  </context-param> 

	  <welcome-file-list>
	     <welcome-file>/index.jsp</welcome-file>
	  </welcome-file-list>

	<!--********************************** log4j配置       ********************************** -->
	  <context-param>
	    <param-name>log4jConfigLocation</param-name>
	    <param-value>classpath:config/log4j.properties</param-value>
	  </context-param>
	  <context-param>
	    <param-name>log4jRefreshInterval</param-name>
	    <param-value>6000</param-value>
	  </context-param>
	  <listener>
	      <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
	  </listener>
	<!--********************************** log4j配置   ********************************** -->    

	 <!--********************************** spring配置   ********************************** -->
	  <context-param>
	    <param-name>contextConfigLocation</param-name>
	    <param-value>classpath:config/springConfig/*.xml</param-value>
	  </context-param>
	  <listener>
	    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	  </listener>

	  <servlet>
	    <servlet-name>xnb_web_api</servlet-name>
	    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
	    <init-param>
	      <param-name>contextConfigLocation</param-name>
	      <param-value>classpath:config/project-servlet.xml</param-value>
	    </init-param>
	    <init-param>
	      <param-name>encoding</param-name>
	      <param-value>UTF-8</param-value>
	    </init-param>
	    <load-on-startup>1</load-on-startup>
	  </servlet>
	  <servlet-mapping>
	    <servlet-name>xnb_web_api</servlet-name>
	    <url-pattern>/</url-pattern>
	  </servlet-mapping>
	<!--********************************** spring配置   ********************************** --> 

	<!-- **********************************  字符集过滤     ********************************************************* -->
	  <filter>
	    <filter-name>Set Character Encoding</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>Set Character Encoding</filter-name>
	    <url-pattern>/*</url-pattern>
	  </filter-mapping>
	<!-- **********************************  字符集过滤     ********************************************************* -->
	<!-- **********************************过滤器配置 **********************************-->
  	<filter>
  		<filter-name>loginCheck</filter-name>
  		<filter-class>com.moensun.xnbwebapi.filter.SessionCheck</filter-class>
  	</filter>
  	<filter-mapping>
  		<filter-name>loginCheck</filter-name>
  		<url-pattern>/*</url-pattern>
  	</filter-mapping>
   <!-- **********************************过滤器配置 **********************************-->
</web-app>

project-servlet.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-4.0.xsd
						       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
						       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-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/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
	  <context:annotation-config />
	  <mvc:annotation-driven />
<!-- ************************  把标记了@Controller注解的类转换为bean ************************ -->
      <context:component-scan base-package="com.moensun.xnbwebapi.controller">

      </context:component-scan>
<!-- ************************  把标记了@Controller注解的类转换为bean ************************ -->
      <mvc:resources mapping="/resources/**" location="/resources/"/> <!-- 静态文件 -->

 <!--*****************************************    中文乱码解决 以UTF8输出              *****************************************-->
	<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
	    <property name="messageConverters">
	        <list>
	            <ref bean="jsonHttpMessageConverter" />
	            <ref bean="stringHttpMessageConverter" />
	        </list>
	    </property>
	</bean>

	<!-- json -->
	<bean id="jsonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
		<property name="supportedMediaTypes" value="application/json" />
		<property name="objectMapper" ref="jacksonObjectMapper" />
	</bean>
	<bean id="jacksonObjectMapper" class="com.fasterxml.jackson.databind.ObjectMapper" />
	<bean id="jacksonSerializationConfig" class="com.fasterxml.jackson.databind.SerializationConfig" factory-bean="jacksonObjectMapper" factory-method="getSerializationConfig" />

	<!-- json -->
	<!-- string -->
	<bean id="stringHttpMessageConverter" class="org.springframework.http.converter.StringHttpMessageConverter">
		<property name="supportedMediaTypes">
			<list>
		      	<value>text/plain;charset=UTF-8</value>
		        <value>text/html;charset=UTF-8</value>
		        <value>application/json;charset=UTF-8</value>
			</list>
		</property>
	</bean>
	<!-- string -->
<!--*****************************************    中文乱码解决 以UTF8输出              *****************************************-->

<!-- *****************************   配置视图解释器    ***************************** -->
	<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
		<property name="mediaTypes">
		  <map>
		    <entry key="html" value="text/html"/>
		    <entry key="xml" value="text/xml"/>
		    <entry key="json" value="application/json"/>
		  </map>
		</property>
		<property name="defaultViews">
	    	<list>
	        	<bean class="org.springframework.web.servlet.view.json.MappingJackson2JsonView" />
	   		</list>
	    </property>
		<property name="viewResolvers">
		  <list>
		    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		      <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
		      <property name="prefix" value="/WEB-INF/views/"/>
		      <property name="suffix" value=".jsp"/>
		    </bean>
		  </list>
		</property>
	</bean>
<!-- *****************************   配置视图解释器    ***************************** -->  

</beans>						       

applicationContext.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:mvc="http://www.springframework.org/schema/mvc"
		xmlns:tx="http://www.springframework.org/schema/tx"
		xmlns:context="http://www.springframework.org/schema/context"
		xmlns:aop="http://www.springframework.org/schema/aop"
		xmlns:mongo="http://www.springframework.org/schema/data/mongo"
		xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
		                    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-34.0.xsd
		                    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/aop  http://www.springframework.org/schema/aop/spring-aop.xsd
		                   http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd">

	  <mvc:annotation-driven/>

      <context:component-scan base-package="com.moensun.xnbwebapi"></context:component-scan>  

<!--********************************************************    载入外部文件       ******************************************************** -->
	  <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
			<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
  			<property name="ignoreResourceNotFound" value="true" />
  			<property name="ignoreUnresolvablePlaceholders" value="true" />
			<property name="locations">
				<list>
					<value>classpath:config/dbConfig/db.properties</value>
				</list>
			</property>
	 </bean>
<!--********************************************************    载入外部文件       ******************************************************** -->

</beans>		                    

配置如上 ,代码如下

@Controller
@RequestMapping(value="user/")
public class UserController {
	@RequestMapping(value="login")
	public @ResponseBody  Model login(final Model model){
		model.addAttribute("1","2");
		return model;
	}
}

用Model这种返回方式,总是映射到URL上,我不知道哪里出了问题,同时是可以返回JSON的。有哪位大神遇到请帮我看下。

时间: 2024-08-01 04:06:00

springMVC的配置,请大神们看看,有没有哪里有问题,我用Model做返回类型的时候总是映射到URL的相关文章

jquery-图片轮播(新手请大神指教一下)

这是我刚学jquery写的,感觉效果不是很好. #scrollPics{ height: 330px; width: 980px; margin-bottom: 10px; overflow: hidden; position:relative;}.slider ul{ padding: 0px;}.slider ul li{ float: left; list-style: none; width: 980px;}.num{ position:absolute; right:5px; bott

理解C#语言中的类型转换----初学者的理解,请大神指教

一下都是在视频教学中学到后的理解,如果说错了请大神指教 C#语言中的类型转换,就是将某个数据要转换成另一个类型的数据. c#语言中的数据类型主要有: char类型(字符类型): string类型(字符串类型): int类型(整数类型): double类型(小数类型): 类型转换主要分为三种: 1:任意类型转换为string类型: 转换代码书写格式为:待转换的数据.Tostring(): a,这里的待转换的数据指的是需要转换的数据或变量.后面的Tostring():是固定书写. 转换完成后的返回类

实现一个对象验证库系列 -- 3) Fluent以及扩展方法实现 (请大神批评)

前情回顾: 上一篇 2) 验证器实现 简单描述了下验证器的简单实现 本文将说说Fluent方式的实现,欢迎大神们指点指点 3) Fluent以及扩展方法实现 我们按照之前 Fluent 的设想以及我们解耦的方式,所以我们先实现一个创建验证器创建者的静态类: public static class Validation { public static IValidatorBuilder<T> NewValidatorBuilder<T>() // 创建验证器创建者 { return

实现一个对象验证库系列 -- 2) 验证器实现 (请大神批评)

前情回顾: 上一篇 1) 接口介绍以及总体思路概述 简单描述了下库的代码结构 本文将说说验证器实现,欢迎大神指导更快更好的方案 2) 验证器实现 我们首先从用户调用的验证器开始实现,所以我们应该首先这样做 public class Validator : IValidator { public IValidateResult Validate(ValidateContext context) { } } 但是我们的验证器不是没有规则嘛?回忆一下我们好像是在为 Fluent 设计时添加了一个验证器

菜菜菜鸟学习之JavaWeb 入门1(自己的学习理解,不对之处请大神们多多指教啊)

一.相关基础知识 1.C/S(Client/Server)架构和B/S(Browser/Server)架构 首先说C/S架构,简单讲其实很常见,类似QQ等需要下载客户端的应用程序就是建立在C/S架构中.往深一点讲,它是分布式架构,每个客户端直接连接数据库服务器,并且数据的处理需要依赖客户端,所以说我们经常见到QQ用着用着就卡死了.这么一来,软件开发时选择C/S架构会出现以下问题: 1)所有客户端并发连接数据库,这直接限制客户端程序同时运行的数量. 2)需要安装,麻烦.(不过,这阻挡不了现在各种A

在下新手!练习shell脚本遇到一个问题请大神帮帮忙!

脚本信息: #!/bin/bash # MIAO=`history | tail -1 | cut -d' ' -f2` if        [ $MIAO -gt 1000 ]; then        echo "Some command will gone." else        echo "OK." fi   错误信息: [[email protected] practice]# ./text8.sh ./text8.sh: line 5: [: -gt

购物车 python作业 后面有些问题 请大神帮忙完善一下,谢谢哈

功能要求: 要求用户输入总资产,例如:2000显示商品列表,让用户根据序号选择商品,加入购物车购买,如果商品总额大于总资产,提示账户余额不足,否则,购买成功.附加:可充值.某商品移除购物车goods = [ {"name": "电脑", "price": 1999}, {"name": "鼠标", "price": 10}, {"name": "游艇&quo

请大神指导从大日志文件中统计关键字次数的办法

awk 'NR==FNR{a[$0]=1;next}{if($0 in a)b[$0]++}END{for (i in b)print i,b[i]}' filea fileb | sort 文件A中有若干行数据,每行为一个关键字文件B为大日志文件,大小为10G以下 想着能够统计出文件A中每个关键字在B中的出现次数,例如行1,3行2,10行3,100..... 最笨的办法是逐行读入后用grep,但是太费时间,有没有只打开一次B文件,就能把A中所有行都统计出来的办法呢? aaa 3 bbb 3 c

python 汉字编码问题,请大神帮忙!!

我用openpyxl写入汉字的时候,出现'BUSINESS\xb3\xa4\xb6\xc8\xd0\xa3\xd1\xe9\xce\xb4\xcd\xa8\xb9\xfd',这样的字符,就是不出现汉字.