Construir e integrar rapidamente uma estrutura de projeto SSM (apenas para iniciantes)?

~Construção do quadro de integração do MUS (pontos-chave)

Prefácio

SSM: Spring, SpringMVC, Mybatis

1. Introdução à primavera

  • Em 2002, foi lançado o primeiro protótipo do Spring. O framework Spring foi baseado na interface21. Após redesenho e enriquecimento contínuo de sua conotação, a versão oficial 1.0 foi lançada em 24 de março de 2004.
  • Rod Johnson , fundador do Spring Framework e autor famoso
  • Conceito Spring: Torna as tecnologias existentes mais fáceis de usar.É uma mistura que integra estruturas tecnológicas existentes.

2.Introdução ao SpringMVC

  • Spring MVC é um produto subsequente do SpringFrameWork e foi integrado ao Spring Web Flow.
  • A estrutura Spring fornece um módulo MVC completo para construir aplicativos da Web.
  • O framework Spring MVC desconhece as visualizações utilizadas, portanto não obriga a usar apenas a tecnologia JSP. Spring MVC separa as funções de controladores, objetos de modelo, despachantes e objetos manipuladores, tornando-os mais fáceis de personalizar.

3.Introdução ao Mybatis

  • MyBatis é uma excelente estrutura de camada de persistência que oferece suporte a SQL personalizado, procedimentos armazenados e mapeamento avançado.
  • MyBatis evita quase todo código JDBC e configuração manual de parâmetros e obtenção de conjuntos de resultados.
  • MyBatis pode usar XML simples ou anotações para configuração e mapas nativos para mapear interfaces e Java POJOs (Plain Old Java Objects, objetos Java comuns) em registros no banco de dados.

做一个SSM项目,步骤如下

1. Analise as necessidades

Antes de mais nada, saiba que tipo de projeto você quer fazer, e deixe claro o que você quer fazer

2. Projetar banco de dados

Projete as tabelas e campos utilizados no projeto de acordo com os requisitos

3. Crie um projeto Maven

Você pode criar o Maven diretamente com a ferramenta IDEA e selecionar o modelo webapp ou criar um projeto Maven vazio e clicar com o botão direito em Adicionar e adicionar webapp.

  • Importe dependências (importe dependências de acordo com sua situação, apenas para referência!)
		<!--测试junit-->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
        <!--MySQL数据库驱动-->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.19</version>
        </dependency>
        <!--c3p0连接池-->
        <dependency>
            <groupId>com.mchange</groupId>
            <artifactId>c3p0</artifactId>
            <version>0.9.5.5</version>
        </dependency>


        <!--servlet.jsp-->
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>javax.servlet.jsp-api</artifactId>
            <version>2.3.3</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.1</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.web</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>


        <!--mybatis-->
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>3.5.0</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
            <version>2.0.1</version>
        </dependency>
        <!--逆向工程-->
        <dependency>
            <groupId>org.mybatis.generator</groupId>
            <artifactId>mybatis-generator-core</artifactId>
            <version>1.4.0</version>
        </dependency>


        <!--Spring-->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>5.3.0</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>5.3.0</version>
        </dependency>

		<dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>5.3.0</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>5.3.0</version>
        </dependency>
  		<dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>5.3.0</version>
        </dependency>    
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
            <version>5.3.0</version>
        </dependency> 
         <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-expression</artifactId>
            <version>5.3.0</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>5.3.0</version>
        </dependency>
        
         <!--aop-->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
            <version>5.3.0</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aspects</artifactId>
            <version>5.3.0</version>
        </dependency>
        
        <!--orm-->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>5.3.0</version>
        </dependency>
        
		<!--事务-->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>5.3.0</version>
        </dependency>

		 <!--thymeleaf-->
        <dependency>
            <groupId>org.thymeleaf</groupId>
            <artifactId>thymeleaf</artifactId>
            <version>3.0.11.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.thymeleaf</groupId>
            <artifactId>thymeleaf-spring5</artifactId>
            <version>3.0.11.RELEASE</version>
        </dependency>

		 <!--jackson-->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.11.3</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>2.11.3</version>
        </dependency>
        <dependency>

            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <version>2.11.3</version>
        </dependency>

		<!--fileupload 上传-->
        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
            <version>1.4</version>
        </dependency>

        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.2</version>
        </dependency>
        
         <!-- ehcache核心jar包 -->
        <dependency>
            <groupId>net.sf.ehcache</groupId>
            <artifactId>ehcache-core</artifactId>
            <version>2.6.11</version>
        </dependency>
        <!-- MyBatis与ehcache整合jar包 -->
        <dependency>
            <groupId>org.mybatis.caches</groupId>
            <artifactId>mybatis-ehcache</artifactId>
            <version>1.2.1</version>
        </dependency>
        
        <!--小辣椒-->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.2</version>
        </dependency>


         <!--静态导出问题-->
    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
                <filtering>false</filtering>
            </resource>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
                <filtering>false</filtering>
            </resource>
        </resources>
    </build>
  • Escreva os pacotes que serão usados ​​(apenas para referência!)
    -
