常用框架xml文件头

MyBetis-config

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>


</configuration>

Mapper

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="">

</mapper>

Spring/SpringAOP

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
	http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">



</beans>
  • 10
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Spring Boot 框架本身并没有提供导出 Excel 文件的功能,但可以通过使用一些第三方库来实现。 以下是一种常用的方式: 1. 添加依赖 在 pom.xml 文件中添加以下依赖: ```xml <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>4.1.2</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml</artifactId> <version>4.1.2</version> </dependency> ``` 这两个依赖分别提供了对 Excel 文件的读写操作。 2. 编写代码 下面是一个简单的示例代码: ```java import org.apache.poi.ss.usermodel.*; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.springframework.stereotype.Service; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.List; @Service public class ExcelService { public void exportExcel(List<Student> students, HttpServletResponse response) throws IOException { // 创建 Workbook 对象 Workbook workbook = new XSSFWorkbook(); // 创建 Sheet 对象 Sheet sheet = workbook.createSheet("学生信息"); // 创建表 Row headerRow = sheet.createRow(0); Cell headerCell1 = headerRow.createCell(0); headerCell1.setCellValue("学号"); Cell headerCell2 = headerRow.createCell(1); headerCell2.setCellValue("姓名"); Cell headerCell3 = headerRow.createCell(2); headerCell3.setCellValue("性别"); // 填充数据 int rowIndex = 1; for (Student student : students) { Row row = sheet.createRow(rowIndex++); Cell cell1 = row.createCell(0); cell1.setCellValue(student.getStudentId()); Cell cell2 = row.createCell(1); cell2.setCellValue(student.getName()); Cell cell3 = row.createCell(2); cell3.setCellValue(student.getGender()); } // 设置响应 response.setContentType("application/vnd.ms-excel"); response.setHeader("Content-disposition", "attachment;filename=students.xlsx"); // 输出到响应流 workbook.write(response.getOutputStream()); // 关闭 Workbook 对象 workbook.close(); } } ``` 这个示例代码中,我们创建了一个 `ExcelService` 类,其中有一个 `exportExcel()` 方法,该方法接受一个学生列表和一个 `HttpServletResponse` 对象作为参数。该方法会创建一个 Workbook 对象,然后创建一个名为“学生信息”的 Sheet 对象,并填充数据。最后,将 Workbook 对象输出到响应流,实现文件导出。 注意,这里使用的是 XSSFWorkbook 类来创建 Workbook 对象,因为它支持新的 xlsx 格式。如果要支持旧的 xls 格式,可以使用 HSSFWorkbook 类。 3. 调用方法 在控制器中调用 `ExcelService` 的 `exportExcel()` 方法,传入学生列表和响应对象即可实现导出 Excel 文件。 ```java import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.ArrayList; import java.util.List; @RestController public class StudentController { @Autowired private ExcelService excelService; @GetMapping("/students/export") public void exportStudents(HttpServletResponse response) throws IOException { List<Student> students = new ArrayList<>(); // ... 从数据库或其他地方获取学生列表 excelService.exportExcel(students, response); } } ``` 在上面的代码中,我们通过 `@Autowired` 注解将 `ExcelService` 对象注入到控制器中,然后在 `exportStudents()` 方法中调用 `exportExcel()` 方法实现导出。最后,我们可以在浏览器中访问 `/students/export` 路径,就会自动下载一个名为“students.xlsx”的 Excel 文件。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值