springmvc mybatis集成配置示例

网友投稿 181 2023-07-06


springmvc mybatis集成配置示例

简单之美,springmvc,mybatis就是一个很好的简单集成方案,能够满足一般的项目需求。闲暇时间把项目配置文件共享出来,供大家参看:

1.首先我们来看下依赖的pom:

org.springframework

spring-core

${spring.version}

org.springframework

spring-beans

${spring.version}

org.springframework

spring-context

${spring.version}

org.springframework

spring-tx

${spring.version}

org.springframework

spring-web

${spring.version}

org.springframework

spring-webmvc

${spring.version}

org.springframework

spring-jdbc

${spring.version}

org.springframework

spring-test

${spring.version}

test

org.mybatis

mybatis

3.2.8

org.mybatis

mybatis-spring

1.2.2

mysql

mysql-connector-java

5.1.34

com.alibaba

druid

1.0.12

org.aspectj

aspectjweaver

1.8.4

http://

log4j

log4j

1.2.17

javax.servlet

servlet-api

3.0-alpha-1

javax.servlet

jstl

1.2

org.codehaus.jackson

jackson-mapper-asl

1.9.13

com.alibaba

fastjson

1.2.3

com.fasterxml.jackson.core

jackson-annotations

${jackson.version}

com.fasterxml.jackson.core

jackson-core

${jackson.version}

com.fasterxml.jackson.core

jackson-databind

commons-io

commons-io

2.4

commons-fileupload

commons-fileupload

1.2.2

spring 选用的是4.1.4的版本,根据系统需要我们可以选择自己适合的版本。

2.相关的配置文件:

a)spring.xml

xmlns:xsi="http://w3.org/2001/XMLSchema-instance" xmlns:context="http://springframework.org/schema/context"

xsi:schemaLocation="http://springframework.org/schema/beans

http://springframework.org/schema/beans/spring-beans-4.1.xsd

http://springframework.org/schema/context

http://springframework.org/schema/context/spring-context-4.1.xsd">

b)spring-mvc.xml

xmlns:mvc="http://springframework.org/schema/mvc" xmlns:xsi="http://w3.org/2001/XMLSchema-instance"

xmlns:p="http://springframework.org/schema/p" xmlns:context="http://springframework.org/schema/context"

xsi:schemaLocation="http://springframework.org/schema/beans

http://springframework.org/schema/beans/spring-beans-4.1.xsd

http://springframework.org/schema/context

http://springframework.org/schema/context/spring-context-4.1.xsd

http://springframework.org/schema/mvc

http://springframework.org/schema/mvc/spring-mvc-4.1.xsd">

class="org.springframework.http.converter.json.MappingJackson2HttpMessagggMogzXeConverter">

text/html;charset=UTF-8

class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">

class="org.springframework.web.servlet.view.InternalResourceViewResolver">

value="org.springframework.web.servlet.view.JstlView" />

c)spring-mybatis.xml

xmlns:xsi="http://w3.org/2001/XMLSchema-instance" xmlns:tx="http://springframework.org/schema/tx"

xmlns:aop="http://springframework.org/schema/aop"

xsi:schemaLocation="

http://springframework.org/schema/beans

httpggMogzX://springframework.org/schema/beans/spring-beans-4.1.xsd

http://springframework.org/schema/tx

http://springframework.org/schema/tx/spring-tx-4.1.xsd

http://springframework.org/schema/aop

http://springframework.org/schema/aop/spring-aop-4.1.xsd

">

init-method="init" destroy-method="close">

value="33" />

class="org.springframework.jdbc.datasource.DataSourceTransactionManager">

d)web.xml

springmvc_mybatis_demo

contextConfigLocation

classpath:spring.xml,classpath:spring-mybatis.xml

encodingFilter

org.springframework.web.filter.CharacterEncodingFilter

encoding

utf-8

forceEncoding

true

encodingFilter

