SSM (Vue3+ElementPlus+Axios+SSM 前后端分离)

本教程详细介绍了使用 Vue3、ElementPlus 和 SSM(SpringMVC+Spring+MyBatis)进行前后端分离的项目开发过程。从创建SSM项目、配置环境,到搭建Vue3前端工程,再到整合ElementPlus组件库,实现家居信息的增删改查功能,包括分页和条件查询。项目涵盖了数据验证、接口调用及前后端交互,提供了一套完整的实践方案。
摘要由CSDN通过智能技术生成

文章目录


1. 项目介绍

1.1 项目功能/界面

● SSM 整合项目界面


在这里插入图片描述

● 技术栈

  • 说明:前后端分离开发,前端框架 Vue + 后端框架 SSM
  1. 前端框架 Vue
  2. 后台框架-SSM(SpringMVC+Spring+MyBatis)
  3. 数据库-MySQL
  4. 项目的依赖管理-Maven
  5. 分页-pagehelper
  6. 逆向工程-MyBatis Generator
  7. 其它…

2. 项目基础环境搭建

2.1 创建项目

  1. 创建 Maven 项目-提醒,配置 maven 的仓库镜像

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

  1. 手动创建 java 和 test 相关目录

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

  1. 引入项目依赖的 jar 包,先引入基本的包,开发中,需要什么包再导入即可
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.xjs</groupId>
  <artifactId>furn-ssm</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>war</packaging>

  <name>furn-ssm Maven Webapp</name>
  <!-- FIXME change it to the project's website -->
  <url>http://www.example.com</url>

  <!--修改编译版本-->
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>

    <!--引入springmvc, 也会引入/导入spring的库/jar-->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-webmvc</artifactId>
      <version>5.3.8</version>
    </dependency>

    <!--引入spring-jdbc, 支持事务相关-->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-jdbc</artifactId>
      <version>5.3.8</version>
    </dependency>

    <!--引入spring aspects 切面编程需要的库/jar-->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-aspects</artifactId>
      <version>5.3.8</version>
    </dependency>

    <!--引入mybatis库/jar-->
    <dependency>
      <groupId>org.mybatis</groupId>
      <artifactId>mybatis</artifactId>
      <version>3.5.7</version>
    </dependency>

    <!--引入druid数据库连接池-->
    <dependency>
      <groupId>com.alibaba</groupId>
      <artifactId>druid</artifactId>
      <version>1.2.6</version>
    </dependency>

    <!--引入mysql驱动-->
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>5.1.49</version>
    </dependency>
  </dependencies>

</project>

  1. 给项目配置 Tomcat,方式和前面将 javaweb 一样

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

  1. 启动 Tomcat , 完成测试

在这里插入图片描述

2.2 项目全局配置 web.xml

  1. 配置 D:\xjs_ssm\furn-ssm\src\main\webapp\WEB-INF\web.xml ,和项目全局相关的【适当的想一想前面我们学习的 spring,springmvc,mybatis,不需要背,把每步骤看懂,到时知道到哪里去找配置】
