您的位置:首页 > 编程语言 > Java开发

Spring MVC + Mybatis 配置文件模板

2013-11-26 16:49 417 查看
用来用去还是CSDN好

1.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_2_5.xsd"

xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">

<display-name>dw.spring3.rest</display-name>

<welcome-file-list>

<welcome-file>index.html</welcome-file>

</welcome-file-list>

<!-- The context params that read by ContextLoaderListener -->

<context-param>

<param-name>contextConfigLocation</param-name>

<param-value>

/WEB-INF/rest-context.xml

</param-value>

</context-param>

<!-- This listener will load other application context file in addition to springweb-servlet.xml -->

<listener>

<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

</listener>

<!-- Default load servletName_servlet.xml in WEB-INF -->

<servlet>

<servlet-name>rest</servlet-name>

<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

<load-on-startup>1</load-on-startup>

</servlet>

<servlet-mapping>

<servlet-name>rest</servlet-name>

<url-pattern>/service/*</url-pattern>

</servlet-mapping>

<jsp-config>

<taglib>

<taglib-uri>http://java.sun.com/jsp/jstl/core</taglib-uri>

<taglib-location>/WEB-INF/tags/c.tld</taglib-location>

</taglib>

</jsp-config>

</web-app>

二.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: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.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

<context:component-scan base-package="dw.spring3.rest.controller" />

<mvc:annotation-driven />

<!-- To enable @RequestMapping process on type level and method level

<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />

<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />-->

<bean id="jaxbMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">

<property name="classesToBeBound">

<list>

<value>dw.spring3.rest.bean.Employee</value>

<value>dw.spring3.rest.bean.EmployeeList</value>

</list>

</property>

</bean>

<!-- XML View Output -->

<bean id="employees" class="org.springframework.web.servlet.view.xml.MarshallingView">

<constructor-arg ref="jaxbMarshaller" />

</bean>

<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">

<property name="mediaTypes">

<map>

<entry key="xml" value="application/xml"/>

<entry key="html" value="text/html"/>

</map>

</property>

<property name="viewResolvers">

<list>

<bean class="org.springframework.web.servlet.view.BeanNameViewResolver"/>

<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">

<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>

<property name="prefix" value="/WEB-INF/jsp/"/>

<property name="suffix" value=".jsp"/>

</bean>

</list>

</property>

</bean>

</beans>

三、mybatis Mapper

<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"

"http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="com.isoftstone.securityframework.AccountMapper">

<resultMap id="baseResult"

type="xxxx.Account">

<id property="id" column="id" />

<result property="accountId" column="ACCOUNTID" />

<association property="creator" column="id"

javaType="xxxx.Account"

select="getCreator" />

<collection property="accountExts" javaType="ArrayList"

column="id" ofType="xxxx.AccountExt"

select="queryAccountExts" />

</resultMap>

</mapper>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: