• 整合SSM(Mybatis-Spring-SpringMVC层)


    环境:

    • IDEA

    • MySQL 5.7.19

    • Tomcat 9

    • Maven 3.6

    (1)数据库环境

    创建一个存放书籍数据的数据库表,需要注意是一个行模块进行执行,不要全部一起,会报错

    1. CREATE DATABASE `ssmbuild`;
    2. USE `ssmbuild`;
    3. DROP TABLE IF EXISTS `books`;
    4. CREATE TABLE `books` (
    5. `bookID` INT(10) NOT NULL AUTO_INCREMENT COMMENT '书id',
    6. `bookName` VARCHAR(100) NOT NULL COMMENT '书名',
    7. `bookCounts` INT(11) NOT NULL COMMENT '数量',
    8. `detail` VARCHAR(200) NOT NULL COMMENT '描述',
    9. KEY `bookID` (`bookID`)
    10. ) ENGINE=INNODB DEFAULT CHARSET=utf8
    11. INSERT INTO `books`(`bookID`,`bookName`,`bookCounts`,`detail`)VALUES
    12. (1,'Java',1,'从入门到放弃'),
    13. (2,'MySQL',10,'从删库到跑路'),
    14. (3,'Linux',5,'从进门到进牢');

    基本环境搭建  

    (2)新建一Maven项目!ssmbuild

    (3)导入相关的pom依赖  

    1. <dependencies>
    2. <dependency>
    3. <groupId>junitgroupId>
    4. <artifactId>junitartifactId>
    5. <version>4.12version>
    6. dependency>
    7. <dependency>
    8. <groupId>mysqlgroupId>
    9. <artifactId>mysql-connector-javaartifactId>
    10. <version>5.1.47version>
    11. dependency>
    12. <dependency>
    13. <groupId>com.mchangegroupId>
    14. <artifactId>c3p0artifactId>
    15. <version>0.9.5.5version>
    16. dependency>
    17. <dependency>
    18. <groupId>javax.servletgroupId>
    19. <artifactId>servlet-apiartifactId>
    20. <version>2.5version>
    21. dependency>
    22. <dependency>
    23. <groupId>javax.servlet.jspgroupId>
    24. <artifactId>jsp-apiartifactId>
    25. <version>2.2version>
    26. dependency>
    27. <dependency>
    28. <groupId>javax.servletgroupId>
    29. <artifactId>jstlartifactId>
    30. <version>1.2version>
    31. dependency>
    32. <dependency>
    33. <groupId>org.mybatisgroupId>
    34. <artifactId>mybatisartifactId>
    35. <version>3.5.9version>
    36. dependency>
    37. <dependency>
    38. <groupId>org.mybatisgroupId>
    39. <artifactId>mybatis-springartifactId>
    40. <version>2.0.6version>
    41. dependency>
    42. <dependency>
    43. <groupId>org.springframeworkgroupId>
    44. <artifactId>spring-webmvcartifactId>
    45. <version>5.3.19version>
    46. dependency>
    47. <dependency>
    48. <groupId>org.springframeworkgroupId>
    49. <artifactId>spring-jdbcartifactId>
    50. <version>5.3.19version>
    51. dependency>
    52. <dependency>
    53. <groupId>org.projectlombokgroupId>
    54. <artifactId>lombokartifactId>
    55. <version>1.18.24version>
    56. dependency>
    57. dependencies>

     (4)maven资源过滤设置

    1. <build>
    2. <resources>
    3. <resource>
    4. <directory>src/main/javadirectory>
    5. <includes>
    6. <include>**/*.propertiesinclude>
    7. <include>**/*.xmlinclude>
    8. includes>
    9. <filtering>falsefiltering>
    10. resource>
    11. <resource>
    12. <directory>src/main/resourcesdirectory>
    13. <includes>
    14. <include>**/*.propertiesinclude>
    15. <include>**/*.xmlinclude>
    16. includes>
    17. <filtering>falsefiltering>
    18. resource>
    19. resources>
    20. build>

    (5)连接数据库  

    设置时间区域(版本过低的需要!)

    输入账户密码,测试是否成功!  

    选择创建的数据库(ssmbuild)

     

    (6)建立基本结构和配置框架  

    • com.gt.pojo

    • com.gt.mapper

    • com.gt.service

    • com.gt.controller

    • 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. configuration>

    • applicationContext.xml  
    1. "1.0" encoding="UTF-8"?>
    2. <beans xmlns="http://www.springframework.org/schema/beans"
    3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    4. xsi:schemaLocation="http://www.springframework.org/schema/beans
    5. http://www.springframework.org/schema/beans/spring-beans.xsd&
  • 相关阅读:
    WKWebKit总结
    20220929-ArrayList扩容机制源码分析
    【新版】系统架构设计师 - 软件架构设计<轻量级架构>
    提升绘图效率不再难,看看这8款AI流程图软件,一键快速生成流程图!
    Android 12,调用系统库libft2.so 遇到的各种问题记录
    Django配合python进行requests请求
    springboot中如何集成logback呢?
    【微信小程序】数据绑定
    02 【setup reactive ref】
    做神经网络用哪个笔记本,笔记本能跑神经网络么
  • 原文地址:https://blog.csdn.net/qq_46423017/article/details/126789609