本節(jié)操作完成了對(duì)spring子容器的配置。
1、創(chuàng)建源代碼和配置文件所在目錄
- 創(chuàng)建java文件夾,設(shè)置為Sources Root,具體操作如下圖所示:
創(chuàng)建源代碼和配置文件的目錄
2、創(chuàng)建各層package
- 創(chuàng)建controller
- 創(chuàng)建service
- 創(chuàng)建mapper
- 創(chuàng)建entity
具體操作如下圖所示:
創(chuàng)建controller、service、mapper、entity包
3、在resources中創(chuàng)建springmvc.xml
具體操作如下圖所示:
創(chuàng)建springmvc.xml
4、修改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/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!--掃描controller層-->
<context:component-scan base-package="net.wanho.controller"></context:component-scan>
<!--以標(biāo)簽的方式創(chuàng)建處理器映射器以及處理器適配器-->
<mvc:annotation-driven></mvc:annotation-driven>
<bean id="mappingJacksonHttpMessageConverter"
class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/html;charset=UTF-8</value>
</list>
</property>
</bean>
<!-- 啟動(dòng)Spring MVC的注解功能,完成請(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>
</beans>
至此,我們完成了對(duì)spring子容器的配置。