4. Escreva db.properties e conecte-se ao banco de dados
user=root
password=root
#如果使用的是Mysql8.0+,增加一个时区的配置
url=jdbc:mysql://localhost:3306/student?useSSl=true&useUnicode=true&characterEncoding=utf8
driver=com.mysql.jdbc.Driver
5. Escreva o arquivo de configuração principal applicationContext.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>

    <!--配置mybatis自带日志-->
    <settings>
        <!--用STDOUT_LOGGING显示sql语句-->
        <setting name="logImpl" value="STDOUT_LOGGING"/>

        <setting name="lazyLoadingEnabled" value="true"/>
        <!-- 每个属性按需要加载 -->
        <setting name="aggressiveLazyLoading" value="false"/>

        <!--开启二级缓存-->
        <setting name="cacheEnabled" value="true"/>
    </settings>

    <typeAliases>
        <!--这里给实体类去别名,方便在mapper配置文件中使用-->
        <package name="com.qianfeng.entity.User"/>
    </typeAliases>

</configuration>
6. Escreva o código da interface da camada dao
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface UserDao {
    
    

    List<User> getAll();

    User getOne(Integer id);

    int delete(Integer id);

    int update(User user);

    int add(User user);

    int checkUserName(String username);

}

7. Escreva Mapper.xml (implemente a interface e use CRUD para operar o banco de dados)

~ Apenas para referência!

<?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 写的就是接口的全类名-->
<mapper namespace="com.qianfeng.dao.UserDao">

    <select id="getAll" resultType="User">

        select * from user

    </select>

    <select id="getOne" resultType="User" databaseId="Integer">

        select * from user where id=#{id}

    </select>

    <delete id="delete" parameterType="integer">

        delete from user where id=#{id}

    </delete>

    <insert id="add" parameterType="User">

        insert into user
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name!=null and name!=&quot;&quot;">
                name,
            </if>
            <if test="username!=null">
                username,
            </if>
            <if test="password!=null">
                password,
            </if>
            <if test="age &gt;=0 and age&lt;=150">
                age,
            </if>
            <if test="gender!=null">
                gender,
            </if>
            <if test="birth!=null">
                birth
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name!=null and name != &quot;&quot;">
                #{name,jdbcType=VARCHAR},
            </if>
            <if test="username!=null">
                #{username,jdbcType=VARCHAR},
            </if>
            <if test="password!=null">
                #{password,jdbcType=VARCHAR},
            </if>
            <if test="age &gt;=0 and age &lt;=150">
                #{age,jdbcType=INTEGER},
            </if>
            <if test="gender!=null">
                #{gender,jdbcType=VARCHAR},
            </if>
            <if test="birth!=null">
                #{birth,jdbcType=DATE}
            </if>
        </trim>


    </insert>

    <update id="update" parameterType="User">

        update user
        <set>
            <if test="name!=null and name!=&quot;&quot;">
                name = #{name,jdbcType=VARCHAR},
            </if>
            <if test="age &gt;=0 and age &lt;=150">
                age = #{age,jdbcType=INTEGER},
            </if>
            <if test="gender!=null">
                gender = #{gender,jdbcType=VARCHAR},
            </if>
            <if test="birth!=null">
                birth = #{birth,jdbcType=DATE}
            </if>
        </set>
        where id=#{id,jdbcType=INTEGER}

    </update>


    <select id="checkUserName" parameterType="string" resultType="int">

        select count(*) from user where username=#{username};

    </select>


    <!--联合唯一去重-->
    <select id="removeCoincidence" resultType="Boolean">

         alter ignore table radar_region_coincidence add unique index(parent_radar_id,radar_id);
        SELECT COUNT(1) as '查询数量' from user GROUP BY parent_radar_id,radar_id;

    </select>

