我是靠谱客的博主 个性墨镜,最近开发中收集的这篇文章主要介绍SSM框架纯手写xml模板SSM框架纯手写xml代码模板,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

SSM框架纯手写xml代码模板

1.结构图

注意颜色:java根目录为蓝色,配置文件右下角黄色,测试资源绿色,前端项目文件图标有个蓝点
在这里插入图片描述

2.后端

2.1配置类

2.1.1 applicationContext.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.xsd">

    <!--对应controller-->
    <import resource="classpath:spring-mvc.xml"></import>

    <!--对应service-->
    <import resource="classpath:spring-config.xml"></import>

    <!--对应dao-->
    <import resource="classpath:spring-mybatis.xml"></import>

</beans>
2.1.2 database.properties
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/ssm_maven?useSSL=true&useUnicode=true&characterEncoding=utf8
jdbc.username=root
jdbc.password=root
2.1.3 mybatis-config.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>

    <typeAliases>
        <package name="com.bright.pojo"/>
    </typeAliases>

   <!-- mapper实现类装配入接口-->
    <mappers>
        <mapper resource="com/bright/dao/BookMapper.xml"/>
    </mappers>

</configuration>
2.1.4 spring-config.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:tx="http://www.springframework.org/schema/tx"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
                        http://www.springframework.org/schema/beans/spring-beans.xsd
                        http://www.springframework.org/schema/tx
                        http://www.springframework.org/schema/tx/spring-tx.xsd
                        http://www.springframework.org/schema/aop
                        https://www.springframework.org/schema/aop/spring-aop.xsd">

    <!--注册业务类实现类-->
    <bean id="bookServiceImpl" class="com.bright.service.BookServiceImpl">
        <property name="bookMapper" ref="bookMapper"/>
    </bean>

    <!-- 配置事务管理器 -->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <!-- 注入数据库连接池 -->
        <property name="dataSource" ref="dataSource"/>
    </bean>

    <!-- 事务的配置 -->
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
        <!--在 tx:advice 标签内部 配置事务的属性 -->
        <tx:attributes>
            <tx:method name="*" read-only="false" propagation="REQUIRED"/>
            <tx:method name="find*" read-only="true" propagation="SUPPORTS"/>
            <tx:method name="query*" read-only="true" propagation="SUPPORTS"/>
        </tx:attributes>
    </tx:advice>
    <!-- 配置 aop -->
    <aop:config>
        <!-- 配置切入点表达式 -->
        <aop:pointcut expression="execution(* com.bright.service.*.*(..))" id="pt1"/>
        <aop:advisor advice-ref="txAdvice" pointcut-ref="pt1"/>
    </aop:config>

    <!--如果是在业务层使用绑定,需要开启注解驱动
    <tx:annotation-driven transaction-manager="transactionManager" />-->

   <!--自定义切面-->
    <bean id="myAspect" class="com.bright.tools.MyAspect"/>
    <aop:config>
        <aop:pointcut id="myPoint"  expression="execution(* com.bright.service.*Impl.*(..))"/>
        <aop:aspect id="myAspect" ref="myAspect" >
            <aop:around  method="aroundAdvice" pointcut-ref="myPoint"/>
        </aop:aspect>
    </aop:config>
</beans>
2.1.5 spring-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
                        http://www.springframework.org/schema/context/spring-context.xsd
                        http://www.springframework.org/schema/mvc
                        https://www.springframework.org/schema/mvc/spring-mvc.xsd">
    <!-- 1.开启SpringMVC的注解驱动,(1)注册映射器,(2)注册适配器 (3)可以在bean里面使用注解 -->
    <mvc:annotation-driven>
        <!--解决json和java对象之间的转换乱码-->
        <mvc:message-converters register-defaults="false">
            <!-- 避免string类型直接解析成json-->
            <bean class="org.springframework.http.converter.StringHttpMessageConverter"/>
            <!-- 避免IE执行AJAX时,返回JSON出现下载文件 -->
            <bean id="fastJsonHttpMessageConverter" class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
                <property name="supportedMediaTypes">
                    <list>
                        <!-- 这里顺序不能反,一定先写text/html,不然ie下出现下载提示 -->
                        <value>text/html;charset=UTF-8</value>
                        <value>application/json;charset=UTF-8</value>
                    </list>
                </property>
            </bean>
        </mvc:message-converters>
    </mvc:annotation-driven>

    <!-- 2.扫描web相关的bean-->
    <context:component-scan base-package="com.bright.controller" />

    <!-- 3.静态资源过滤-->
    <mvc:default-servlet-handler/>
    <!--如果你所有的Web应用服务器的默认Servlet名称不是"default",则需要通过default-servlet-name属性显示指定:
    <mvc:default-servlet-handler default-servlet-name="所使用的Web服务器默认使用的Servlet名称" />-->

    <!-- 4.配置ViewResolver视图解析器 -->
    <bean 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>

    <!--5.拦截器,防止未登录人员进入-->
    <mvc:interceptors>
        <mvc:interceptor>
            <mvc:mapping path="/**"/>
            <bean class="com.bright.interceptor.LoginInterceptor"/>
        </mvc:interceptor>
    </mvc:interceptors>
    <!--
       /    拦截的是除了.jsp外的所有请求
       /*  是拦截所有当前的文件夹,不包含子文件夹
       /** 是拦截所有的文件夹及里面的子文件夹
    -->
    <!--文件上传配置-->
    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <!-- 请求的编码格式,必须和jSP的pageEncoding属性一致,以便正确读取表单的内容,
        默认为ISO-8859-1 -->
        <property name="defaultEncoding"

最后

以上就是个性墨镜为你收集整理的SSM框架纯手写xml模板SSM框架纯手写xml代码模板的全部内容,希望文章能够帮你解决SSM框架纯手写xml模板SSM框架纯手写xml代码模板所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(60)

评论列表共有 0 条评论

立即
投稿
返回
顶部