5.前后端分离
最编程
2024-04-20 21:20:08
...
目录
一、前后端分离上传文件
1.在yml中设置port和localhost
2.如何使用postman测试上传文件的接口
二、如何导出excel文件
编辑1.在pom.xml中导包
2.在实体类中给每个字段添加注解,导出表格时,列名将会改为对应的中文
3.controller中方法的具体代码
一、前后端分离上传文件
1.在yml中设置port和localhost
yml文件:
contorller文件:
使用两个value注解用于接收变量的值
这样做的好处是,后期在云服务器部署时,只需要在yml中修改localhost即可。
2.如何使用postman测试上传文件的接口
1.可以使用Body,选择为变量类型为file
2.使用binary,点击上传
二、如何导出excel文件
1.在pom.xml中导包
<!--导出文件需要的依赖 -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>5.2.3</version>
</dependency>
2.在实体类中给每个字段添加注解,导出表格时,列名将会改为对应的中文
添加@Alias注解的前后效果:
3.controller中方法的具体代码
/**
* 批量导出数据
* 文件下载类型的数据通常使用void
* required = false 可以不传
*/
@GetMapping("/export")
public void exportData(@RequestParam(required = false) String username,
@RequestParam(required = false) String name,
HttpServletResponse response) throws IOException {
//写入excel表中
ExcelWriter writer = ExcelUtil.getWriter(true);
List<User> list = new ArrayList<>();
//1.全部导出
if(StrUtil.isBlank(username) &&StrUtil.isBlank(name)){
list = userService.list(); //查询出当前user表的所有数据
}
writer.write(list,true);
//导出excel,必须设置的浏览器格式
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
//设置导出文件的名称 inline预览,attachment附件
response.setHeader("Content-Disposition","attachment;filename="+ URLEncoder.encode("用户信息表","UTF-8") + ".xlsx");
//通过response写成流的方式
ServletOutputStream outputStream = response.getOutputStream();
writer.flush(outputStream,true);//把writer中的对象刷新到数据流outputStream中
writer.close();
//isCloseOut是否在刷新完成后关闭输出流
outputStream.flush();//刷新
outputStream.close();//关闭
}
推荐阅读
-
企业级项目实战品达物流TMS(资料齐全)SpringCloud+SpringBoot+Vue+Mybatis-Plus+Docker19套JAVA企业级大型项目实战前后端分离/微服务/云原生/分布式/高并发/高可用/中间平台策略项目架构、百亿级项目实战、金融项目实战JAVA项目、物联网项目、项目面试实战、秒杀项目实战、租房项目实战、在线教育项目实战、权限系统实战、股票交易项目、短信平台实战、房源平台项目实战、工作流项目实战。
-
若翼若翼框架前后端分离版本汇总(傻瓜式操作)
-
蓝鲸 SaaS 开发构建 Django + Vue 前后端分离的开发框架
-
什么是数据库事物?为什么需要数据库事物,事物有哪些特征?事物的隔离级别是什么?-1.什么是数据库事务? 1.事务是作为一个逻辑单元执行的一系列操作。一个逻辑工作单元必须具备四个属性,即ACID(原子性、一致性、隔离性和持久性)属性,只有这样才能成为事务: 原子性 2.事务必须是一个原子工作单元;它的数据修改要么全部执行,要么全部不执行。 一致性 3.事务完成时,所有数据必须保持一致。在相关数据库中,所有规则都必须适用于事务的修改,以保持所有数据的完整性。事务结束时,所有内部数据结构(如 B 树索引或双向链接表)必须正确无误。 隔离 4.并发事务的修改必须与其他并发事务的修改隔离。一个事务会在另一个并发事务修改之前或之后查看某一状态下的数据,而不会查看中间状态下的数据。这就是所谓的可序列化,因为它允许重新加载起始数据和重放一系列事务,从而使数据最终处于与原始事务执行时相同的状态。 持久性 5.事务完成后,它对系统的影响是永久性的。即使在系统发生故障的情况下,修改也会保留。 2. 为什么需要数据库事物,事物有哪些特征? 事物对数据库的作用是对数据进行一系列操作,要么全部成功,要么全部失败,防止出现中间状态,确保数据库中的数据始终处于正确、和谐的状态。 特征:原子性、一致性、隔离性、持久性,以及其他特征 原子性(Atomicity):所有操作在事务开始后,要么全部做完,要么全部不做,不可能停滞在中间环节。事务执行过程中出现错误时,会回滚到事务开始前的状态,所有操作就像没有发生一样。也就是说,事务是一个不可分割的整体,就像化学中的原子一样,是物质的基本单位。 一致性(Consistency):在事务开始之前和结束之后,数据库的完整性约束都没有被破坏。例如,如果 A 转钱给 B,A 不可能扣除这笔钱,但 B 却没有收到这笔钱。 隔离:在同一时间内,只允许一个事务请求相同的数据,不同事务之间没有干扰。例如,甲正在从一张银行卡上取款,在甲取款过程结束之前,乙不能向这张卡转账。 持久性(耐用性):事务完成后,事务对数据库的所有更新都将保存到数据库中,无法回滚 3.事务的隔离级别有哪些? 数据库事务有四种隔离级别,从低到高分别是未提交读取(Read uncommitted)、已提交读取(Read committed)、可重复读取(Repeatable read)、可序列化(Serializable)。此外,事务的并发操作中可能会出现脏读、不可重复读、幽灵读等情况。事务并发问题 脏读:事务 A 读取事务 B 更新的数据,然后事务 B 回滚操作,那么事务 A 读取的数据就是脏数据。 不可重复读取:事务 A 多次读取同一数据,事务 B 在事务 A 多次读取期间更新并提交数据,导致事务 A 多次读取同一数据时结果不一致。 幻影读取:系统管理员 A 将数据库中所有学生的具体分数改为 ABCDE 等级,但系统管理员 B 在此时插入了具体分数的记录,当系统管理员 A 更改结束后发现仍有一条记录未被更改,仿佛发生了幻觉,这称为幻影读取。 小结:不可重复读和幻读容易混淆,不可重复读侧重于修改,幻读侧重于增删。解决不可重复读问题只需锁定满足条件的行,解决幻读问题则需要锁定表 MySQL 事务隔离级别
-
5.前后端分离
-
[CodeIgniter4] 前端和后端跨域分离问题
-
Vue3+TP6+API社交电商系统实战(前后端分离) - 免费在线视频教学 - php中文网
-
java 项目管理系统源代码 + 项目描述 + 功能描述 + 前后端分离 + 二次开发
-
前后端分离知识点讲解实战 - 蓝莓皮音乐社区项目 - 免费在线视频教学 - php.cn
-
最详细的 DataEase-V1 部署前后端分离教程