<!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>
  <!--  1、配置启动Spring容器:
      主要配置和业务逻辑有关的,比如数据源,事务控制等-->
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:applicationContext.xml</param-value>
  </context-param>
  <!--
      ContextLoaderListener: 监听器

      1、ContextLoaderListener监听器作用是启动Web容器时,自动装配ApplicationContext的配置信息
      2、它实现了ServletContextListener接口,在web.xml配置该监听器,启动容器时,会默认执行它实现的方法
  -->
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>

  <!--
  1、配置前端控制器/中央控制器/分发控制器
  2. 用户的请求都会经过它的处理
  3. 因为这里没有指定springmvc的配置文件,那么就会默认按照 [servlet-name]-servlet.xml 来获取
  4. 读取配置文件的原理,在前面 springmvc时学过
 -->
  <servlet>
    <servlet-name>springDispatcherServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <!--在web项目启动时,就自动的加载DispatcherServlet-->
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>springDispatcherServlet</servlet-name>
    <!--说明:
        1. 这里我们配置的url-pattern是 / ,表示用户的请求都经过 DispatcherServlet
    -->
    <url-pattern>/</url-pattern>
  </servlet-mapping>


  <!--配置Spring提供的过滤器,解决中文乱码问题
  解读:
  1. forceRequestEncoding 配置成 true ,表示该过滤器会执行 request.setCharacterEncoding(encoding);
  2. forceResponseEncoding 配置成 true, 表示该过滤器会执行 response.setCharacterEncoding(encoding);
  -->
  <filter>
    <filter-name>CharacterEncodingFilter</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>
    <init-param>
      <param-name>forceRequestEncoding</param-name>
      <param-value>true</param-value>
    </init-param>
    <init-param>
      <param-name>forceResponseEncoding</param-name>
      <param-value>true</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>CharacterEncodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

  <!--配置HiddenHttpMethodFilter
     1. 使用Rest风格的URI,可以把页面发过来的post请求转为指定的delete或者put请求
     2. 配置url-pattern 是 /* 表示请求都经过 hiddenHttpMethodFilter过滤
 -->
  <filter>
    <filter-name>hiddenHttpMethodFilter</filter-name>
    <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>hiddenHttpMethodFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
</web-app>

  1. 如果 web.xml 的 <web-app> 报红,选择只是高亮 syntax 即可,本身没有问题,就是 DTD 的约束

在这里插入图片描述

2.3 SpringMVC 配置

  1. 创建 SpringMVC 的配置文件 springDispatcherServlet-servlet.xml : 主要包含网站跳转逻辑的控制
  2. 创建 D:\xjs_ssm\furn-ssm\src\main\webapp\WEB-INF\springDispatcherServlet-servlet.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">

</beans>

在这里插入图片描述

  1. 创建项目相关的包

在这里插入图片描述

  1. 配置扫描 com.xjs 包 的 控制器
    <!-- 解读
        1. 扫描com.xjs包
        2. use-default-filters="false" 禁用默认过滤规则
        3. context:include-filter 配置说明 只是扫描控制器
    -->
    <context:component-scan base-package="com.xjs.furn">
        <!--SpringMvc只是扫描Controller-->
        <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
    </context:component-scan>
  1. 配置视图解析器
    <!--配置视图解析器[默认视图解析器]-->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <!--配置属性suffix 和 prefix-->
        <property name="prefix" value="/WEB-INF/views/"/>
        <property name="suffix" value=".html"/>
    </bean>
  1. 两个常规配置
    <!--加入两个常规配置-->
    <!--支持SpringMVC的高级功能,比如JSR303校验, 映射动态请求-->
    <mvc:annotation-driven></mvc:annotation-driven>
    <!--将springmvc不能处理的请求,交给tomcat处理,比如css, js-->
    <mvc:default-servlet-handler/>
  1. 完成配置后的 springDispatcherServlet-servlet.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.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd">

    <!-- 解读
        1. 扫描com.xjs包
        2. use-default-filters="false" 禁用默认过滤规则
        3. context:include-filter 配置说明 只是扫描控制器
    -->
    <context:component-scan base-package="com.xjs.furn">
        <!--SpringMvc只是扫描Controller-->
        <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
    </context:component-scan>

    <!--配置视图解析器[默认视图解析器]-->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <!--配置属性suffix 和 prefix-->
        <property name="prefix" value="/WEB-INF/views/"/>
        <property name="suffix" value=".html"/>
    </bean>

    <!--加入两个常规配置-->
    <!--支持SpringMVC的高级功能,比如JSR303校验, 映射动态请求-->
    <mvc:annotation-driven></mvc:annotation-driven>
    <!--将springmvc不能处理的请求,交给tomcat处理,比如css, js-->
    <mvc:default-servlet-handler/>
    
</beans>
  1. 完成测试
  • 创建 D:\xjs_ssm\furn-ssm\src\main\java\com\xjs\furn\controller\TestController.java
package com.xjs.furn.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @Author: 谢家升
 * @Version: 1.0
 */
@Controller
public class TestController {
   

    @RequestMapping("/hi")
    public String hi() {
   
        System.out.println("TestController-hi");
        return "hi";
    }
}

  • 创建 D:\xjs_ssm\furn-ssm\src\main\webapp\WEB-INF\views\hi.html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>hi</title>
</head>
<body>
<h1>hi,成功</h1>
</body>
</html>
  • 启动 Tomcat ,浏览器输入 http://localhost:8080/ssm/hi

在这里插入图片描述

2.4 配置 Spring 和 MyBatis 并完成整合

  1. 创建 spring 的配置文件 applicationContext.xml : 主要配置和业务逻辑有关的,比如数据源,事务控制等

  2. 创建 D:\xjs_ssm\furn-ssm\src\main\resources\applicationContext.xml , 并加入必要的命名空间

    ① 提示:同样适用前面的方式创建
    右键=> New =>XML configuration => Spring Config

<?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">

    <!--spring的配置文件:主要配置和业务逻辑有关的,比如数据源,事务控制等-->


</beans>
  1. 配置扫描 com.xjs.furn 包,但是不扫描控制器, 控制器由 springmvc 管理
    <!--
        1. 扫描com.xjs.furn包 [包括子包]
        2. context:exclude-filter 表示不扫描 控制器 @Controller
    -->
    <context:component-scan base-package="com.xjs.furn">
        <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
    </context:component-scan>
  1. 创建 D:\xjs_ssm\furn-ssm\src\main\resources\jdbc.properties ,配置连接 mysql 的信息
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://127.0.0.1:3306/furn_ssm?useSSL=true&amp;useUnicode=true&amp;characterEncoding=UTF-8
jdbc.user=root
jdbc.pwd=hsp
  1. 配置数据源配置
    <!--引入外部的jdbc.properties文件 放在 resources 下-->
    <context:property-placeholder location="classpath:jdbc.properties"/>
    <!--配置数据源对象-DataSource Druid数据源-->
    <bean class="com.alibaba.druid.pool.DruidDataSource" id="pooledDataSource">
        <!--给数据源对象配置属性值-->
        <property name="username" value="${jdbc.user}"/>
        <property name="password" value="${jdbc.pwd}"/>
        <property name="driverClassName" value="${jdbc.driver}"/>
        <property name="url" value="${jdbc.url}"/>
    </bean>
  1. 配置 spring 与 mybatis 的整合
  • 第一步:pom.xml 中引入mybatis整合spring的适配包
    <!--引入mybatis整合spring的适配包, 一定要引入-->
    <dependency>
      <groupId>org.mybatis</groupId>
      <artifactId>mybatis-spring</artifactId>
      <version>2.0.6</version>
    </dependency>
  • 第二步:配置 mybatis 和 spring 的整合
    <!--配置mybatis和spring的整合
        1. 在项目中 引入 mybatis 整合到 spring 的适配库/包
        2. 这里爆红,是因为还没有相应的文件,当有文件时就不会爆红了
    -->
    <bean class="org.mybatis.spring.SqlSessionFactoryBean" id="sqlSessionFactory">
        <!--指定mybatis的全局配置文件-->
        <property name="configLocation" value="classpath:mybatis-config.xml"/>
        <!--指定数据源-->
        <property name="dataSource" ref="pooledDataSource"/>
        <!--指定 mybatis 的 mapper文件[Mapper.xml] 的位置
            1. 在开发中,通常将 mapper.xml文件放在类路径 resource/mapper 目录下
            2. 所以这里指定的 value 是 classpath:mapper/*.xml
        -->
        <property name="mapperLocations" value="classpath:mapper/*.xml"/>
    </bean>
  1. 在类路径 resource 下创建 D:\xjs_ssm\furn-ssm\src\main\resources\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>

    <!--配置MyBatis自带的日志输出-查看原生的sql-->
    <settings>
        <setting name="logImpl" value="STDOUT_LOGGING"/>
    </settings>

    <!--配置别名
      1. 如果一个包下有很多的类,我们可以直接引入包
      2. 这样该包下面的所有类名,可以直接使用
    -->
    <typeAliases>
        <package name="com.xjs.furn.bean"/>
    </typeAliases>
</configuration>
  1. 在类路径下创建 mapper 目录,存放 mapper 的 xml 文件

在这里插入图片描述

  1. 配置将 mybatis 接口实现加入到 ioc 容器,在 applicationContext.xml 配置
    <!-- 配置扫描器,将mybatis接口的实现加入到ioc容器中
        1. 我们的mapper接口放在com.xjs.furn.dao
        2. mybatis就是处于DAO层, 操作DB
    -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <!--
            1. 扫描所有的dao接口的实现,加入到ioc容器中
            2. 这里dao接口,就是mapper接口
        -->
        <property name="basePackage" value="com.xjs.furn.dao"/>
    </bean>
  1. 配置事务控制,在 applicationContext.xml 配置
<!--配置事务管理器-对象
    1. DataSourceTransactionManager 这个对象是进行事务管理
    2. 一定要配置数据源属性,这样指定该事务管理器 是对哪个数据源进行事务控制
    -->
    <bean class="org.springframework.jdbc.datasource.DataSourceTransactionManager" id="transactionManager">
        <property name="dataSource" ref="pooledDataSource"/>
    </bean>
  1. 配置开启基于注解的事务(使用 XML 配置+切入表达式),并指定切入点
<!--配置启动基于注解的声明式事务管理功能-->
    <!--这是以前的玩法, 这次 使用XML配置+切入表达式来玩-->
    <!--<tx:annotation-driven transaction-manager="transactionManager"/>-->

    <!--
        解读:
        1. 开启基于注解的事务,并指定切入点
        2. execution(* com.xjs.furn.service..*(..)):
           表示对com.xjs.furn.service包所有类的所有方法控制事务
        3. tx:advice : 配置事务增强, 也就是指定事务如何切入
        4. 不需要背,但是能看到,能修改,能维护
    -->
    <aop:config>
        <!-- 切入点表达式 -->
        <aop:pointcut id="txPoint" expression="execution(* com.xjs.furn.service..*(..))"/>
        <!-- 配置事务增强/规则: 使用txAdvice 指定规则对 txPoint进行切入-->
        <aop:advisor advice-ref="txAdvice" pointcut-ref="txPoint"/>
    </aop:config>
    <!--配置事务增强【指定事务规则】,也就是指定事务如何切入-->
    <tx:advice id="txAdvice">
        <tx:attributes>
            <!-- *代表所有方法都是事务方法-->
            <tx:method name="*"/>
            <!-- 以get开始的所有方法 ,我们认为是只读,进行调优-->
            <tx:method name="get*" read-only="true"/>
        </tx:attributes>
    </tx:advice>
  1. 到此 SSM 整合基本完成,看下 spring 配置文件 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"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:aop="http://www.springframework.org/schema/aop" 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/aop https://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">

    <!--spring的配置文件:主要配置和业务逻辑有关的,比如数据源,事务控制等-->

    <!--
        1. 扫描com.xjs.furn包 [包括子包]
        2. context:exclude-filter 表示不扫描 控制器 @Controller
    -->
    <context:component-scan base-package="com.xjs.furn">
        <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
    </context:component-scan>

    <!--引入外部的jdbc.properties文件 放在 resources 下-->
    <context:property-placeholder location="classpath:jdbc.properties"/>
    <!--配置数据源对象-DataSource Druid数据源-->
    <bean class="com.alibaba.druid.pool.DruidDataSource" id="pooledDataSource">
        <!--给数据源对象配置属性值-->
        <property name="username" value="${jdbc.user}"/>
        <property name="password" value="${jdbc.pwd}"/>
        <property name="driverClassName" value="${jdbc.driver}"/>
        <property name="url" value="${jdbc.url}"/>
    </bean>

    <!--配置mybatis和spring的整合
        1. 在项目中 引入 mybatis 整合到 spring 的适配库/包
        2. 这里爆红,是因为还没有相应的文件,当有文件时就不会爆红了
    -->
    <bean class="org.mybatis.spring.SqlSessionFactoryBean" id="sqlSessionFactory">
        <!--指定mybatis的全局配置文件-->
        <property name="configLocation" value="classpath:mybatis-config.xml"/>
        <!--指定数据源-->
        <property name="dataSource" ref="pooledDataSource"/>
        <!--指定 mybatis 的 mapper文件[Mapper.xml] 的位置
            1. 在开发中,通常将 mapper.xml文件放在类路径 resource/mapper 目录下
            2. 所以这里指定的 value 是 classpath:mapper/*.xml
        -->
        <property name="mapperLocations" value="classpath:mapper/*.xml"/>
    </bean>

    <!-- 配置扫描器,将mybatis接口的实现加入到ioc容器中
        1. 我们的mapper接口放在com.xjs.furn.dao
        2. mybatis就是处于DAO层, 操作DB
    -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <!--
            1. 扫描所有的dao接口的实现,加入到ioc容器中
            2. 这里dao接口,就是mapper接口
        -->
        <property name="basePackage" value="com.xjs.furn.dao"/>
    </bean>

    <!--配置事务管理器-对象
        1. DataSourceTransactionManager 这个对象是进行事务管理
        2. 一定要配置数据源属性,这样指定该事务管理器 是对哪个数据源进行事务控制
    -->
    <bean class="org.springframework.jdbc.datasource.DataSourceTransactionManager" id="transactionManager">
        <property name="dataSource" ref="pooledDataSource"/>
    </bean>

    <!--配置启动基于注解的声明式事务管理功能-->
    <!--这是以前的玩法, 这次 使用XML配置+切入表达式来玩-->
    <!--<tx:annotation-driven transaction-manager="transactionManager"/>-->

    <!--
        解读:
        1. 开启基于注解的事务,并指定切入点
        2. execution(* com.xjs.furn.service..*(..)):
           表示对com.xjs.furn.service包所有类的所有方法控制事务
        3. tx:advice : 配置事务增强, 也就是指定事务如何切入
        4. 不需要背,但是能看到,能修改,能维护
    -->
    <aop:config>
        <!-- 切入点表达式 -->
        <aop:pointcut id="txPoint" expression="execution(* com.xjs.furn.service..*(..))"/>
        <!-- 配置事务增强/规则: 使用txAdvice 指定规则对 txPoint进行切入-->
        <aop:advisor advice-ref="txAdvice" pointcut-ref="txPoint"/>
    </aop:config>
    <!--配置事务增强【指定事务规则】,也就是指定事务如何切入-->
    <tx:advice id="txAdvice">
        <tx:attributes>
            <!-- *代表所有方法都是事务方法-->
            <tx:method name="*"/>
            <!-- 以get开始的所有方法 ,我们认为是只读,进行调优-->
            <tx:method name="get*" read-only="true"/>
        </tx:attributes>
    </tx:advice>

</beans>
  1. 完成测试:创建 D:\xjs_ssm\furn-ssm\src\test\java\com\xjs\test\T1.java
package com.xjs.test;

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @Author: 谢家升
 * @Version: 1.0
 */
