8-26SSM+ElementUI

Jar导入版本转换为maven版本 ssm项目(掌握)
SSM抽取Base(掌握)
Maven多模块(掌握)
前后端分离后台-crud实现(掌握)
前后端分离前台基于vue-element-admin模板-crud实现(掌握)

Jar导入版本转换为maven版本 ssm项目

集成ssm
pom.xml:




  4.0.0

  cn.itsource
  crm
  1.0-SNAPSHOT
  war

  crm
  http://www.example.com

  
    UTF-8
    1.8
    1.8
    
    
    4.2.5.RELEASE
    
    3.2.1
    
    1.7.2
    1.2.17
    
    2.5.0
  

  
    
    
      junit
      junit
      4.11
      test
    

    
    
      org.springframework
      spring-aop
      ${spring.version}
    
    
      org.springframework
      spring-aspects
      ${spring.version}
    
    
      org.springframework
      spring-beans
      ${spring.version}
    
    
      org.springframework
      spring-context
      ${spring.version}
    
    
      org.springframework
      spring-core
      ${spring.version}
    
    
      org.springframework
      spring-expression
      ${spring.version}
    
    
      org.springframework
      spring-jdbc
      ${spring.version}
    
    
      org.springframework
      spring-test
      ${spring.version}
    
    
      org.springframework
      spring-tx
      ${spring.version}
    
    
      commons-logging
      commons-logging
      1.1.1
    

    
    
      org.springframework
      spring-web
      ${spring.version}
    
    
      org.springframework
      spring-webmvc
      ${spring.version}
    

    
    
      aopalliance
      aopalliance
      1.0
    
    
      org.aspectj
      aspectjweaver
      1.6.8
    

    
    
      commons-fileupload
      commons-fileupload
      1.3.1
    
    
      commons-io
      commons-io
      2.2
    
    
    
      com.fasterxml.jackson.core
      jackson-databind
      ${jackson.version}
    
    
      com.fasterxml.jackson.core
      jackson-core
      ${jackson.version}
    
    
      com.fasterxml.jackson.core
      jackson-annotations
      ${jackson.version}
    

    
    
      commons-dbcp
      commons-dbcp
      1.2.2
    
    
      commons-pool
      commons-pool
      1.5.3
    

    
    
      org.mybatis
      mybatis
      ${mybatis.version}
    
    
      org.mybatis
      mybatis-spring
      1.2.0
    

    
    
      log4j
      log4j
      ${log4j.version}
    

    
    
      org.slf4j
      slf4j-api
      ${slf4j.version}
    
    
      org.slf4j
      slf4j-log4j12
      ${slf4j.version}
      test
    

    
    
      mysql
      mysql-connector-java
      5.1.46
    

    
    
      jstl
      jstl
      1.2
    

    
    
      javax.servlet
      javax.servlet-api
      3.0.1
      provided
    

    
      javax.servlet.jsp
      jsp-api
      2.2
      provided
    
  

  
    crm
    
      
        
          maven-clean-plugin
          3.0.0
        
        
        
          maven-resources-plugin
          3.0.2
        
        
          maven-compiler-plugin
          3.7.0
        
        
          maven-surefire-plugin
          2.20.1
        
        
          maven-war-plugin
          3.2.0
        
        
          maven-install-plugin
          2.5.2
        
        
          maven-deploy-plugin
          2.8.2
        
      
    
  


web.xml


  crm
  
  
    contextConfigLocation
    classpath:applicationContext.xml
  
  
  
    org.springframework.web.context.ContextLoaderListener
  

  
  
    springmvc
    org.springframework.web.servlet.DispatcherServlet
    
      contextConfigLocation
      classpath:applicationContext-mvc.xml
    
    1
  
  
    springmvc
    /
  

  
  
    encodingFilter
    org.springframework.web.filter.CharacterEncodingFilter
    
      encoding
      UTF-8
    
  
  
    encodingFilter
    /*
  

applicationContext-mvc.xml




    
    

    
    

    
    

    
    
        
        
    

    
    
        
        
        
        
    

applicationContext.xml




    
    

    
    

    
    
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
    

    
    
        
        
        
        
        
        
            
                cn.itsource.crm.domain
                Cn.itsource.crm.query
            
        
    

    
    
        
    

    
    
        
    

    
    



EmployeeMapper.xml




    



Mapper层
public interface DepartmentMapper {
    public List findAll();
}

Service层
接口
public interface IDepartmentService {
    public List findAll();
}

实现类
@Service
public class DepartmentServiceImpl implements IDepartmentService {
    @Autowired
    private DepartmentMapper departmentMapper;
    @Override
    public List findAll() {
        return departmentMapper.findAll();
    }
}

后台环境搭建-抽取Base

 在cn.itsource.mapper层 抽取BaseMapper

package cn.itsource.mapper;

import java.io.Serializable;
import java.util.List;

/**
 * 基础Mapper
 */
public interface BaseMapper {

    /**
     * 保存一个对象
     * @param t
     */
    void save(T t);

    /**
     * 移除一个对象
     * @param id
     */
    void remove(Serializable id);

    /**
     * 更新一个对象
     * @param t
     */
    void update(T t);

    /**
     * 通过id加载一个对象
     * @param id
     * @return
     */
    T loadById(Serializable id);

    /**
     * 加载所有对象
     * @return
     */
    List loadAll();
}


2 抽取BaseDomain
package cn.itsource.domain;
public class BaseDomain {
    private Long id;
    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
}

3 IBaseService
package cn.itsource.service;

import java.io.Serializable;
import java.util.List;

public interface IBaseService {
    /**
     * 添加一个对象
     * @param t
     */
    void add(T t);

    /**
     * 删除一个对象
     * @param id
     */
    void del(Serializable id);

    /**
     * 更新一个对象
     * @param t
     */
    void update(T t);

    /**
     * 通过id获取一个对象
     * @param id
     * @return
     */
    T getById(Serializable id);

    /**
     * 获取所有对象
     * @return
     */
    List getAll();
}
BaseServiceImpl实现
package cn.itsource.service.impl;

import cn.itsource.mapper.BaseMapper;
import cn.itsource.service.IBaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.List;
//不需要加@Service,子类继承是添加
//类级别事务为读事务,分别在增删改的方法上面加写事务
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BaseServiceImpl implements IBaseService {

    @Autowired
    private BaseMapper baseMapper;

//    @Transactional(readOnly = false,propagation = Propagation.REQUIRED)
    @Transactional
    @Override
    public void add(T t) {
        baseMapper.save(t);
//        int i = 1/0;
    }

    @Transactional
    @Override
    public void del(Serializable id) {
        baseMapper.remove(id);
    }
    @Transactional
    @Override
    public void update(T t) {
         baseMapper.update(t);
    }

    @Override
    public T getById(Serializable id) {
        return baseMapper.loadById(id);
    }

    @Override
    public List getAll() {
        return baseMapper.loadAll();
    }
}


BaseDomain BaseMapper IBaseService,BaseServiceImpl

后台环境搭建-ssm+maven多模块

8-26SSM+ElementUI_第1张图片
只有crm_web是maven-webapp项目,其他都是普通maven项目
**crm_parent中的pom.xml是用来导入公共的包,其他的模块哪一层需要就导入相应的包
并建立相应联系,配置相关的文件
**

前后端分离后台实现-Crud

1、接口实现
package cn.itsource.web.controller;

import cn.itsource.basic.AjaxResult;
import cn.itsource.basic.PageList;
import cn.itsource.domain.Employee;
import cn.itsource.query.EmployeeQuery;
import cn.itsource.service.IEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 员工接口:先不考虑持久层
 *     crud接口
 */
@Controller
@RequestMapping("/employee") //定位资源
public class EmployeeController {
    @Autowired
    private IEmployeeService employeeService;

    //创建员工接口:url 参数,返回值
    //@RequestBody 在请求主体里面传递过,前端要传递json就用这种方式
    @RequestMapping(method = RequestMethod.PUT)
    @ResponseBody
    public AjaxResult add(@RequestBody Employee employee)
    {
        System.out.println("添加成功");
        return AjaxResult.me();
    }

    //删除接口:url 参数,返回值
    // 前台传递del /employee/1
    @RequestMapping(value = "{id}",method = RequestMethod.DELETE)
    @ResponseBody
    public AjaxResult del(@PathVariable("id")Long id){
        System.out.println("删除成功"+id);
        return AjaxResult.me();
    }
    //删除接口:url 参数,返回值
    // 前台传递del /employee/1
    @RequestMapping(value = "{id}",method = RequestMethod.POST)
    @ResponseBody
    public AjaxResult update(@PathVariable("id")Long id,@RequestBody Employee employee){
        System.out.println("修改成功"+id+employee);
        return AjaxResult.me();
    }

    //查询一个
    @ResponseBody
    @RequestMapping(value = "/{id}",method = RequestMethod.GET)
    public  Employee getById(@PathVariable("id") Long id){
        Employee employee = new Employee("zs");
        employee.setId(id);
        return employee;
    }
    //查询所有

    @ResponseBody
    @RequestMapping(method = RequestMethod.PATCH)
    public  List list(){
        return employeeService.getAll();
    }


    // 高级查询
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET)
    public PageList query(@RequestBody EmployeeQuery query){
        return new PageList<>();
    }
}

2.2、实现
2.4.0


    
        io.springfox
        springfox-swagger2
        ${springfox.version}
    
    
        io.springfox
        springfox-swagger-ui
        ${springfox.version}
    

package cn.itsource.crm.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableWebMvc
@EnableSwagger2
@ComponentScan(basePackages=“cn.itsource.crm.web.controller”)
public class SwaggerConfig {

@Bean
public Docket api(){
    return new Docket(DocumentationType.SWAGGER_2)
            .apiInfo(this.apiInfo())
            .select()
            .apis(RequestHandlerSelectors.basePackage("cn.itsource.crm.web.controller"))
            .paths(PathSelectors.any())
            .build();
}


private ApiInfo apiInfo(){
     @SuppressWarnings("deprecation")
    ApiInfo info=new ApiInfo(
             "Spring 构建RestFule",
             "aaa",
             "aa",
             "a",
             "cc",
             "x",
             "x");
     return info;
}

}

在web层 新创建包cn.itsource.crm1.web.config和类:SwaggerConfig

//对swagger进行配置
@Configuration
@EnableWebMvc
@EnableSwagger2
//扫描个包下面controller来生成接口描述
@ComponentScan(basePackages=“cn.itsource.web.controller”)
public class SwaggerConfig {

@Bean
public Docket api(){
    return new Docket(DocumentationType.SWAGGER_2)
            .apiInfo(this.apiInfo())
            .select()
            .apis(RequestHandlerSelectors.basePackage("cn.itsource.web.controller"))
            .paths(PathSelectors.any())
            .build();
}


private ApiInfo apiInfo(){
     @SuppressWarnings("deprecation")
    ApiInfo info=new ApiInfo(
             "itsource20190427crud测试",
             "一个完成crud",
             "v1",
             "http://www.itsource.cn",
             "zytest",
             "apache",
             "http://www.itsource.cn");
     return info;
}

}

不要忘记扫描包

前后端分离前台基于vue-element-admin模板-crud实现(掌握)

8-26SSM+ElementUI_第2张图片
自己注册下载一个模块下来改

你可能感兴趣的:(8-26SSM+ElementUI)