SSM整合案例企业权限管理系统(1):SSM环境搭建

文章目录

  • 一、数据库环境搭建
    • 1.sql语句
    • 2.可视化效果
    • 3.字段说明
  • 二、maven工程搭建
    • 1.首先创建父工程
    • 2.创建父工程的子模块
      • 2.1几大子模块
      • 2.2web模块需要用maven模板项目
      • 2.3最后效果
    • 3.父工程pom.xml导入jar包
    • 4domian模块中实体类创建
      • 4.1创建含有如下属性的实体类
      • 4.2目录结构
    • 5.dao模块接口配置
      • 5.1接口代码
      • 5.2目录结构
    • 6.service模块创建接口和实现类
      • 6.1接口代码
      • 6.2实现类代码
      • 6.3目录结构
    • 7.配置文件
      • 7.1完善目录
      • 7.2配置applicationContext.xml
      • 7.3springmvc.xml
      • 7.4配置web.xml
    • 8.web模块新建ProductController类
      • 8.1ProductController
      • 8.2目录结构
    • 9.基本功能测试
      • 9.1页面的支持
    • 10.main.jsp(主页)
  • 三、添加产品流程
    • 1.流程分析
    • 2.代码实现
      • 2.1前端代码解释
      • 2.2后端代码实现
    • 3.功能效果

一、数据库环境搭建

1.sql语句

CREATE TABLE product(
id VARCHAR(32) PRIMARY KEY,
productNum VARCHAR(50) NOT NULL,
productName VARCHAR(50),
cityName VARCHAR(50),
DepartureTime TIMESTAMP,
productPrice DOUBLE,
productDesc VARCHAR(500),
productStatus INT,
UNIQUE KEY(id,productNum)
)
INSERT INTO PRODUCT (id, productnum, productname, cityname, departuretime, productprice,
productdesc, productstatus)
VALUES ('676C5BD1D35E429A8C2E114939C5685A', 'xpt-002', '北京三日游', '北京', 20181010101000, 1200, '不错的旅行', 1);

INSERT INTO PRODUCT (id, productnum, productname, cityname, departuretime, productprice,
productdesc, productstatus)
VALUES ('12B7ABF2A4C544568B0A7C69F36BF8B7', 'xpt-003', '上海五日游', '上海', 20180425143000, 1800, '魔都我来了', 0);
INSERT INTO PRODUCT (id, productnum, productname, cityname, departuretime, productprice,
productdesc, productstatus)
VALUES ('9F71F01CB448476DAFB309AA6DF9497F', 'xpt-001', '北京三日游', '北京', 20181010101000, 1200, '不错的旅行', 1);

2.可视化效果

在这里插入图片描述

3.字段说明

SSM整合案例企业权限管理系统(1):SSM环境搭建_第1张图片

二、maven工程搭建

1.首先创建父工程

SSM整合案例企业权限管理系统(1):SSM环境搭建_第2张图片SSM整合案例企业权限管理系统(1):SSM环境搭建_第3张图片SSM整合案例企业权限管理系统(1):SSM环境搭建_第4张图片

2.创建父工程的子模块

创建方式和上述完全一致,依次命名为
SSM整合案例企业权限管理系统(1):SSM环境搭建_第5张图片SSM整合案例企业权限管理系统(1):SSM环境搭建_第6张图片SSM整合案例企业权限管理系统(1):SSM环境搭建_第7张图片

2.1几大子模块

SSM整合案例企业权限管理系统(1):SSM环境搭建_第8张图片

2.2web模块需要用maven模板项目

SSM整合案例企业权限管理系统(1):SSM环境搭建_第9张图片SSM整合案例企业权限管理系统(1):SSM环境搭建_第10张图片

2.3最后效果

SSM整合案例企业权限管理系统(1):SSM环境搭建_第11张图片

3.父工程pom.xml导入jar包