</mapper>
8. Escreva o arquivo de configuração de mybatis.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.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">


    <!--扫包-->
    <context:component-scan base-package="com.qianfeng.dao"/>

    <!--1.关联数据库配置文件 property-placeholder 文件占位-->
    <context:property-placeholder location="classpath:db.properties"/>

    <!--2.数据库连接池
    dbcp:半自动化操作,不能自动化连接
    c3p0:自动化操作(自动化的加载配置文件,并且可以自动设置到对象中!)
    druid(德鲁伊):hikari:
    -->
    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
        <property name="username" value="${user}"/>
        <property name="password" value="${password}"/>
        <property name="url" value="${url}"/>
        <property name="driverClassName" value="${driver}"/>


        <!-- 连接池其他属性 -->
        <!--第一次连接初始化-->
        <property name="initialSize" value="100" />
        <!--最大连接池数量-->
        <property name="maxActive" value="1000" />
        <!--最大等待时间,单位毫秒-->
        <property name="maxWait" value="60000" />
        <!--连接保持空闲而不被驱逐的最长时间-->
        <property name="minEvictableIdleTimeMillis" value="300000" />
        <!--连接池中的minIdle数量以内的连接,空闲时间超过minEvictableIdleTimeMillis,则会执行keepAlive操作-->
        <property name="keepAlive" value="true"/>
        <!--有两个含义:
1) Destroy线程会检测连接的间隔时间,如果连接空闲时间大于等于minEvictableIdleTimeMillis则关闭物理连接 2) testWhileIdle的判断依据,详细看testWhileIdle属性的说明-->
        <property name="timeBetweenEvictionRunsMillis" value="-1" />
        <!--最小连接池数量-->
        <property name="minIdle" value="20" />
        <!--要求程序从池中get到连接后, N 秒后必须close,否则druid 会强制回收该连接,不管该连接中是活动还是空闲, 以防止进程不会进行close而霸占连接。-->
        <property name="removeAbandoned" value="true"/>
        <!--设置druid 强制回收连接的时限,当程序从池中get到连接开始算起,超过此值后,druid将强制回收该连接,单位秒。-->
        <property name="removeAbandonedTimeout" value="180"/>
        <!--当druid强制回收连接后,是否将stack trace 记录到日志中-->
        <property name="logAbandoned" value="true" />
        <!--建议配置为true,不影响性能,并且保证安全性。申请连接的时候检测,如果空闲时间大于timeBetweenEvictionRunsMillis,执行validationQuery检测连接是否有效。-->
        <property name="testWhileIdle" value="true" />
        <!--用来检测连接是否有效的sql,要求是一个查询语句,常用select 'x'。如果validationQuery为null,testOnBorrow、testOnReturn、testWhileIdle都不会起作用。-->
        <property name="validationQuery" value="SELECT 'x'" />
        <!--申请连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能。-->
        <property name="testOnBorrow" value="false" />
        <!--归还连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能。-->
        <property name="testOnReturn" value="false" />
        <!--是否缓存preparedStatement,也就是PSCache。PSCache对支持游标的数据库性能提升巨大,比如说oracle。在mysql下建议关闭。-->
        <property name="poolPreparedStatements" value="true"/>
        <!--要启用PSCache,必须配置大于0,当大于0时,poolPreparedStatements自动触发修改为true。在Druid中,不会存在Oracle下PSCache占用内存过多的问题,可以把这个数值配置大一些,比如说100-->
        <property name="maxPoolPreparedStatementPerConnectionSize" value="20"/>
        <!--属性类型是字符串,通过别名的方式配置扩展插件,常用的插件有:
        监控统计用的filter:stat
        日志用的filter:log4j
        防御sql注入的filter:wall-->
        <property name="filters" value="stat,wall,slf4j"/>
        <!--连接属性。比如设置一些连接池统计方面的配置。-->
        <property name="connectionProperties" value="druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000" />
    </bean>


    <!--3.配置mybatis  sqlsessionfactory  -->

    <!--SqlSessionFactoryBean来替代SqlSessionFactoryBuilder来创建SqlSession;利用mybatis映射文件**.xml来配置-->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">

        <!-- SqlSessionFactoryBean有一个必须属性dataSource-->
        <property name="dataSource" ref="dataSource"/>

        <!--扫描pojo包,给包下所有pojo对象起别名-->
        <property name="typeAliasesPackage" value="com.qianfeng.entity"/>

        <!-- 当mybatis的xml文件和mapper接口不在相同包下时,需要用mapperLocations属性指定xml文件的路径。*是个通配符,代表所有的文件,**代表所有目录下 -->
        <property name="mapperLocations" value="classpath:mappers/*.xml"/>

        <!--(用来指定mybatis的xml配置文件路径),绑定mybatis-config.xml文件-->
        <property name="configLocation" value="classpath:mybatis-config.xml"/>
    </bean>

    <!--4.在springmvc与mybatis整合时,需要对每一个mapper定义对应的一个MapperFactoryBean,
    可以使用MapperScannerConfigurer自动扫描mapper,然后自动为我们注册对应的MapperFactoryBean对象。-->
    <!--动态实现dao接口可以注入到Spring容器中-->
    <bean id="mapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">

        <property name="sqlSessionFactoryBeanName" value="sqlSession"/>

        <!--basePackage表示需要扫描的包,annotationClass表示需要扫描该包下有该的注解的类。-->
        <property name="basePackage" value="com.qianfeng.dao"/>

    </bean>

