SSM搭建流程

第一步勾选这两个
在这里插入图片描述
这里是项目名可以随便写,点击next
在这里插入图片描述
选择到你的maven,继续next
在这里插入图片描述
这是你创建项目的位置
在这里插入图片描述
然后在pom.xml中导入SSM依赖
在这里插入图片描述
dao层下面写mapper接口,resources下面放mappers文件夹,mappers文件夹里面放mapper的配置文件
在这里插入图片描述
然后配置spring的配置文件在这里插入图片描述

<!--开启全局注解扫描-->
    <context:component-scan base-package="cn.kgc"/>

    <!--引入配置文件-->
    <context:property-placeholder location="classpath*:db.properties"/>

    <!--配置数据源-->
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <property name="user" value="${username}"/>
        <property name="driverClass" value="${driver}"/>
        <property name="password" value="${password}"/>
        <property name="jdbcUrl" value="${url}"/>
    </bean>

    <!--配置会话工厂-->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <!--设置别名-->
        <property name="typeAliasesPackage" value="cn.kgc.ssm.pajo"/>
        <!--映射mapper文件-->
        <property name="mapperLocations" value="classpath*:mappers/*Mapper.xml"/>
    </bean>

    <!--扫描dao层-->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="cn.kgc"/>
    </bean>

    <!--事务控制-->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource/"/>
    </bean>

    <!--创建声明式事务-->
    <tx:advice transaction-manager="transactionManager" id="txAdvice">
        <tx:attributes>
            <!--针对不同的方法做出不同的事务策略-->
            <tx:method name="*" propagation="REQUIRED" timeout="-1"/>
        </tx:attributes>
    </tx:advice>

    <!--将控制融入到代码中-->
    <aop:config>
        <aop:advisor advice-ref="txAdvice" pointcut="execution(* cn.kgc.ssm.service.*.*(..))"/>
    </aop:config>

然后配置springmvc的配置文件
在这里插入图片描述
然后配置web.xml SSM的基本框架基本就搭建完了

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
  http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
  <display-name>Archetype Created Web Application</display-name>

  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath*:applicationContext.xml</param-value>
  </context-param>
  <servlet>
    <servlet-name>springmvc</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath*:applicationContext-mvc.xml</param-value>
    </init-param>
  </servlet>
  <servlet-mapping>
    <servlet-name>springmvc</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>
  <!--过滤器-->
  <filter>
    <filter-name>encodingFilter</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <init-param>
      <param-name>encoding</param-name>
      <param-value>UTF-8</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>encodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
</web-app>
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值