首先贴出配置文件:
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="/schema/beans"xmlns:xsi="/2001/XMLSchema-instance" xmlns:context="/schema/context"xmlns:mvc="/schema/mvc"xsi:schemaLocation="/schema/beans/schema/beans/spring-beans.xsd/schema/context/schema/context/spring-context.xsd/schema/mvc/schema/mvc/spring-mvc.xsd"><!-- 添加注解驱动(启动spring-mvc注解驱动) --><mvc:annotation-driven/><!-- 扫描web相关的bean @Controller--><context:component-scan base-package="com.six.controller"/><!-- 配置一个检察员对进入DispatcherServlet的URL进行检查,如果是静态资源交给WEB应用服务器默认的Servlet处理如果不是静态资源继续交给DispatcherServlet处理--><mvc:default-servlet-handler/><!-- 定义跳转的文件的前后缀 ,视图模式配置 --><bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"><property name="prefix" value="/WEB-INF/jsp/"/><property name="suffix" value=".jsp"/></bean><!-- 配置返回json类型的数据开始 --><beanclass="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"><property name="messageConverters"><list><ref bean="jsonHttpMessageConverter"/></list></property></bean><bean id="jsonHttpMessageConverter"class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"><property name="supportedMediaTypes"><list><value>application/json;charset=UTF-8</value></list></property></bean><!-- 配置返回json类型的数据结束 --></beans>
Schema是对XML文档结构的定义和描述,其主要的作用是用来约束XML文件,并验证XML文件有效性。
xmlns是 xml namespace的缩写也就是XML的命名空间,xmlns属性可以在文档中定义一个或者多个可供选择的命名空间。
xmlns="/schema/beans"<!--默认的命名空间,表示未使用其他命名空间的所有标签的默认命名空间-->
xmlns:xsi="/2001/XMLSchema-instance"<!--xsi标准命名空间,用于指定自定义命名空间的schema文件,声明之后就可以使用schemaLocation属性了-->