<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.0modelVersion>

    <groupId>com.xptgroupId>
    <artifactId>SSM_EnterpriseAuthorityManagementartifactId>
    <packaging>pompackaging>
    <version>1.0-SNAPSHOTversion>


    <properties>
        <spring.version>5.0.2.RELEASEspring.version>
        <slf4j.version>1.6.6slf4j.version>
        <log4j.version>1.2.12log4j.version>
        <mysql.version>5.1.6mysql.version>
        <mybatis.version>3.4.5mybatis.version>
        <spring.security.version>5.0.1.RELEASEspring.security.version>
    properties>

    <dependencies>        
        <dependency>
            <groupId>org.aspectjgroupId>
            <artifactId>aspectjweaverartifactId>
            <version>1.6.8version>
        dependency>
        <dependency>
            <groupId>org.springframeworkgroupId>
            <artifactId>spring-aopartifactId>
            <version>${spring.version}version>
        dependency>
        <dependency>
            <groupId>org.springframeworkgroupId>
            <artifactId>spring-contextartifactId>
            <version>${spring.version}version>
        dependency>
        <dependency>
            <groupId>org.springframeworkgroupId>
            <artifactId>spring-context-supportartifactId>
            <version>${spring.version}version>
        dependency>
        <dependency>
            <groupId>org.springframeworkgroupId>
            <artifactId>spring-webartifactId>
            <version>${spring.version}version>
        dependency>
        <dependency>
            <groupId>org.springframeworkgroupId>
            <artifactId>spring-ormartifactId>
            <version>${spring.version}version>
        dependency>
        <dependency>
            <groupId>org.springframeworkgroupId>
            <artifactId>spring-beansartifactId>
            <version>${spring.version}version>
        dependency>
        <dependency>
            <groupId>org.springframeworkgroupId>
            <artifactId>spring-coreartifactId>
            <version>${spring.version}version>
        dependency>
        <dependency>
            <groupId>org.springframeworkgroupId>
            <artifactId>spring-testartifactId>
            <version>${spring.version}version>
        dependency>
        <dependency>
            <groupId>org.springframeworkgroupId>
            <artifactId>spring-webmvcartifactId>
            <version>${spring.version}version>

        dependency>
        <dependency>
            <groupId>org.springframeworkgroupId>
            <artifactId>spring-txartifactId>
            <version>${spring.version}version>
        dependency>
        <dependency>
            <groupId>junitgroupId>
            <artifactId>junitartifactId>
            <version>4.12version>
            <scope>testscope>
        dependency>

        <dependency>
            <groupId>javax.servletgroupId>
            <artifactId>javax.servlet-apiartifactId>
            <version>3.1.0version>
            <scope>providedscope>
        dependency>
        <dependency>
            <groupId>javax.servlet.jspgroupId>
            <artifactId>jsp-apiartifactId>
            <version>2.0version>
            <scope>providedscope>
        dependency>
        <dependency>
            <groupId>jstlgroupId>
            <artifactId>jstlartifactId>
            <version>1.2version>
        dependency>        
        <dependency>
            <groupId>log4jgroupId>
            <artifactId>log4jartifactId>
            <version>${log4j.version}version>
        dependency>
        <dependency>
            <groupId>org.slf4jgroupId>
            <artifactId>slf4j-apiartifactId>
            <version>${slf4j.version}version>
        dependency>
        <dependency>
            <groupId>org.slf4jgroupId>
            <artifactId>slf4j-log4j12artifactId>
            <version>${slf4j.version}version>
        dependency>        

        <dependency>
            <groupId>org.mybatisgroupId>
            <artifactId>mybatisartifactId>
            <version>${mybatis.version}version>
        dependency>
        <dependency>
            <groupId>org.mybatisgroupId>
            <artifactId>mybatis-springartifactId>
            <version>1.3.0version>
        dependency>
        <dependency>
            <groupId>c3p0groupId>
            <artifactId>c3p0artifactId>
            <version>0.9.1.2version>
            <type>jartype>
            <scope>compilescope>
        dependency>
        <dependency>
            <groupId>com.github.pagehelpergroupId>
            <artifactId>pagehelperartifactId>
            <version>5.1.2version>
        dependency>
        <dependency>
            <groupId>org.springframework.securitygroupId>
            <artifactId>spring-security-webartifactId>
            <version>${spring.security.version}version>
        dependency>
        <dependency>
            <groupId>org.springframework.securitygroupId>
            <artifactId>spring-security-configartifactId>
            <version>${spring.security.version}version>
        dependency>
        <dependency>
            <groupId>org.springframework.securitygroupId>
            <artifactId>spring-security-coreartifactId>
            <version>${spring.security.version}version>
        dependency>
        <dependency>
            <groupId>org.springframework.securitygroupId>
            <artifactId>spring-security-taglibsartifactId>
            <version>${spring.security.version}version>
        dependency>


        <dependency>
            <groupId>mysqlgroupId>
            <artifactId>mysql-connector-javaartifactId>
            <version>${mysql.version}version>
        dependency>

        <dependency>
            <groupId>javax.annotationgroupId>
            <artifactId>jsr250-apiartifactId>
            <version>1.0version>
        dependency>
    dependencies>
    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.pluginsgroupId>
                    <artifactId>maven-compiler-pluginartifactId>
                    <version>3.2version>
                    <configuration>
                        <source>1.8source>
                        <target>1.8target>
                        <encoding>UTF-8encoding>
                        <showWarnings>trueshowWarnings>
                    configuration>
                plugin>
            plugins>
        pluginManagement>
    build>


    <modules>
        <module>EnterpriseAuthorityManagement_servicemodule>
        <module>EnterpriseAuthorityManagement_domainmodule>
        <module>EnterpriseAuthorityManagement_utilsmodule>
        <module>EnterpriseAuthorityManagement_webmodule>
    modules>