/*

org.springframework.web.context.ContextLoaderListener

org.springframework.web.util.IntrospectorCleanupListener

spring mvc servlet

rest

org.springframework.web.servlet.DispatcherServlet

contextConfigLocation

classpath:spring-mvc.xml

1

rest

/

DruidStatView

com.alibaba.druid.support.http.StatViewServlet

DruidStatView

/druid/*

30

index.jsp

使用了druid的数据源,在web中的详细配置可以参看代码。

以上就是对springmvc mybatis集成配置的资料整理,后续继续补充相关资料,谢谢大家对本站的支持!

xmlns:xsi="http://w3.org/2001/XMLSchema-instance" xmlns:context="http://springframework.org/schema/context"

xsi:schemaLocation="http://springframework.org/schema/beans

http://springframework.org/schema/beans/spring-beans-4.1.xsd

http://springframework.org/schema/context

http://springframework.org/schema/context/spring-context-4.1.xsd">

b)spring-mvc.xml

xmlns:mvc="http://springframework.org/schema/mvc" xmlns:xsi="http://w3.org/2001/XMLSchema-instance"

xmlns:p="http://springframework.org/schema/p" xmlns:context="http://springframework.org/schema/context"

xsi:schemaLocation="http://springframework.org/schema/beans

http://springframework.org/schema/beans/spring-beans-4.1.xsd

http://springframework.org/schema/context

http://springframework.org/schema/context/spring-context-4.1.xsd

http://springframework.org/schema/mvc

http://springframework.org/schema/mvc/spring-mvc-4.1.xsd">

class="org.springframework.http.converter.json.MappingJackson2HttpMessagggMogzXeConverter">

text/html;charset=UTF-8

class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">

class="org.springframework.web.servlet.view.InternalResourceViewResolver">

value="org.springframework.web.servlet.view.JstlView" />

xmlns:mvc="http://springframework.org/schema/mvc" xmlns:xsi="http://w3.org/2001/XMLSchema-instance"

xmlns:p="http://springframework.org/schema/p" xmlns:context="http://springframework.org/schema/context"

xsi:schemaLocation="http://springframework.org/schema/beans

http://springframework.org/schema/beans/spring-beans-4.1.xsd

http://springframework.org/schema/context

http://springframework.org/schema/context/spring-context-4.1.xsd

http://springframework.org/schema/mvc

http://springframework.org/schema/mvc/spring-mvc-4.1.xsd">

class="org.springframework.http.converter.json.MappingJackson2HttpMessagggMogzXeConverter">

text/html;charset=UTF-8

class="org.springframework.http.converter.json.MappingJackson2HttpMessagggMogzXeConverter">

text/html;charset=UTF-8

class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">

class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">

class="org.springframework.web.servlet.view.InternalResourceViewResolver">

value="org.springframework.web.servlet.view.JstlView" />

class="org.springframework.web.servlet.view.InternalResourceViewResolver">

value="org.springframework.web.servlet.view.JstlView" />

value="org.springframework.web.servlet.view.JstlView" />

c)spring-mybatis.xml

xmlns:xsi="http://w3.org/2001/XMLSchema-instance" xmlns:tx="http://springframework.org/schema/tx"

xmlns:aop="http://springframework.org/schema/aop"

xsi:schemaLocation="

http://springframework.org/schema/beans

httpggMogzX://springframework.org/schema/beans/spring-beans-4.1.xsd

http://springframework.org/schema/tx

http://springframework.org/schema/tx/spring-tx-4.1.xsd

http://springframework.org/schema/aop

http://springframework.org/schema/aop/spring-aop-4.1.xsd

">

init-method="init" destroy-method="close">

value="33" />

class="org.springframework.jdbc.datasource.DataSourceTransactionManager">

d)web.xml

springmvc_mybatis_demo

contextConfigLocation

classpath:spring.xml,classpath:spring-mybatis.xml

encodingFilter

org.springframework.web.filter.CharacterEncodingFilter

encoding

utf-8

forceEncoding

true

encodingFilter

/*

org.springframework.web.context.ContextLoaderListener

org.springframework.web.util.IntrospectorCleanupListener

spring mvc servlet

rest

org.springframework.web.servlet.DispatcherServlet

contextConfigLocation

classpath:spring-mvc.xml

1

rest

/

DruidStatView

com.alibaba.druid.support.http.StatViewServlet

DruidStatView

/druid/*

30

index.jsp

使用了druid的数据源,在web中的详细配置可以参看代码。

以上就是对springmvc mybatis集成配置的资料整理,后续继续补充相关资料,谢谢大家对本站的支持!

xmlns:xsi="http://w3.org/2001/XMLSchema-instance" xmlns:tx="http://springframework.org/schema/tx"

xmlns:aop="http://springframework.org/schema/aop"

xsi:schemaLocation="

http://springframework.org/schema/beans

httpggMogzX://springframework.org/schema/beans/spring-beans-4.1.xsd

http://springframework.org/schema/tx

http://springframework.org/schema/tx/spring-tx-4.1.xsd

http://springframework.org/schema/aop

http://springframework.org/schema/aop/spring-aop-4.1.xsd

">

init-method="init" destroy-method="close">

value="33" />

init-method="init" destroy-method="close">

value="33" />

value="33" />

class="org.springframework.jdbc.datasource.DataSourceTransactionManager">

class="org.springframework.jdbc.datasource.DataSourceTransactionManager">

d)web.xml

springmvc_mybatis_demo

contextConfigLocation

classpath:spring.xml,classpath:spring-mybatis.xml

encodingFilter

org.springframework.web.filter.CharacterEncodingFilter

encoding

utf-8

forceEncoding

true

encodingFilter

/*

org.springframework.web.context.ContextLoaderListener

org.springframework.web.util.IntrospectorCleanupListener

spring mvc servlet

rest

org.springframework.web.servlet.DispatcherServlet

contextConfigLocation

classpath:spring-mvc.xml

1

rest

/

DruidStatView

com.alibaba.druid.support.http.StatViewServlet

DruidStatView

/druid/*

30

index.jsp

使用了druid的数据源,在web中的详细配置可以参看代码。

以上就是对springmvc mybatis集成配置的资料整理,后续继续补充相关资料,谢谢大家对本站的支持!


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:完整B树算法Java实现代码
下一篇:Bootstrap 3的box
相关文章

 发表评论

暂时没有评论,来抢沙发吧~