搭建SSM框架

2023-10-29

项目结构

在这里插入图片描述

1、SSM框架依赖

  <!-- 设置变量 -->
  <properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <maven.compiler.compileVersion>1.8</maven.compiler.compileVersion>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <spring.version>4.2.4.RELEASE</spring.version>
    <mybatis.version>3.4.5</mybatis.version>
    <slf4j.version>1.7.25</slf4j.version>
    <log4j.version>1.2.17</log4j.version>
  </properties>

  <dependencies>
    <!-- 单元测试 -->
    <!-- https://mvnrepository.com/artifact/junit/junit -->
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.13-rc-2</version>
      <scope>test</scope>
    </dependency>

    <!-- java ee -->
    <!-- https://mvnrepository.com/artifact/javax/javaee-api -->
    <dependency>
      <groupId>javax</groupId>
      <artifactId>javaee-api</artifactId>
      <version>8.0.1</version>
      <scope>provided</scope>
    </dependency>

    <!-- spring框架 -->
    <!-- https://mvnrepository.com/artifact/org.springframework/spring-core -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-core</artifactId>
      <version>4.2.4.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-beans</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-oxm</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-tx</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-jdbc</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-aop</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context-support</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-expression</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-orm</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-web</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-webmvc</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <!-- mybatis框架包 start -->
    <!-- https://mvnrepository.com/artifact/org.mybatis/mybatis -->
    <dependency>
      <groupId>org.mybatis</groupId>
      <artifactId>mybatis</artifactId>
      <version>3.4.6</version>
    </dependency>

    <dependency>
      <groupId>org.mybatis</groupId>
      <artifactId>mybatis-spring</artifactId>
      <version>1.3.1</version>
    </dependency>

    <!-- pageHelper分页插件 -->
    <!-- https://mvnrepository.com/artifact/com.github.pagehelper/pagehelper -->
    <dependency>
      <groupId>com.github.pagehelper</groupId>
      <artifactId>pagehelper</artifactId>
      <version>5.1.11</version>
    </dependency>
    <!-- jsqlparser -->
    <!-- https://mvnrepository.com/artifact/com.github.jsqlparser/jsqlparser -->
    <dependency>
      <groupId>com.github.jsqlparser</groupId>
      <artifactId>jsqlparser</artifactId>
      <version>3.1</version>
    </dependency>

    <!-- 数据库驱动 -->
    <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>5.1.48</version>
    </dependency>


    <!-- 导入dbcp的jar包,用来在applicationContext.xml中配置数据库 -->
    <dependency>
      <groupId>commons-dbcp</groupId>
      <artifactId>commons-dbcp</artifactId>
      <version>1.4</version>
    </dependency>
    <!-- jstl标签类 -->
    <dependency>
      <groupId>jstl</groupId>
      <artifactId>jstl</artifactId>
      <version>1.2</version>
    </dependency>
    <!-- log start -->
    <dependency>
      <groupId>log4j</groupId>
      <artifactId>log4j</artifactId>
      <version>${log4j.version}</version>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
      <version>${slf4j.version}</version>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-log4j12</artifactId>
      <version>${slf4j.version}</version>
    </dependency>
    <!-- log END -->
    <!-- Json  -->
    <!-- 格式化对象,方便输出日志 -->
    <dependency>
      <groupId>com.alibaba</groupId>
      <artifactId>fastjson</artifactId>
      <version>1.2.6</version>
    </dependency>
    <dependency>
      <groupId>org.codehaus.jackson</groupId>
      <artifactId>jackson-mapper-asl</artifactId>
      <version>1.9.13</version>
    </dependency>

    <!-- servlet -->
    <!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>4.0.1</version>
      <scope>provided</scope>
    </dependency>

    <!-- jsp -->
    <!-- https://mvnrepository.com/artifact/javax.servlet/jsp-api -->
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>jsp-api</artifactId>
      <version>2.0</version>
      <scope>provided</scope>
    </dependency>



    <!-- jackson -->
    <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-databind</artifactId>
      <version>2.5.4</version>
    </dependency>


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


    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-annotations</artifactId>
      <version>2.5.4</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.aspectj/aspectjweaver -->
    <dependency>
      <groupId>org.aspectj</groupId>
      <artifactId>aspectjweaver</artifactId>
      <version>1.9.6</version>
    </dependency>



    <!-- 上传组件包 start -->
    <dependency>
      <groupId>commons-fileupload</groupId>
      <artifactId>commons-fileupload</artifactId>
      <version>1.3.1</version>
    </dependency>
    <dependency>
      <groupId>commons-io</groupId>
      <artifactId>commons-io</artifactId>
      <version>2.4</version>
    </dependency>
    <dependency>
      <groupId>commons-codec</groupId>
      <artifactId>commons-codec</artifactId>
      <version>1.10</version>
    </dependency>

  </dependencies>
  <build>
    <plugins>
      <!-- tomcat插件控制 -->
      <plugin>
        <groupId>org.apache.tomcat.maven</groupId>
        <artifactId>tomcat7-maven-plugin</artifactId>
        <version>2.2</version>
        <configuration>
          <port>8080</port>
          <path>/</path>
          <ignorePackaging>true</ignorePackaging>
        </configuration>
      </plugin>
    </plugins>
  </build>