project>

4domian模块中实体类创建

4.1创建含有如下属性的实体类

只给出属性名和类名,gettersetter方法自行右键生成即可

public class Product {

    private String id; // 主键
    private String productNum; // 编号 唯一
    private String productName; // 名称
    private String cityName; // 出发城市
    private Date departureTime; // 出发时间
    private String departureTimeStr;
    private double productPrice; // 产品价格
    private String productDesc; // 产品描述
    private Integer productStatus; // 状态 0 关闭 1 开启
    private String productStatusStr;
}

4.2目录结构

SSM整合案例企业权限管理系统(1):SSM环境搭建_第12张图片

5.dao模块接口配置

5.1接口代码

public interface IProductDao {

    //查询所有的产品信息
    public List<Product> findAll() throws Exception;
}

5.2目录结构

SSM整合案例企业权限管理系统(1):SSM环境搭建_第13张图片

6.service模块创建接口和实现类

6.1接口代码

public interface IProductService {
    
    public List<Product> findAll() throws Exception;
    
}

6.2实现类代码

@Service
@Transactional
public class ProductServiceImpl implements IProductService {

    //服务层调用dao层
    //等待被注入
    @Autowired
    private IProductDao productDao;
    @Override
    public List<Product> findAll() throws Exception {
        return productDao.findAll();
    }
}

6.3目录结构

SSM整合案例企业权限管理系统(1):SSM环境搭建_第14张图片

7.配置文件

所有的配置都在web子模块中进行,但是web模块是基于maven骨架工程创建的,所以需要先完善它的目录。

7.1完善目录

SSM整合案例企业权限管理系统(1):SSM环境搭建_第15张图片

7.2配置applicationContext.xml

这是spring的核心配置文件


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


    
    <context:component-scan base-package="com.xpt.service">
    context:component-scan>
    <context:component-scan base-package="com.xpt.dao">
    context:component-scan>
        
    <bean id="mapperScanner" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.xpt.dao"/>
    bean>

    <context:property-placeholder location="classpath:db.properties"/>
    
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <property name="driverClass" value="${jdbc.driver}"/>
        <property name="jdbcUrl" value="${jdbc.url}"/>
        <property name="user" value="${jdbc.user}"/>
        <property name="password" value="${jdbc.password}"/>
    bean>
    
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
    bean>
    