public class T1 {
   

    @Test
    public void T1() {
   
        //看看spring配置的bean是否可以获取到

        //1. 获取到ioc容器
        ApplicationContext ioc = new ClassPathXmlApplicationContext("applicationContext.xml");

        //2. 获取Bean
        System.out.println(ioc.getBean("pooledDataSource"));

        System.out.println(ioc.getBean("sqlSessionFactory"));
    }

}

  1. 看看是否能够得到 Spring 容器的数据源对象和会话工厂对象
{
	CreateTime:"2022-07-13 15:56:13",
	ActiveCount:0,
	PoolingCount:0,
	CreateCount:0,
	DestroyCount:0,
	CloseCount:0,
	ConnectCount:0,
	Connections:[
	]
}
org.apache.ibatis.session.defaults.DefaultSqlSessionFactory@2a693f59

Process finished with exit code 0

2.5 创建表,使用逆向工程生成 Bean、XxxMapper 和 XxxMapper.xml

  1. 创建 furn_ssm 数据库和 furn 表
-- 创建 furn_ssm 数据库
DROP DATABASE IF EXISTS furn_ssm;
CREATE DATABASE furn_ssm;
USE furn_ssm; 

-- 创建家居表
CREATE TABLE furn(
`id` INT(11) PRIMARY KEY AUTO_INCREMENT, ## id
`name` VARCHAR(64) NOT NULL, ## 家居名
`maker` VARCHAR(64) NOT NULL, ## 厂商
`price` DECIMAL(11,2) NOT NULL, ## 价格
`sales` INT(11) NOT NULL, ## 销量
`stock` INT(11) NOT NULL, ## 库存
`img_path` VARCHAR(256) NOT NULL ## 照片路径
);

