首先jsp操作数据的逻辑和展示数据的逻辑是可以混在一起写的,thymeleaf一般只作为展示页面使用,不涉及对数据的操作,虽然它俩本质上都是前后端不分离,但是还是有区别的,我直接问AI把这两部分拆开写了,你可以尝试下: import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import java.util.ArrayList; import java.util.List; @Controller public class MyController { @GetMapping("/my-page") public String myPage(Model model) { List nr = // 初始化你的nr列表(从数据库或其他来源获取) List bgnr = new ArrayList(); for (int ii = 0; ii " + nr.get(ii) + ""); } // ... 实现其他逻辑,计算pcount, wpcount, flnum, lnum, elnum, nullLn, Cll, Lln等变量 // 将处理后的数据添加到Model中供前端模板使用 model.addAttribute("bgnr", bgnr); model.addAttribute("pcount", pcount); // ... 添加其他需要在前端展示的变量 return "my-template"; // 前端对应的Thymeleaf模板名 } } 页面: Total pages: