eWebEdior 从数据库中读出转换到插件里的方法

contentnew=contentnew.replaceAll("&","&");
contentnew=contentnew.replaceAll("<","<");
contentnew=contentnew.replaceAll(" "," ");
contentnew=contentnew.replaceAll(">",">");
contentnew=contentnew.replaceAll("\"",""");
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1. 首先,我们需要添加以下依赖: ```xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>2.1.1</version> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>easyexcel</artifactId> <version>2.1.7</version> </dependency> ``` 2. 然后,我们需要创建一个实体类来保存Excel的数据: ```java @Data public class User { private Long id; private String name; private Integer age; } ``` 3. 接下来,我们需要创建一个Mapper类来处理数据库操作: ```java @Mapper public interface UserMapper { @Insert("insert into user(name, age) values(#{name}, #{age})") int insert(User user); @Select("select * from user") List<User> findAll(); } ``` 4. 然后,我们需要创建一个Controller类来处理Excel文件的读取和保存: ```java @RestController @RequestMapping("/user") public class UserController { @Autowired private UserMapper userMapper; @PostMapping("/import") public String importExcel(MultipartFile file) throws IOException { // 读取Excel文件 InputStream inputStream = file.getInputStream(); List<User> userList = EasyExcel.read(inputStream).head(User.class).sheet().doReadSync(); // 将数据保存到数据库 for (User user : userList) { userMapper.insert(user); } return "导入成功"; } @GetMapping("/export") public void exportExcel(HttpServletResponse response) throws IOException { // 从数据库读取数据 List<User> userList = userMapper.findAll(); // 将数据保存到Excel文件 OutputStream outputStream = response.getOutputStream(); response.setContentType("application/vnd.ms-excel"); response.setHeader("Content-disposition", "attachment;filename=user.xlsx"); EasyExcel.write(outputStream, User.class).sheet().doWrite(userList); } } ``` 5. 最后,我们需要在application.properties文件配置数据库连接信息: ```properties spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver spring.datasource.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8 spring.datasource.username=root spring.datasource.password=root ``` 完成以上步骤后,我们就可以通过访问/user/import接口来导入Excel文件的数据,通过访问/user/export接口来将数据库的数据导出到Excel文件
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值