当前位置: 首页 > news >正文

[SpringMVC] SSM整合-前后台协议联调

✨✨个人主页:沫洺的主页

 📚📚系列专栏: 📖 JavaWeb专栏📖 JavaSE专栏 📖 Java基础专栏📖vue3专栏 

                           📖MyBatis专栏📖Spring专栏📖SpringMVC专栏

💖💖如果文章对你有所帮助请留下三连✨✨

🥏SSM整合页面开发 

前端静态页面源码SSM功能页面

链接:https://pan.baidu.com/s/1eEYoox8WIwEn0UMrkSuCEg?pwd=mozs 

为了确保静态资源能够被访问到,需要设置静态资源过滤

@Configuration
public class SpringMvcSupport extends WebMvcConfigurationSupport {
    @Override
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/pages/**")
            .addResourceLocations("/pages/");
        registry.addResourceHandler("/css/**")
            .addResourceLocations("/css/");
        registry.addResourceHandler("/js/**")
            .addResourceLocations("/js/");
        registry.addResourceHandler("/plugins/**")
            .addResourceLocations("/plugins/");
    }
}

SpringMvc加载配置

@Configuration
@ComponentScan({"com.moming.controller","com.moming.config"})
//开启json数据类型自动转换
@EnableWebMvc
public class SpringMvcConfig {
}

列表查询功能

前端代码

//列表
getAll() {
    //发送ajax请求
    axios.get("/books").then((res)=>{
        this.dataList = res.data.data;
    });
}

添加功能

前端代码

//弹出添加窗口
handleCreate() {
    this.dialogFormVisible = true;
    this.resetForm();
},
//重置表单
resetForm() {
    this.formData = {};
},
//添加
handleAdd () {
    //发送ajax请求
    axios.post("/books",this.formData).then((res)=>{
        console.log(res.data);
        //如果操作成功,关闭弹层,显示数据
        if(res.data.code == 20011){
            this.dialogFormVisible = false;
            this.$message.success("添加成功");
        }else if(res.data.code == 20010){
            this.$message.error("添加失败");
        }else{
            this.$message.error(res.data.msg);
        }
    }).finally(()=>{
        this.getAll();
    });
},

 后台代码改进

@Service
public class BookServiceImpl implements BookService {
    @Autowired
    private BookDao bookDao;
    //增删改的方法判断了影响的行数是否大于0,而不是固定返回true
    public boolean save(Book book) {
        return bookDao.save(book) > 0;
    }
    //增删改的方法判断了影响的行数是否大于0,而不是固定返回true
    public boolean update(Book book) {
        return bookDao.update(book) > 0;
    }
    //增删改的方法判断了影响的行数是否大于0,而不是固定返回true
    public boolean delete(Integer id) {
        return bookDao.delete(id) > 0;
    }
​
    public Book getById(Integer id) {
        if(id < 0){
            throw new BusinessException(Code.BUSINESS_ERR,"项目业务级异常!");
            return bookDao.getById(id);
        }
    }
    public List<Book> getAll() {
        return bookDao.getAll();
    }
}

修改功能

显示弹出框查询图书信息

//弹出编辑窗口
handleUpdate(row) {
    // console.log(row);   //row.id 查询条件
    //查询数据,根据id查询
    axios.get("/books/"+row.id).then((res)=>{
        // console.log(res.data.data);
        if(res.data.code == 20041){
            //展示弹层,加载数据
            this.formData = res.data.data;
            this.dialogFormVisible4Edit = true;
        }else{
            this.$message.error(res.data.msg);
        }
    });
}

 保存修改后的图书信息

//编辑
handleEdit() {
    //发送ajax请求
    axios.put("/books",this.formData).then((res)=>{
        //如果操作成功,关闭弹层,显示数据
        if(res.data.code == 20031){
            this.dialogFormVisible4Edit = false;
            this.$message.success("修改成功");
        }else if(res.data.code == 20030){
            this.$message.error("修改失败");
        }else{
            this.$message.error(res.data.msg);
        }
    }).finally(()=>{
        this.getAll();
    });
}

删除功能

// 删除
handleDelete(row) {
    //1.弹出提示框
    this.$confirm("此操作永久删除当前数据,是否继续?","提示",{
        type:'info'
    }).then(()=>{
        //2.做删除业务
        axios.delete("/books/"+row.id).then((res)=>{
            if(res.data.code == 20021){
                this.$message.success("删除成功");
            }else{
                this.$message.error("删除失败");
            }
        }).finally(()=>{
            this.getAll();
        });
    }).catch(()=>{
        //3.取消删除
        this.$message.info("取消删除操作");
    });
}

相关文章:

  • DOM操作.操作元素内容
  • 【Java SE】String类
  • 数据可视化看板:基于 Echarts + Python Flask 动态实时大屏
  • 5道真题训练|学会了二叉树的前世今生
  • python专区--时间模块
  • 36、Java 中的 String、StringBuilder、StringBuffer、字符串常量池和 intern 方法
  • 基于正交设计的折射反向学习樽海鞘群算法
  • 国庆假期浏览了几十篇YOLO改进英文期刊,总结改进创新的一些相同点(期刊创新点持续更新)
  • 《计算机视觉基础知识蓝皮书》第5篇 目标检测基础
  • 提升能力和认知边界,最有效的方法是赚钱
  • Window下使用RegisterWindowMessage来实现消息通讯
  • Java 数组、排序和查找(1)
  • 你还没用过Mybatis-Plus?丝般顺滑,快速上手!
  • css3d动画:平移、旋转、缩放
  • 【英语:基础进阶_正式场景表达】F1.五步法搞定英文面试
  • [iOS]Core Data浅析一 -- 启用Core Data
  • 【面试系列】之二:关于js原型
  • Android Studio:GIT提交项目到远程仓库
  • Android系统模拟器绘制实现概述
  • idea + plantuml 画流程图
  • Java Agent 学习笔记
  • Laravel核心解读--Facades
  • MyEclipse 8.0 GA 搭建 Struts2 + Spring2 + Hibernate3 (测试)
  • npx命令介绍
  • SAP云平台运行环境Cloud Foundry和Neo的区别
  • sessionStorage和localStorage
  • 短视频宝贝=慢?阿里巴巴工程师这样秒开短视频
  • 复杂数据处理
  • 力扣(LeetCode)21
  • 前端自动化解决方案
  • 使用 @font-face
  • 小程序、APP Store 需要的 SSL 证书是个什么东西?
  • 用Canvas画一棵二叉树
  • 7行Python代码的人脸识别
  • #Linux(权限管理)
  • $forceUpdate()函数
  • (02)Hive SQL编译成MapReduce任务的过程
  • (1)(1.8) MSP(MultiWii 串行协议)(4.1 版)
  • (70min)字节暑假实习二面(已挂)
  • (done) ROC曲线 和 AUC值 分别是什么?
  • (分布式缓存)Redis哨兵
  • (附源码)ssm高校运动会管理系统 毕业设计 020419
  • (机器学习的矩阵)(向量、矩阵与多元线性回归)
  • (转)http-server应用
  • .bat批处理(二):%0 %1——给批处理脚本传递参数
  • .net Application的目录
  • .net CHARTING图表控件下载地址
  • .NET 应用架构指导 V2 学习笔记(一) 软件架构的关键原则
  • :中兴通讯为何成功
  • @configuration注解_2w字长文给你讲透了配置类为什么要添加 @Configuration注解
  • @JSONField或@JsonProperty注解使用
  • @vue/cli脚手架
  • @软考考生,这份软考高分攻略你须知道
  • [20170705]diff比较执行结果的内容.txt
  • [C# 网络编程系列]专题六:UDP编程