beans>

7.3springmvc.xml


<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       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/mvc
           http://www.springframework.org/schema/mvc/spring-mvc.xsd
           http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context.xsd
           http://www.springframework.org/schema/aop
		http://www.springframework.org/schema/aop/spring-aop.xsd
           ">

        
        <context:component-scan base-package="com.xpt.controller">
        context:component-scan>

        
        <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            
            <property name="prefix" value="/pages/"/>
            
            <property name="suffix" value=".jsp"/>
        bean>

        
        <mvc:resources location="/css/" mapping="/css/**" />
        <mvc:resources location="/img/" mapping="/img/**" />
        <mvc:resources location="/js/" mapping="/js/**" />
        <mvc:resources location="/plugins/" mapping="/plugins/**" />

        
        <mvc:annotation-driven/>

        
        <aop:aspectj-autoproxy proxy-target-class="true"/>
beans>

7.4配置web.xml


<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">


  
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListenerlistener-class>
  listener>
  
  <context-param>
    <param-name>contextConfigLocationparam-name>
    <param-value>classpath*:applicationContext.xmlparam-value>
  context-param>

  
  <servlet>
    <servlet-name>dispatcherServletservlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServletservlet-class>
    
    <init-param>
      <param-name>contextConfigLocationparam-name>
      <param-value>classpath:spring-mvc.xmlparam-value>
    init-param>
    
    <load-on-startup>1load-on-startup>
  servlet>
  <servlet-mapping>
    <servlet-name>dispatcherServletservlet-name>
    <url-pattern>*.dourl-pattern>
  servlet-mapping>


  
  <filter>
    <filter-name>characterEncodingFilterfilter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilterfilter-class>
    <init-param>
      <param-name>encodingparam-name>
      <param-value>UTF-8param-value>
    init-param>
  filter>
  <filter-mapping>
    <filter-name>characterEncodingFilterfilter-name>
    <url-pattern>/*url-pattern>
  filter-mapping>
  
  <welcome-file-list>
    <welcome-file>index.htmlwelcome-file>
    <welcome-file>index.htmwelcome-file>
    <welcome-file>index.jspwelcome-file>
    <welcome-file>default.htmlwelcome-file>
    <welcome-file>default.htmwelcome-file>
    <welcome-file>default.jspwelcome-file>
  welcome-file-list>
web-app>

8.web模块新建ProductController类

8.1ProductController

@Controller
@RequestMapping("/product")
public class ProductController {
    
    //控制器应该调用service层
    @Autowired
    private IProductService productService;
    //.do是个人习惯
    @RequestMapping("/findAll.do")
    public ModelAndView findAll() throws Exception {
        ModelAndView mv = new ModelAndView();
        List<Product> products = productService.findAll();
        mv.addObject("",products);
        mv.setViewName("");
        return mv;
    }
}

8.2目录结构

SSM整合案例企业权限管理系统(1):SSM环境搭建_第16张图片

9.基本功能测试

9.1页面的支持

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

  • 效果:

SSM整合案例企业权限管理系统(1):SSM环境搭建_第17张图片

10.main.jsp(主页)

SSM整合案例企业权限管理系统(1):SSM环境搭建_第18张图片

SSM整合案例企业权限管理系统(1):SSM环境搭建_第19张图片

三、添加产品流程

1.流程分析

SSM整合案例企业权限管理系统(1):SSM环境搭建_第20张图片

2.代码实现

2.1前端代码解释

SSM整合案例企业权限管理系统(1):SSM环境搭建_第21张图片

2.2后端代码实现

SSM整合案例企业权限管理系统(1):SSM环境搭建_第22张图片

3.功能效果

SSM整合案例企业权限管理系统(1):SSM环境搭建_第23张图片

你可能感兴趣的:(SSM)