-- 初始化家居数据
INSERT INTO furn(`id` , `name` , `maker` , `price` , `sales` , `stock` , `img_path`)
VALUES(NULL , '北欧风格小桌子' , '熊猫家居' , 180 , 666 , 7 ,
'assets/images/product-image/1.jpg');
INSERT INTO furn(`id` , `name` , `maker` , `price` , `sales` , `stock` , `img_path`)
VALUES(NULL , '简约风格小椅子' , '熊猫家居' , 180 , 666 , 7 ,
'assets/images/product-image/2.jpg');
INSERT INTO furn(`id` , 
  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
很高兴回答您的问题!Java项目员工管理系统是一个非常常见的实践项目。它通常涉及到前后端分离的架构,使用JavaEE作为后端框架,Vue作为前端框架,SSM作为整个项目的技术栈,MySQL作为数据库,同时使用Maven进行项目构建和依赖管理,Axios用于前后端数据交互,HTML用于构建前端页面。 以下是一个简单的步骤指南,以帮助您开始这个项目: 1. 确定项目需求:明确系统所需的功能和特性,例如员工信息的增删改查、权限管理等。 2. 创建数据库:使用MySQL或其他数据库管理系统创建一个数据库,定义员工表和其他相关表。 3. 后端开发: - 使用JavaEE作为后端框架,搭建项目结构。 - 使用SSM框架(SpringSpringMVC、MyBatis)进行后端开发。配置数据源、连接数据库,并编写DAO层接口和Mapper文件。 - 实现业务逻辑层和控制层,编写接口和请求处理方法。 4. 前端开发: - 使用Vue作为前端框架,搭建项目结构。 - 使用Axios进行前后端数据交互,发送HTTP请求。 - 使用HTML和CSS构建前端页面,实现员工信息的展示、增删改查等功能。 5. 前后端联调: - 后端提供接口,在前端使用Axios发送请求,获取后端数据。 - 前端通过Ajax获取数据,并进行展示和交互。 6. 项目打包部署: - 使用Maven进行项目构建和依赖管理。配置pom.xml文件,添加所需的依赖。 - 部署后端项目到服务器,配置数据库连接等相关配置。 - 将前端代码打包为静态文件,并部署到Web服务器中。 这只是一个简单的指南,实际开发过程中还需要考虑更多的细节和问题。希望以上信息对您有所帮助!如有任何进一步的问题,请随时提问。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

要学就学灰太狼

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值