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 ...
随机推荐
- SQLite多线程使用总结
SQLite支持3种线程模式: 单线程:这种模式下,没有进行互斥,多线程使用不安全.禁用所有的mutex锁,并发使用时会出错.当SQLite编译时加了SQLITE_THREADSAFE=0参数,或者在 ...
- 封装class类为jar包提供给其他项目使用
一.完成class类的编写与测试工作 二.完善javadoc注释,生成自己的API 注释要按照标准要求进行 Project -- generate javadoc
- eclipse 查找controller
一.打开eclipse: 二.同时按住Ctrl + Shift + R ; 弹出框如下: 在红色输入框内输入controller 名字即可. 查找控制器里面的方法:Ctrl + O
- 关于yolo 模型中1X1卷积层的作用
1X1卷积层的作用: 1.实现跨通道的交互和信息整合.2.进行卷积核通道数的降维和升维.3.就是可以在保持feature map 尺寸不变(即不损失分辨率)的前提下大幅增加非线性特性,把网络做得很de ...
- Tyvj1052(树形DP)
P1052 没有上司的舞会 时间: 1000ms / 空间: 131072KiB / Java类名: Main 描述 Ural大学有N个职员,编号为1~N.他们有从属关系,也就是说他们的关系就像一棵以 ...
- UnicodeEncodeError: 'ascii' codec can't encode character u'\u65e0' in position 1: ordinal not in range(128)
UnicodeEncodeError: 'ascii' codec can't encode character u'\u65e0' in position 1: ordinal not in ran ...
- glance image-create
glance image-create
- Flutter实战视频-移动电商-65.会员中心_订单区域UI布局
65.会员中心_订单区域UI布局 我的订单区域 member.dart写我的标题的方法 布局使用瓦片布局 先做修饰,decoration颜色的背景,下边线的样式 //我的订单标题 Widget _or ...
- 3-1Java程序的执行流程
3-1Java程序的执行流程 用记事本写一个简单的程序 存到:E:\java路径下 class HelloImooc{ public static void main(String[] agrg ...
- 2019Unite大会
一年一度的Unite大会,在今年(2019)的5月10日准时在上海的国际会议中心盛大举行.本届大会历时三天,由来自全球的Unity公司技术专家.开发者.艺术家和Unity爱好者们齐聚一堂,展示Unit ...