SpringBoot | Thymeleaf | 局部更新
建立一个实体类:
public class Fruit {
int id;
String name;
public Fruit() {
}
public Fruit(int id, String name) {
this.id = id;
this.name = name;
}
//省略get和set方法
}
建立一个控制类:
package org.project.controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping; import java.util.ArrayList;
import java.util.List; @Controller
public class FruitController { @RequestMapping("/fruit")
public String fruit(Model model){
return "fruit";
} @RequestMapping("/fruit/detail")
public String detail(Model model,int id) { List<Fruit> fruits = new ArrayList<>(); if(id == 0) {
String[] strings={"香蕉","苹果","凤梨","西瓜"};
for(int i = 1; i <= strings.length; i++) {
fruits.add(new Fruit(i,strings[i-1]));
}
} else if(id == 1) {
String[] strings={"菠萝","草莓","西红柿","黑莓","百香果","葡萄"};
for(int i = 1; i <= strings.length; i++) {
fruits.add(new Fruit(i,strings[i-1]));
}
}
model.addAttribute("fruits",fruits);
return "fruit::fruit-list";
}
}
前端代码:
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Thyleaf</title>
<script type="text/javascript" src="/lib/jquery/1.9.1/jquery.min.js"></script>
<script>
function ceshi1() {
$('#fruit-list').load("/fruit/detail?id=0");
}
function ceshi2() {
$('#fruit-list').load("/fruit/detail?id=1");
}
</script>
</head>
<body>
<button onclick="ceshi1()">测试1</button>
<button onclick="ceshi2()">测试2</button> <div id="fruit-list" style="text-align: center;margin:0 auto;width: 900px" th:fragment="fruit-list">
<table width="100%" border="1" cellspacing="1" cellpadding="0">
<thead>
<th>ID</th>
<th>水果名</th>
</thead>
<tbody>
<tr th:each="fruit : ${fruits}">
<td th:text="${fruit.id}"></td>
<td th:text="${fruit.name}"></td>
</tr>
</tbody>
</table>
</div> </body>
</html>
效果:


SpringBoot | Thymeleaf | 局部更新的更多相关文章
- org.springframework.expression.spel.SpelEvaluationException: EL1004E: Method call: Method service() cannot be found on com.my.blog.springboot.thymeleaf.util.MethodTest type
前言 本文中提到的解决方案,源码地址在:springboot-thymeleaf,希望可以帮你解决问题. 至于为什么已经写了一篇文章thymeleaf模板引擎调用java类中的方法,又多此一举的单独整 ...
- WebApiClient的JsonPatch局部更新
1. 文章目的 随着WebApiClient的不断完善,越来越多开发者选择WebApiClient替换原生的HttpClient,本文将介绍使用WebApiClient来完成JsonPatch提交的新 ...
- springboot+thymeleaf+pageHelper带条件分页查询
html层 <div> <a class="num"><b th:text="'共 '+ ${result.resultMap['pages ...
- 通过Solrj实现对索引库中数据的局部更新操作
for (UpdateIndexDTO updateIndexDTO : data) { // 局部更新 SolrInputDocument doc = new SolrInputDocument() ...
- springboot+thymeleaf简单使用
关于springboot想必很多人都在使用,由于公司项目一直使用的是SpringMVC,所以自己抽空体验了一下springboot的简单使用. 环境搭建 springbooot的环境搭建可以说很灵活, ...
- SpringBoot thymeleaf使用方法,thymeleaf模板迭代
SpringBoot thymeleaf使用方法,thymeleaf模板迭代 SpringBoot thymeleaf 循环List.Map ============================= ...
- SpringBoot thymeleaf模板页面没提示,SpringBoot thymeleaf模板插件安装
SpringBoot thymeleaf模板插件安装 SpringBoot thymeleaf模板Html页面没提示 SpringBoot thymeleaf模板页面没提示 SpringBoot t ...
- SpringBoot thymeleaf模板版本,thymeleaf模板更换版本
SpringBoot thymeleaf模板版本 thymeleaf模板更换版本 修改thymeleaf模板版本 ================================ ©Copyright ...
- .Net页面局部更新的思考
最近在修改以前做的模块,添加一个新功能.整理了下才发现重用率很低,大部分的东西还是需要重新写.功能里用到了局部更新,所有整理一下一路来实现局部更新的解决方案及改进. 我接触的项目开发大多是以Asp.n ...
随机推荐
- gradle中的 settings.gradle
gradle 默认只执行当前目录下的build.gradle 脚本,而我们的项目通常是有多个模块依赖的,这时需要我们对多个目录同时编译,那就需要我们创建一个settings.gradle 文件 如果 ...
- 远程请求json数据,list中显示
public class MainActivity extends Activity { protected static final int WHAT_REQUEST_SUCCESS = 1; pr ...
- 关于“telnet localhost:8080不能打开到主机的连接, 在端口 23: 连接失败”问题
你的命令写错了!不是telnet localhost:1433 是 telnet localhost 1433 不要那个:号 http://www.fengfly.com/ 答案补充 :“正在连接到l ...
- LightOJ1234 Harmonic Number —— 分区打表
题目链接:https://vjudge.net/problem/LightOJ-1234 1234 - Harmonic Number PDF (English) Statistics Foru ...
- 我在面试.NET/C#程序员时会提出的问题
我在面试.NET/C#程序员时会提出的问题 2011-03-03 15:38 by 老赵, 28107 visits 说起来我也面试过相当数量的.NET(包括C#,后文不重复)程序员了,有的通过电话, ...
- Centos下Docker安装与使用的相关命令
sudo yum install -y yum-utils device-mapper-persistent-data lvm2 systemctl docker status yum-config- ...
- 我的CSDN博客
从csdn搬过来的: csdn地址:http://blog.csdn.net/WR_technology
- nyoj 269 VF
VF 时间限制:1000 ms | 内存限制:65535 KB 链接:NYOJ269 原创在:点击打开链接 题意:1-1000000000之间,各位数字之和等于给定s的数的个数. 每行给出一个数s ...
- HihoCoder1576 子树中的最小权值( dfs序 +线段树 || 树剖)
给定一棵N个节点的树,编号1~N.其中1号节点是根,并且第i个节点的权值是Vi. 针对这棵树,小Hi会询问小Ho一系列问题.每次小Hi会指定一个节点x,询问小Ho以x为根的子树中,最小的权值是多少.为 ...
- eclipse代码编辑器中按alt+/提示No Default Proposals 的解决方法
window-> Preferences-> Java-> Editor-> Content Assist-> Advanced 上面的选项卡Select the pro ...