不多说了 首先滤清思路
这是一套正常的curd架构(这里由于浪费时间所以我只写了新增其他代码用mp就能随便写)
注意 本篇文章最重要的
就是这四个配置类 (结束后会放在最后)
FileUpload用于指定用户文件upload的服务器指定位置
ObjectExcelRead用于导出功能
ObjectExcelView用于做导出功能
PageData用于查出数据
application.yml的配置
server:
port: 80
spring:
thymeleaf:
cache: false # 这个开发配置为false,避免改了模板还要重启服务器
prefix: classpath:/templates/ #模板文件视图前缀,默认是classpath:/templates/,可不用配置
suffix: .html
mvc:
view:
suffix: .html
prefix:
datasource:
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/spring?serverTimezone=UTC
username: root
password: xjy
mybatis-plus:
global-config:
db-config:
id-type: auto
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
在resource的资源加入
html显示数据要用
然后编写Controller类
@Controller
@RequestMapping("/goods")
public class goodsController {
@Autowired
private GoodsService goodsService;
@RequestMapping("/excel")
public ModelAndView exportExcel() {
ModelAndView mv = new ModelAndView();
try {
Map<String, Object> dataMap = new HashMap<>();
List<String> titles = new ArrayList<>();
titles.add("商品编号"); // 1
titles.add("名称"); // 2
titles.add("数量");//3
dataMap.put("titles", titles);
List<Goods> varOList = goodsService.queryAllExcel();
List<Pa