• ssm-freemarker-小众网配置


    •  上图的操作完成后,所说的如下图,其实是进行一个事务声明:
        1. <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        2. <property name="dataSource" ref="dataSource"/>
        3. bean>
        4. <tx:annotation-driven transaction-manager="transactionManager"/>

        applicationContext.xml

          1. "1.0" encoding="UTF-8"?>
          2. <beans xmlns="http://www.springframework.org/schema/beans"
          3. xmlns:mvc="http://www.springframework.org/schema/mvc"
          4. xmlns:context="http://www.springframework.org/schema/context"
          5. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          6. xmlns:tx="http://www.springframework.org/schema/tx"
          7. xmlns:task="http://www.springframework.org/schema/task"
          8. xsi:schemaLocation="
          9. http://www.springframework.org/schema/beans
          10. http://www.springframework.org/schema/beans/spring-beans.xsd
          11. http://www.springframework.org/schema/context
          12. http://www.springframework.org/schema/context/spring-context.xsd
          13. http://www.springframework.org/schema/task
          14. http://www.springframework.org/schema/task/spring-task.xsd
          15. http://www.springframework.org/schema/mvc
          16. http://www.springframework.org/schema/mvc/spring-mvc.xsd
          17. http://www.springframework.org/schema/tx
          18. http://www.springframework.org/schema/tx/spring-tx.xsd">
          19. <context:property-placeholder location="classpath:jdbc.properties"/>
          20. <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
          21. <property name="driverClassName" value="${jdbc.driver}"/>
          22. <property name="url" value="${jdbc.url}"/>
          23. <property name="username" value="${jdbc.username}"/>
          24. <property name="password" value="${jdbc.password}"/>
          25. <property name="initialSize" value="${jdbc.initialSize}"/>
          26. <property name="maxActive" value="${jdbc.maxActive}"/>
          27. bean>
          28. <bean class="org.mybatis.spring.SqlSessionFactoryBean">
          29. <property name="dataSource" ref="dataSource"/>
          30. <property name="mapperLocations" value="classpath:mapper/*.xml"/>
          31. <property name="configLocation" value="classpath:mybatis-config.xml"/>
          32. <property name="typeAliasesPackage" value="com.pro.domain"/>
          33. <property name="plugins">
          34. <array>
          35. <bean class="com.github.pagehelper.PageInterceptor">
          36. <property name="properties">
          37. <value>
          38. helperDialect=mysql
          39. value>
          40. property>
          41. bean>
          42. array>
          43. property>
          44. bean>
          45. <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
          46. <property name="basePackage" value="com.pro.dao"/>
          47. bean>
          48. <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
          49. <property name="dataSource" ref="dataSource"/>
          50. bean>
          51. <tx:annotation-driven transaction-manager="transactionManager"/>
          52. <context:component-scan base-package="com.pro"/>
          53. <mvc:annotation-driven/>
          54. <mvc:default-servlet-handler/>
          55. <bean id="FreeMarkerConfigurer" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
          56. <property name="templateLoaderPath" value="/WEB-INF/ftl"/>
          57. <property name="freemarkerSettings">
          58. <props>
          59. <prop key="defaultEncoding">UTF-8prop>
          60. props>
          61. property>
          62. bean>
          63. <bean id="viewResolver" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
          64. <property name="contentType" value="text/html.charset=utf-8"/>
          65. <property name="suffix" value=".ftl"/>
          66. bean>
          67. beans>

      • mybatis-config.xml

      •  
        1. "1.0" encoding="UTF-8" ?>
        2. configuration
        3. PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        4. "http://mybatis.org/dtd/mybatis-3-config.dtd">
        5. <configuration>
        6. <settings>
        7. <setting name="mapUnderscoreToCamelCase" value="true"/>
        8. settings>
        9. configuration>

    导入依赖,因为测试mybatis的相关配置是否成功,所以要导入两个测试相关的依赖,spring-test ,前端页面没用jsp了,用的是freemarker模板语言,所以要导依赖,

     注意当你要使用mybatis-plus的时候,低版本(2.3.6;1.3.2)的mybatis的两个依赖会冲突

    改成(3.5.7和2.0.3) 

    1. <packaging>warpackaging>
    2. <dependencies>
    3. <dependency>
    4. <groupId>org.springframeworkgroupId>
    5. <artifactId>spring-testartifactId>
    6. <version>5.2.16.RELEASEversion>
    7. dependency>
    8. <dependency>
    9. <groupId>junitgroupId>
    10. <artifactId>junitartifactId>
    11. <version>4.12version>
    12. dependency>
    13. <dependency>
    14. <groupId>org.springframeworkgroupId>
    15. <artifactId>spring-webmvcartifactId>
    16. <version>5.1.9.RELEASEversion>
    17. dependency>
    18. <dependency>
    19. <groupId>org.freemarkergroupId>
    20. <artifactId>freemarkerartifactId>
    21. <version>2.3.30version>
    22. dependency>
    23. <dependency>
    24. <groupId>org.springframeworkgroupId>
    25. <artifactId>spring-context-supportartifactId>
    26. <version>5.2.6.RELEASEversion>
    27. dependency>
    28. <dependency>
    29. <groupId>org.springframeworkgroupId>
    30. <artifactId>spring-jdbcartifactId>
    31. <version>5.1.9.RELEASEversion>
    32. dependency>
    33. <dependency>
    34. <groupId>org.mybatisgroupId>
    35. <artifactId>mybatisartifactId>
    36. <version>3.5.7version>
    37. dependency>
    38. <dependency>
    39. <groupId>org.mybatisgroupId>
    40. <artifactId>mybatis-springartifactId>
    41. <version>2.0.3version>
    42. dependency>
    43. <dependency>
    44. <groupId>com.alibabagroupId>
    45. <artifactId>druidartifactId>
    46. <version>1.1.14version>
    47. dependency>
    48. <dependency>
    49. <groupId>javax.servletgroupId>
    50. <artifactId>javax.servlet-apiartifactId>
    51. <version>3.1.0version>
    52. dependency>
    53. <dependency>
    54. <groupId>javax.servletgroupId>
    55. <artifactId>jsp-apiartifactId>
    56. <version>2.0version>
    57. dependency>
    58. <dependency>
    59. <groupId>mysqlgroupId>
    60. <artifactId>mysql-connector-javaartifactId>
    61. <version>5.1.49version>
    62. dependency>
    63. <dependency>
    64. <groupId>javax.servletgroupId>
    65. <artifactId>jstlartifactId>
    66. <version>1.2version>
    67. dependency>
    68. <dependency>
    69. <groupId>com.alibabagroupId>
    70. <artifactId>fastjsonartifactId>
    71. <version>1.2.47version>
    72. dependency>
    73. <dependency>
    74. <groupId>com.fasterxml.jackson.coregroupId>
    75. <artifactId>jackson-coreartifactId>
    76. <version>2.9.9version>
    77. dependency>
    78. <dependency>
    79. <groupId>com.fasterxml.jackson.coregroupId>
    80. <artifactId>jackson-annotationsartifactId>
    81. <version>2.9.9version>
    82. dependency>
    83. <dependency>
    84. <groupId>com.fasterxml.jackson.coregroupId>
    85. <artifactId>jackson-databindartifactId>
    86. <version>2.9.9version>
    87. dependency>
    88. <dependency>
    89. <groupId>com.github.jsqlparsergroupId>
    90. <artifactId>jsqlparserartifactId>
    91. <version>2.0version>
    92. dependency>
    93. <dependency>
    94. <groupId>com.github.pagehelpergroupId>
    95. <artifactId>pagehelperartifactId>
    96. <version>5.1.10version>
    97. dependency>
    98. <dependency>
    99. <groupId>ch.qos.logbackgroupId>
    100. <artifactId>logback-classicartifactId>
    101. <version>1.2.3version>
    102. dependency>
    103. dependencies>

    测试:

    • @RunWith注解的作用

      @RunWith就是一个运行器

      @RunWith(JUnit4.class)就是指用JUnit4来运行

      @RunWith(SpringJUnit4ClassRunner.class),让测试运行于Spring测试环境

      @RunWith(Suite.class)的话就是一套测试集合,
       

      1. package com.pro.service;
      2. import junit.framework.TestCase;
      3. import org.junit.Test;
      4. import org.junit.runner.RunWith;
      5. import org.springframework.beans.factory.annotation.Autowired;
      6. import org.springframework.test.context.ContextConfiguration;
      7. import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
      8. //测试的注解RunWith
      9. @RunWith(SpringJUnit4ClassRunner.class)
      10. @ContextConfiguration(locations = {"classpath:applicationContext.xml"})
      11. public class TestServiceTest extends TestCase {
      12. //因为我们是测试springMvc,所以需要通过注入的方式,故不能直接使用Junit来测试,
      13. @Autowired
      14. private TestService testService;
      15. @Test
      16. public void save(){
      17. com.pro.domain.Test t = new com.pro.domain.Test();
      18. t.setContent("测试xxxxx");
      19. testService.save(t);
      20. }
      21. }

      环境搭建的目录结构

  • 相关阅读:
    使用easyPOI导入excel转换为对象集合
    高级安装程序将应用程序转换为MSIX
    【微服务 Spring Cloud 3】云原生是实现可观测平台的唯一出路?码农:夸张了
    Steam项目推进(二)—— 在项目中使用FairyGUI
    人机交互中的数字与文字
    后台管理---删除功能
    『现学现忘』Git基础 — 17、Commit对象
    水力和水文软件介绍
    effective c++ 41 隐式接口和编译器多态
    基于TensorFlow+CNN+协同过滤算法的智能电影推荐系统——深度学习算法应用(含微信小程序、ipynb工程源码)+MovieLens数据集(四)
  • 原文地址:https://blog.csdn.net/qq_60555957/article/details/126675505