Spring4-Thymeleaf-MyBatis整合Context文件

来源:互联网 发布:origin如何导出数据 编辑:程序博客网 时间:2024/06/05 18:29

Context文件内容:

<?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:p="http://www.springframework.org/schema/p"    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         http://mybatis.org/schema/mybatis-spring          http://mybatis.org/schema/mybatis-spring.xsd">    <!--Controller Service等组件包-->    <context:component-scan base-package="com.项目名" />    <!--springMCV 注解驱动-->    <mvc:annotation-driven enable-matrix-variables="true" />    <!-- spring原配置 -->    <!-- <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">         <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"         /> <property name="prefix" value="/WEB-INF/html位置/" /> <property name="suffix"         value=".html" /> </bean> -->    <!-- thymeleaf配置 -->    <!-- SpringResourceTemplateResolver automatically integrates with Spring's         own -->    <!-- resource resolution infrastructure, which is highly recommended. -->    <bean id="templateResolver"        class="org.thymeleaf.spring4.templateresolver.SpringResourceTemplateResolver">        <property name="prefix" value="/WEB-INF/html位置/" />        <property name="suffix" value=".html" />        <!-- 模板编码-重要!重要!! -->        <property name="characterEncoding" value="utf-8" />        <!-- HTML is the default value, added here for the sake of clarity. -->        <property name="templateMode" value="HTML" />        <!-- Template cache is true by default. Set to false if you want -->        <!-- templates to be automatically updated when modified. -->        <property name="cacheable" value="false" />    </bean>    <!-- SpringTemplateEngine automatically applies SpringStandardDialect and -->    <!-- enables Spring's own MessageSource message resolution mechanisms. -->    <bean id="templateEngine" class="org.thymeleaf.spring4.SpringTemplateEngine">        <property name="templateResolver" ref="templateResolver" />        <!-- Enabling the SpringEL compiler with Spring 4.2.4 or newer can speed             up -->        <!-- execution in most scenarios, but might be incompatible with specific -->        <!-- cases when expressions in one template are reused across different             data -->        <!-- ypes, so this flag is "false" by default for safer backwards -->        <!-- compatibility. -->        <property name="enableSpringELCompiler" value="true" />    </bean>    <bean class="org.thymeleaf.spring4.view.ThymeleafViewResolver">        <property name="templateEngine" ref="templateEngine" />        <!-- NOTE 'order' and 'viewNames' are optional <property name="order" value="1"             /> <property name="viewNames" value="*.html,*.xhtml" /> -->        <property name="characterEncoding" value="utf-8" />    </bean>    <!-- mybatis configure -->    <!-- c3p0 数据连接池 -->    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"        destroy-method="close">        <property name="driverClass" value="com.mysql.jdbc.Driver" />        <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/数据库名?serverTimezone=UTC" /><!-- 时区配置 重要 -->        <property name="user" value="用户名" />        <property name="password" value="密码" />    </bean>    <!-- mybatis会话配置 即xml映射配置 -->    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">        <property name="mapperLocations" value="classpath:com/xml映射位置/**/*.xml" />        <property name="dataSource" ref="dataSource" />    </bean>    <!-- mybatis DAO包接口配置 -->    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property         name="basePackage" value="com.DAO接口包位置.*"></property> <property         name="sqlSessionFactory" ref="sqlSessionFactory"></property> </bean></beans>
原创粉丝点击