项目代码下载:https://files.cnblogs.com/files/xiandedanteng/gatling20200429-1.zip

需求:从后台DB取出雇员数据,显示在前台页面上:

实现步骤

1.添加thymeleaf依赖。看到thymeleaf你是否记起它出现在那首著名的斯卡波罗菜市场呢?

<!-- thymeleaf -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

2.书写控制器

package com.ufo.gatling.ctrl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView; import com.ufo.gatling.entity.Emp;
import com.ufo.gatling.mapper.EmpMapper; @Controller
public class MvcCtrl {
@Autowired
private EmpMapper empMapper=null; // http://localhost:8080/listemps
@GetMapping("/listemps")
public ModelAndView index() {
List<Emp> list=empMapper.findAll(); ModelAndView mv=new ModelAndView("index");
mv.addObject("empList", list);
return mv;
} 。。。
}

3.在/gatling/src/main/resources/templates/下书写页面index.html,内容如下:

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<table border="1px">
<caption>All employees</caption>
<thead>
<tr><th>id</th><th>name</th><th>salary</th></tr>
</thead>
<tbody>
<tr th:each="item:${empList}">
<td th:text="${item.id}">id</td>
<td th:text="${item.name}">name</td>
<td th:text="${item.salary}">salary</td>
</tr>
</tbody>
</table>
</body>
</html>

4.在浏览器中输入:http://localhost:8080/listemps,就会看到以下页面:

--2020-04-29--

把Employees显示在页面上的更多相关文章

  1. 【WPF学习笔记】之如何把数据库里的值读取出来然后显示在页面上:动画系列之(六)(评论处有学习资料及源码)

    (应博友们的需要,在文章评论处有源码链接地址,以及WPF学习资料.工具等,希望对大家有所帮助) ...... 承接系列五 上一节讲了,已经把数据保存到数据库并且删除数据,本讲是把已经存在的数据从数据库 ...

  2. echarts如何显示在页面上

    echarts如何显示在页面上 1.引入echarts的相关.js文件 <script src="js/echarts.min.js"></script> ...

  3. 数据量大的数据转换成jason并显示在页面上

    代码列子: public ActionResult FindUserByUserId(SysMessageDTO model) { CustomResultMsg customResult = new ...

  4. js获取当前时间显示在页面上

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  5. struts中用kindeditor实现的图片上传并且显示在页面上

    做公司网站的时候由于需要在内容属性中加入图片,所以就有了这个问题,本来一开始找几篇文章看都是讲修改kindeditor/jsp/file_manager_json.jsp和upload_json.js ...

  6. WordPress 之 在注册界面 实现 注册后密码直接显示在页面上

    前言:WordPress 功能无疑强大的,但有些功能实现上还是有少许不尽人意,比如在 网站上有新用户注册后,必须下发到用户填写的邮件才能接收到新密码,而密码又是系统自动生成的,如果因为某些原因用户接收 ...

  7. vue 上传文件 并以表格形式显示在页面上

    先上代码 <label for="file" class="btn">多文件上传</label> <input type=&quo ...

  8. 微信小程序云开发-云存储-上传单张照片到云存储并显示到页面上

    一.wxml文件 页面上写上传图片的按钮,按钮绑定chooseImg. <button bindtap="chooseImg" type="primary" ...

  9. HTML标签显示在页面上

    用 <xmp></xmp> 标签包起来,里面的所有文字会原样显示出来 <xmp><P>1</P><div>2</div&g ...

随机推荐

  1. Coders' Legacy 2020 题解

    目录 Chef vs Doof Doof on Cartesian Doof fires Brackets Jeremy gets a gift Unique Substring Perry lear ...

  2. CSS3 新添选择器

    目录 属性选择器 结构伪类选择器 伪元素选择器 属性选择器 属性选择器可以元素特定属性来进行选择,这样就可以不借助于类选择器或id选择器 选择符 简述 E[att] 选择具有att属性的E元素 E[a ...

  3. 2020-06-13:Redis底层数据结构?

    福哥答案2020-06-13: 福哥口诀法:简链字跳整 压快压 SDS simple synamic string:简单动态字符串.支持自动动态扩容的字节数组 .list :链表 .双端链表.dict ...

  4. C#LeetCode刷题之#225-用队列实现栈(Implement Stack using Queues)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/4106 访问. 使用队列实现栈的下列操作: push(x) -- ...

  5. C#LeetCode刷题之#206-反转链表(Reverse Linked List)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3828 访问. 反转一个单链表. 输入: 1->2-> ...

  6. run as --> Maven clean 可以清除旧的jar包

    run as --> Maven clean 可以清除旧的jar包

  7. JavaScript 基础四

    遍历对象的属性 for...in 语句用于对数组或者对象的属性进行循环操作. for (变量 in 对象名字) { 在此执行代码 } 这个变量是自定义 符合命名规范 但是一般我们 都写为 k 或则 k ...

  8. MIT 6.828 Lab04 : Preemptive Multitasking

    目录 Part A:Multiprocessor Support and Cooperative Multitasking Multiprocessor Support 虚拟内存图 Exercise ...

  9. 大整数加法C++(计蒜客)

    求两个不超过 200200 位的非负整数的和. 输入格式 有两行,每行是一个不超过 200200 位的非负整数,可能有多余的前导 00. 输出格式 一行,即相加后的结果.结果里不能有多余的前导 00, ...

  10. 笔记:html基础

    一.HTML:超文本标记语言,是一种标签语言,不是编程语言,显示数据有双标签<body></body> 和单标签<img src=# / >, 标签大小写都可以 通 ...