</beans>
9. Escreva a configuração do 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"
       xmlns:tx="http://www.springframework.org/schema/tx"

       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/config ">


    <!--1.扫service下的包-->
    <context:component-scan base-package="com.qianfeng.service"/>

    <!--2.spring  提供的  datasource  平台事务管理器(用做切面切点)--><!--配置声明式事务  -->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
       <!--注入数据源-->
        <property name="dataSource" ref="dataSource"/>
    </bean>

    <!--3.结合aop实现事务的植入-->
    <!--配置事务通知-->
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
        <tx:attributes>
            <tx:method name="add" propagation="REQUIRED"/>
            <tx:method name="delete" propagation="REQUIRED"/>
            <tx:method name="update" propagation="REQUIRED"/>
            <tx:method name="query" read-only="true"/>
            <tx:method name="*" propagation="REQUIRED"/>
        </tx:attributes>
    </tx:advice>
    

    <!--开启事务注解-->
    <tx:annotation-driven transaction-manager="transactionManager"/>
</beans>
10.Escreva o arquivo de configuração web.xml em WEB-INF
<!DOCTYPE web-app PUBLIC
        "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
        "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
    <display-name>Archetype Created Web Application</display-name>


    <!--声明应用范围(整个WEB项目)内的上下文初始化参数。-->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:spring-*.xml</param-value>
    </context-param>


    <!--字符编码过滤器-->
    <filter>
        <filter-name>CharacterEncodingFilter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <!-- init-param 的param-name 就是参数名  param-value就是参数值, 支持多个参数-->
        <init-param>
            <param-name>encoding</param-name>
            <param-value>utf-8</param-value>
        </init-param>
    </filter>


    <!--Restful过滤器  使得支持GET、POST、PUT与DELETE请求-->
    <filter>
        <filter-name>HiddenHttpMethodFilter</filter-name>
        <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>CharacterEncodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <filter-mapping>
        <filter-name>HiddenHttpMethodFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>


    <!--监听器-->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>


    <!--DispatcherServlet 前端控制器-->
    <servlet>
        <servlet-name>DispatcherServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:spring-web.xml</param-value>
        </init-param>
    </servlet>

    <!--<url-pattern>:指定相对于Servlet的URL的路径。该路径相对于web应用程序上下文的根路径。
    <servlet-mapping>将URL模式映射到某个Servlet,即该Servlet处理的URL。-->

    <!--servlet的映射路径,-->
    <servlet-mapping>
        <servlet-name>DispatcherServlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <!--设置session的失效时间,以分钟为单位-->
    <session-config>
        <session-timeout>15</session-timeout>
    </session-config>

</web-app>
11. Grave o arquivo de configuração mvc.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.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd http://www.alibaba.com/schema/stat http://www.alibaba.com/schema/stat.xsd http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd">


    <!--1.扫包-->
    <context:component-scan base-package="com.qianfeng.controller"/>


    <!--2.注解驱动:annotation-driven配置帮助我们挖成上述两个实例的注入,代替之前的适配器和映射器的开启的配置-->
    <mvc:annotation-driven/>

    
    <!--3.处理静态资源过滤-->
    <mvc:default-servlet-handler/>


    <!--4.MVC模板中添加    thymeleaf模板解析器-->
    <bean id="templateResolver" class="org.thymeleaf.spring5.templateresolver.SpringResourceTemplateResolver">
        <property name="characterEncoding" value="utf-8"/>
        <property name="templateMode" value="HTML"/>
        <!--不使用缓存-->
        <property name="cacheable" value="false"/>
        <property name="suffix" value=".html"/>
        <property name="prefix" value="/"/>
    </bean>

    <!--5.模板引擎配置-->
    <bean id="templateEngine" class="org.thymeleaf.spring5.SpringTemplateEngine">
        <property name="templateResolver" ref="templateResolver"/>

    </bean>

    <!--6.配置视图处理器-->
    <bean class="org.thymeleaf.spring5.view.ThymeleafViewResolver">
        <property name="characterEncoding" value="utf-8"/>
        <property name="templateEngine" ref="templateEngine"/>
    </bean>

</beans>

Atualmente, a estrutura SSM foi configurada e começamos a escrever código de lógica de negócios.


~Espero que possa ajudá-lo e resolver seu problema

~~~感谢您的光临~~~

Acho que você gosta

Origin blog.csdn.net/m0_50762431/article/details/117528051
Recomendado
Clasificación