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

Spring SSM整合页面开发

SSM整合页面开发

1 准备工作

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

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

2 列表查询功能

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

3 添加功能

  • 前端代码
//弹出添加窗口
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 {@Autowiredprivate BookDao bookDao;//增删改的方法判断了影响的行数是否大于0,而不是固定返回truepublic boolean save(Book book) {return bookDao.save(book) > 0;}//增删改的方法判断了影响的行数是否大于0,而不是固定返回truepublic boolean update(Book book) {return bookDao.update(book) > 0;}//增删改的方法判断了影响的行数是否大于0,而不是固定返回truepublic 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();}
}

4 修改功能

  • 显示弹出框查询图书信息
//弹出编辑窗口
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();});
}

5 删除功能

// 删除
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("取消删除操作");});
}


http://www.mrgr.cn/news/19836.html

相关文章:

  • python办公自动化:使用`Python-PPTX`自动化与批量处理
  • js逆向--绕过debugger(一)
  • 网络编程(学习)2024.9.3
  • 万字详解 Redis
  • 手把手写深度学习(27):如果获得相机位姿态的plücker embedding?以RealEstate10K为例
  • RabbitMQ学习笔记
  • Windows 10/11下使用tar进行打包/解压
  • 【Linux】理解Linux中的软链接与硬链接
  • 【重学 MySQL】七、MySQL的登录
  • 恶意代码分析 | Lab1
  • Jedis 操作 Redis 数据结构全攻略
  • python面向过程、面向对象
  • p2p、分布式,区块链笔记(IPFS): 论文Merkle-CRDTs : Merkle-DAGs meet CRDTs
  • Java类和对象之构造方法与对象创建之计算数学中的分数值
  • chapter2_逻辑代数基础
  • 2024 NOIP 初赛复习计划
  • 探索Python中的Ellipsis:不仅仅是三个点
  • MySQL 的基础 一 (连接池, SQL接口, 查询解析器, 查询优化器, 存储引擎接口, 执行器)
  • 跟李沐学AI:循环神经网络RNN
  • LeetCode 算法:完全平方数 c++