2、spring.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"
       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/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">

    <!--1.写一个注解加载扫描器-->
    <context:component-scan base-package="com.wxk"/>
    <!--2.引入外部属性文件-->
    <context:property-placeholder location="classpath:db.properties"/>
    <!--3.注入数据源-->
    <!--文件在spring-jdbc包中-->
    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="${jdbc.driver}"/>
        <property name="url" value="${jdbc.url}"/>
        <property name="username" value="${jdbc.username}"/>
        <property name="password" value="${jdbc.password}"/>
    </bean>
    <!--4.写一个sqlSessionFactory-->
    <!--文件在mybatis-spring包中-->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <!--注入数据源-->
        <property name="dataSource" ref="dataSource"/>
        <!--取别名-->
        <property name="typeAliasesPackage" value="com.wxk.vo"/>
        <!--加载mapper文件-->
        <property name="mapperLocations" value="classpath:mapper/*Mapper.xml"/>
        <!--使用pagehelper插件实现分页-->
        <property name="plugins">
            <array>
                <bean class="com.github.pagehelper.PageInterceptor">
                    <property name="properties">
                        <value>
                            helperDialect=mysql
                            reasonable=true
                        </value>
                    </property>
                </bean>
            </array>
        </property>
    </bean>
    <!--5.生成dao层代理-->
    <!--文件在mybatis-spring包中-->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <!--需要dao包-->
        <property name="basePackage" value="com.wxk.dao"/>
    </bean>
    <!--6.使用spring声明事务-->
    <!--写一个事务管理器,就是切面类-->
    <!--文件在spring-jdbc包中,id规定为transactionManager-->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <!--注入DataSource-->
        <property name="dataSource" ref="dataSource"/>
    </bean>
    <!--使用注解方式管理事务-->
    <tx:annotation-driven transaction-manager="transactionManager"/>
    <!--支持注解的aop-->
    <aop:aspectj-autoproxy/>
</beans>

2.1、在spring中引入的数据库文件db.properties
db.properties

3、mybatis.xml

这个文件可以不需要,相关映射关系可以在spring.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>
  
  <mappers>
    <mapper resource="mapper/MyMapper.xml"/>
  </mappers>
</configuration>

4、springmvc.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 http://www.springframework.org/schema/mvc/spring-mvc.xsd">

    <!--写一个扫描器只扫描Controller-->
    <context:component-scan base-package="com.wxk.controller"/>
    <!--开启注解加载器(处理器映射器和处理器适配器)-->
    <mvc:annotation-driven/>
    <!--写一个视图解析器-->
    <!--类在spring-webmvc包中-->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <!--前缀-->
        <property name="prefix" value="/page/"/>
        <!--后缀-->
        <property name="suffix" value=".jsp"/>
    </bean>

</beans>

5、映射文件MyMapper.xml

<?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="com.wxk.dao.StationDao">
    <select id="getStations" resultType="com.wxk.vo.Station">
        select * from tb_station
    </select>
</mapper>

6、web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
         version="4.0">

  <!--配置前端控制器-->
  <servlet>
    <servlet-name>springmvc</servlet-name>
    <!--路径在spring-webmvc包中-->
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath:springmvc.xml</param-value>
    </init-param>
    <!--第一时间加载-->
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>springmvc</servlet-name>
    <url-pattern>*.do</url-pattern>
  </servlet-mapping>
  <!--执行spring容器-->
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:spring.xml</param-value>
  </context-param>
  <!--写一个监听-->
  <listener>
    <!--类在spring-web包中-->
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  <!--处理post中文乱码-->
  <filter>
    <filter-name>encodingFilter</filter-name>
    <!--类在spring-web包中-->
    <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>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

搭建SSM框架 的相关文章

