如何将jsp代码转换成thymeleaf语法?-灵析社区

皮皮踢

List bgnr=new ArrayList(); for(int ii=0;ii "+ nr.get(ii)+" "); } int bgnr_ln=bgnr.size(); float trHeight=9.0f; float trHeight1=9.0f; //第二页行高 float trHeight2=9.0f; //最后一页行高 int pcount=2;//总页数 int wpcount=0;// int flnum=0;//第二页行数 int lnum=25;//中间也行数 固定 int elnum=0;//最后一页行数 int nullLn=0;//最后一页空行数 int Cll=0; int Lln=0; if(bgnr_ln7.6f) trHeight1=7.6f; trHeight2=trHeight1; } }else{ wpcount=(bgnr_ln-23)/lnum; pcount=pcount+wpcount+1; Lln=(bgnr_ln-23)%lnum; if(Lln==0){ flnum=23; elnum=25; pcount--; wpcount--; trHeight2=7.4f; // trHeight2=trHeight1; }else{ flnum=23; elnum=Lln; nullLn=27-Lln-8; trHeight2=244.0f/(Lln+8); if(trHeight2>9.0f) trHeight2=9.0f; } } %>

阅读量:160

点赞量:0

问AI
首先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: