栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

ssm整合——ssm+elementui+vue+axios完成单表的crud.

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

ssm整合——ssm+elementui+vue+axios完成单表的crud.

1.ssm整合的原理

2.创建maven工程并配置

1)web更换为4.0,之前版本过低会出严重bug

2)引入所需依赖

 引入依赖



    
    
      com.github.pagehelper
      pagehelper
      5.3.0
    

    
    
      org.springframework
      spring-webmvc
      5.2.15.RELEASE
    

    
    
      org.mybatis
      mybatis
      3.5.6
    

    
    
      org.mybatis
      mybatis-spring
      2.0.6
    

    
    
      mysql
      mysql-connector-java
      8.0.28
    

    
    
      com.alibaba
      druid
      1.2.4
    

    
    
      org.projectlombok
      lombok
      1.18.24
    
    
    
      com.fasterxml.jackson.core
      jackson-databind
      2.13.2.2
    
    
    
      javax.servlet
      javax.servlet-api
      4.0.1
    

    
    
      org.springframework
      spring-jdbc
      5.2.15.RELEASE
    

    
    
      org.mybatis.generator
      mybatis-generator-core
      1.4.0
    

    
    
      junit
      junit
      4.12
      compile
    

  

3)spring配置文件

    
    

    
    

    
    

    
    
        
        
        
        
        
        
        
        
        
    

    
    
        
        
        
        
            
                
            
        
    

    
    
        
        
    

4)web配置文件

 
        dispatcherServlet
        org.springframework.web.servlet.DispatcherServlet
        
            contextConfigLocation
            classpath:appliction.xml
        
        
        1
    
    
        dispatcherServlet
        /
    

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

5)使用generator快速生成代码





    
    

    
        
        
            
        

        
        
                        
        

        
            
        

        
        
            
            
        

        
        
            
        

        
        
            
        

        
        

测试代码:

public class TestGenerator {

    @Test
    public void test02() throws Exception{
        List warnings = new ArrayList();
        boolean overwrite = true;
        File configFile = new File("generator.xml");
        ConfigurationParser cp = new ConfigurationParser(warnings);
        Configuration config = cp.parseConfiguration(configFile);
        DefaultShellCallback callback = new DefaultShellCallback(overwrite);
        MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
        myBatisGenerator.generate(null);
    }
}

使用 generator生成了dao、entity、mapper文件

3.实现主页面(查询)

service实体类层代码:

@Service
public class StudentServiceImpl implements StudentService {

    //交予spring管理
    @Autowired
    private StudentMapper sm;

    public PageInfo find(Integer currentPage, Integer pageSize,Map map) {
        PageHelper.startPage(currentPage,pageSize);
        List l = sm.findAll(map);
        PageInfo pageInfo = new PageInfo(l);
        return pageInfo;
    }
}

controller操作层代码:

@RestController
@RequestMapping("student")
public class StudentController {

    @Autowired
    private StudentService ss;

   
    //查询
    @RequestMapping("select")
    public CommonResult select(Integer currentPage, Integer pageSize, @RequestBody Map map){
        PageInfo lsit = ss.find(currentPage, pageSize,map);
        return new CommonResult(2000,"查询成功",lsit);
    }
}

前端界面代码:

<%--
  Created by IntelliJ IDEA.
  User: Z
  Date: 2022/6/15
  Time: 15:23
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>


    Title
    
    
    
    
    
    
    
    




    添加
    退出
    <%--搜索框--%>
    
        
            
        
        
            
        
        
            查询
        
    
    
        
        
            
                
            
            
                
            
        
        
    取 消
    确 定
  
    

    
        

        
            
                
            
            
                
            
        
        
            取 消
            确 定
        
    

    
        
        
        
        
        
        
        
            
        


    

    <%--
        分页组件
        size-change:页面显示条数改变时触发的事件
        current-change:页码改变时触发的事件
        current-page:当前的页面
        page-sizes:接受一个整型数组,数组元素为展示的选择每页显示个数的选项
        page-size:每页显示的条数
    --%>
    
    



4.添加

service层

//添加
    public CommonResult add(Student s) {
        int i = sm.insert(s);
        return new CommonResult(2000,"添加成功",null);
    }

controller操作层:

//添加
    @RequestMapping("insert")
    public CommonResult insert(Student s){
        CommonResult add = ss.add(s);
        return add;
    }
 5.修改

service层

//修改
    public CommonResult upd(Student s) {
        int i = sm.updateByPrimaryKey(s);
        return new CommonResult(2000,"修改成功",null);
    }

controller操作层:

//修改
    @RequestMapping("update")
    public CommonResult update(Student s){
        CommonResult upd = ss.upd(s);
        return upd;
    }
6.删除

service层

//删除
    public CommonResult del(Integer id) {
        int i = sm.deleteByPrimaryKey(id);
        return new CommonResult(2000,"删除成功",null);
    }

controller操作层:

//删除
    @RequestMapping("delete")
    public CommonResult delete(Integer id){
        CommonResult del = ss.del(id);
        return del;
    }
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/981193.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号