Mybatis-Spring-SpringMVC-freemarker-PageHelper的整合
来源:互联网 发布:大数据存储技术 编辑:程序博客网 时间:2024/05/29 06:53
一.Mybatis的配置文件
在Resource目录下创建mybatis.xml
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"><configuration> <plugins> <!--在mybatis中配置拦截器插件--> <plugin interceptor="com.github.pagehelper.PageInterceptor"> <!--dialect 方言--> <!--<property name="dialect" value="mysql"/>--> <!--offsetAsPageNum:默认值为 false,该参数对使用 RowBounds 作为分页参数时有效。 当该参数设置为 true 时 ,会将 RowBounds 中的 offset 参数当成 pageNum 使用,可以用页码和页面大小两个参数进行分页。--> <property name="offsetAsPageNum" value="true"/> <!--rowBoundsWithCount:默认值为false,该参数对使用 RowBounds 作为分页参数时有效。 当该参数设置为true时, 使用 RowBounds 分页会进行 count 查询。--> <property name="rowBoundsWithCount" value="true"/> <!--pageSizeZero:默认值为 false,当该参数设置为 true 时,如果 pageSize=0 或者 RowBound s.limit = 0 就会查询出全部的结果(相当于没有执行分页查询,但是返回结果仍然是 Page 类型)。--> <property name="pageSizeZero" value="true"/> <!--reasonable:分页合理化参数,默认值为false。当该参数设置为 true 时,pageNum<=0 时会查询第一页, page Num>pages(超过总数时),会查询最后一页。默认false 时,直接根据参数进行查询。--> <property name="reasonable" value="true"/> <!--为了支持startPage(Object params)方法,增加了该参数来配置参数映射,用于从对象中根据属性名取值, 可以配置 pageN um,pageSize,count,pageSizeZero,reasonable,不配置映射的用默认值, 默认值为pageNum=pageNum;pageSize=pageSize;count=countSql;reasonable=reasonable;pageSizeZero=pageSizeZero。--> <property name="params" value="pageNum=start;pageSize=limit;"/> <!--支持通过 Mapper 接口参数来传递分页参数,默认值false,分页插件会从查询方法的参数值中,自动根据上面 params 配置的字段中取值,查找到合适 的值时就会自动分页。 使用方法可以参考测试代码中的 --> <property name="supportMethodsArguments" value="true"/> <!-- always总是返回PageInfo类型,check检查返回类型是否为PageInfo,none返回Page --> <property name="returnPageInfo" value="check"/> </plugin> </plugins> <!-- mapping 文件路径配置 --> <mappers> <mapper resource="UserMapper.xml" /> <mapper resource="FileMapper.xml" /> <mapper resource="AuthorMapper.xml"/> <mapper resource="CommentMapper.xml"/> </mappers></configuration>
二.Spring与mybatis的整合
在Resource目录下创建spring文件夹
依次创建spring-dao.xml,spring-service.xml,spring-web.xml
spring-dao.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" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="com.mysql.jdbc.Driver"/> <property name="url" value="jdbc:mysql://localhost:3306/day19"/> <property name="username" value="root"/> <property name="password" value="123456"/> <!-- 连接池启动时候的初始连接数 --> <property name="initialSize" value="10"/> <!-- 最小空闲值 --> <property name="minIdle" value="5"/> <!-- 最大空闲值 --> <property name="maxIdle" value="20"/> <property name="maxWait" value="2000"/> <!-- 连接池最大值 --> <property name="maxActive" value="50"/> <property name="logAbandoned" value="true"/> <property name="removeAbandoned" value="true"/> <property name="removeAbandonedTimeout" value="180"/> </bean> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="configLocation" value="classpath:mybatis.xml"/> <property name="dataSource" ref="dataSource"/> </bean> <bean id="UserDao" class="org.mybatis.spring.mapper.MapperFactoryBean"> <property name="mapperInterface" value="com.song.Mapper.UserDao"/> <property name="sqlSessionFactory" ref="sqlSessionFactory"/> </bean> <bean id="FileDao" class="org.mybatis.spring.mapper.MapperFactoryBean"> <property name="mapperInterface" value="com.song.Mapper.FileDao"/> <property name="sqlSessionFactory" ref="sqlSessionFactory"/> </bean> <bean id="AuthorDao" class="org.mybatis.spring.mapper.MapperFactoryBean"> <property name="mapperInterface" value="com.song.Mapper.AuthorDao"/> <property name="sqlSessionFactory" ref="sqlSessionFactory"/> </bean> <bean id="CommentDao" class="org.mybatis.spring.mapper.MapperFactoryBean"> <property name="mapperInterface" value="com.song.Mapper.CommentDao"/> <property name="sqlSessionFactory" ref="sqlSessionFactory"/> </bean></beans>
spring-service.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" 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.xsd"> <!--扫描service下所有使用注解的类型--> <context:component-scan base-package="com.song.service"/></beans>
spring-web.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.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"> <!--扫描到Controler包--> <context:component-scan base-package="com.song.web"/> <!--静态资源的处理--> <mvc:resources location="/statics/" mapping="/statics/**" /> <!--启用spring的一些annotation --> <context:annotation-config/> <mvc:annotation-driven/> <mvc:default-servlet-handler /> <bean class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer"> <property name="templateLoaderPath" value="WEB-INF/ftl/" /> <property name="defaultEncoding" value="UTF-8" /> </bean> <!-- freemarker视图解析器 --> <bean class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver"> <property name="suffix" value=".ftl" /> <property name="contentType" value="text/html;charset=UTF-8" /> <!-- 此变量值为pageContext.request, 页面使用方法:rc.contextPath --> <property name="requestContextAttribute" value="rc" /> </bean> <!--ViewResolver 视图解析器--> <!--用于支持Servlet、JSP视图解析--> <bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> <property name="prefix" value="/WEB-INF/jsp/"/> <property name="suffix" value=".jsp"/> </bean> <!--<bean id="defaultViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> <property name="prefix" value="/WEB-INF/templates/"/><!–设置JSP文件的目录位置–> <property name="suffix" value=".ftl"/> </bean>--> <bean id="viewResolver" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver"> <property name="cache" value="true" /> <property name="prefix" value="/WEN-INF/ftl" /> <property name="suffix" value=".ftl" /> <property name="contentType" value="text/html; charset=UTF-8"></property> <property name="viewClass"> <value>org.springframework.web.servlet.view.freemarker.FreeMarkerView </value> </property> </bean> <!--<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <!– 配置jsp路径的前缀 –> <property name="prefix" value="/WEB-INF/jsp/" /> <!– 配置jsp路径的后缀 –> <property name="suffix" value=".jsp" /> </bean>--> <!--扫描web相关的bean--> <!----></beans>
阅读全文
0 0
- Mybatis-Spring-SpringMVC-freemarker-PageHelper的整合
- spring+freemarker+springMvc+mybatis+maven整合
- SpringMVC-Spring-MyBatis-Freemarker整合+源码下载
- springMVC+MyBatis+freemarker整合
- Spring+SpringMVC+Mybatis+PageHelper+laypage+Ajax实现的分页
- Spring+SpringMVC+MyBatis的整合
- Spring+SpringMVC+Freemarker(自定义标签)+Mybatis+Log4j快速整合
- Spring+SpringMVC+Freemarker(自定义标签)+Mybatis+Log4j快速整合
- MAVEN_SPRING+SPRINGMVC+MYBATIS+FREEMARKER 整合
- spring整合mybatis逆向工程+PageHelper插件
- spring mvc+freemarker+mybatis整合
- Spring boot +freemarker+mybatis整合
- springmvc,mybatis,freemarker,maven-基于注解的整合
- Spring-SpringMVC-Mybatis整合
- springmvc+spring+mybatis整合
- springmvc+spring+mybatis整合
- Spring+SpringMVC+Mybatis整合
- springmvc+mybatis+spring整合
- 【一致性协议算法】2PC和3PC
- Unity入门操作_UGUI_InputFie_026
- html写动态时钟
- windows7+CUDA+Tensorflow-GPU+Anaconda
- 经典java算法大全
- Mybatis-Spring-SpringMVC-freemarker-PageHelper的整合
- 【Data_Structure笔记11】查找算法之【二叉排序树】
- 算出 20 天后是周几?并用 2012-01-20 的方式输出
- 小米系列真机调试代码时遇到小米系列手机调试Installation failed with message Failed to establish session
- 在Javascript中的一些数组的相关操作——初学者的一点小笔记
- 文章标题
- 51nod 1125[交换机器的最小代价]【贪心】
- Python笔记(十五)--模块
- 适合Java开发者学习的Python入门教程