随机推荐

  • pandas基本操作

    df转csv文件 df to csv df转excel文件 df to excel df增加列 df insert df column name data df增加行 df append df合并 df concat df索引行或者列 df
  • Qt自定义QWidget

    Qt自定义QWidget 实例1 电池 实例2 plot绘图 实例3 plot按比例绘图 实例1 电池 promotion pro QT core gui greaterThan QT MAJOR VERSION 4 QT widgets
  • 好玩的整固代码,你学会了吗?

    Win系统下 今天装机之家教你使用一行代码就可以让电脑卡的死机 可以发给朋友整蛊一下 友情提示 整蛊有的度 不要把别人惹恼了 代码 0 0 将这5个字符复制到记事本上 以bat格式保存 将这个BAT发给其他朋友让他点击试试 保证不过一会你的
  • vue3 + element plus 自定义验证规则(两个表单必填其中一个)

    element plus 表单 自定义验证规则 const validateCustom rule any value any callback any gt if contactsForm value mobile contactsFor
  • 快速上手MongoDB和Python交互

    一 安装 导入 pip install pymongo from pymongo import MongoClient MongoDB 默认没有用户名密码 二 连接数据库 方式一 client MongoClient host localh
  • InputStream转MultipartFile

    import org apache commons fileupload FileItem import org apache commons fileupload FileItemFactory import org apache com
  • 获取iOS项目名称及版本号的方法

    NSDictionary infoDictionary NSBundle mainBundle infoDictionary CFShow infoDictionary app名称 NSString app Name infoDiction
  • systemd 之 journalctl

    原文地址 https www cnblogs com itxdm p Systemd log system journalctl html Systemd 日志系统 一 前言 昨天写了一篇文章 内容为 Systemd 常规操作与彩蛋 参考了
  • JSP+Servlet实现的HR人力资源管理系统】

    基于JSP Servlet实现的HR人力资源管理系统 演示地址 http yanshi ym4j com hr01 用户名 123456 密码 123456下载地址 基于JSP Servlet实现的HR人力资源管理系统 源码世界 项目采用J
  • Python实现独热编码

    关于独热编码与哑变量编码的概念 可以参考 https blog csdn net qq 41853758 article details 81252174 离散特征的编码分为两种情况 1 离散特征的取值之间没有大小的意义 比如color r
  • 信息化工程监理规范_赛迪工程咨询出席监理企业信息化管理和智慧化服务现场经验交流会...

    7月21日 中国建设监理协会主办的 监理企业信息化管理和智慧化服务现场经验交流会 在西安召开 来自全国200余名会员代表参加会议 住房和城乡建设部建筑市场监管司副司长卫明 陕西省住房和城乡建设厅副厅长茹广生 中国建设监理协会会长王早生出席会
  • 一文看懂MySQL中order by排序语句的原理

    order by 是怎么工作的 表定义 CREATE TABLE t1 id int 11 NOT NULL city varchar 16 NOT NULL name varchar 16 NOT NULL age int 11 NOT
  • osg 嵌入Qt 窗口

    osg嵌入Qt窗口完整代码的一个示例 include
  • C++ primer 第四版 目录(仅供参考)

    目录 第1章 快速入门 1 1 编写简单的C 程序 1 2 初窥输入 输出 1 3 关于注释 1 4 控制结构 入 1 5 类的简介 1 6 C 程序 小结 术语 第一部分 基本语言 第2章 变量和基本类型 2 1 基本内置类型 2 2 字
  • 【需求解决系列之四】Android App在线自动更新Library(V2.0)

    前言 其实每个Android App都应该有一个App在线更新的功能 这样才能及时的通知用户去更新最新版本的App 这个功能其实说起来比较简单 因为流程大家都懂 但是要真正的实现 还是要考虑很多东西的 因为项目的需要 对之前已经开源的库做了
  • Python将图片嵌入Excel单元格(仿嵌入)

    欢迎来到Python办公自动化专栏 Python处理办公问题 解放您的双手 博客主页 一晌小贪欢的博客主页 该系列文章专栏 Python办公自动化专栏 文章作者技术和水平有限 如果文中出现错误 希望大家能指正 欢迎各位佬关注 昨天接到一个需
  • C++之继承

    目录 继承的概念及定义 继承的概念 继承定义 定义格式 继承方式 继承基类成员访问方式的变化 基类和派生类对象赋值转换 切片 切割 继承中的作用域 派生类的默认成员函数 构造函数和析构函数 拷贝构造函数和赋值重载 继承和友元 继承与静态成员
  • 【C++】在子类中怎么调用父类的方法

    2023年8月31日 周四上午 目录 使用父类作用域运算符 子类没有重写父类方法时 子类重写了父类方法时 使用this指针调用 子类没有重写父类方法时 在C 中 子类可以以以下几种方式调用父类的方法 使用父类作用域运算符 这种方法既可以在子
  • 谷歌浏览器启动后,图标变成空白解决办法

    谷歌浏览器启动后 图标变成空白 如下图 解决方法 新建一个文本文档 把如下代码复制进去 并保存 修改这个文本文档的后缀名改为 bat 点击运行即可 taskkill f im explorer exeattrib h i userprofi
  • 搭建SSM框架

    项目结构 1 SSM框架依赖