springboot 使用model重定向到html模板,对数据进行展示
1:使用springboot, ,html使用thymeleaf,nekohtml模板
在build.gradle中添加依赖
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath('org.springframework.boot:spring-boot-gradle-plugin:1.5.9.RELEASE')
}
}
group "com.li"
version "1.0-SNAPSHOT"
apply plugin: "java" //java 插件
apply plugin: "org.springframework.boot" //spring boot 插件
apply plugin: "io.spring.dependency-management"
apply plugin: "application" //应用
//mainClassName = "Main.Application"
sourceCompatibility = 1.8
repositories {
mavenCentral()
}8:
dependencies {
compile("org.springframework.boot:spring-boot-starter-web",
"org.springframework.boot:spring-boot-starter-test",
// "org.springframework.boot:spring-boot-starter-activemq:1.5.9.RELEASE",
"org.springframework.boot:spring-boot-starter-cache",
"org.springframework.boot:spring-boot-devtools",
// "org.mybatis.spring.boot:mybatis-spring-boot-starter:1.3.0",
"mysql:mysql-connector-java:5.1.35",
// 'org.apache.commons:commons-lang3:3.4',
// 'org.apache.commons:commons-pool2',
// 'org.apache.logging.log4j:log4j-core:2.7',
// 'org.springframework.boot:spring-boot-starter-security',
"org.springframework.boot:spring-boot-starter-thymeleaf",
"net.sourceforge.nekohtml:nekohtml"
)
// compile('commons-net:commons-net:3.1')
// runtime ("org.apache.tomcat.embed:tomcat-embed-jasper")
testCompile group: 'junit', name: 'junit', version: '4.12'
}
2: 在application.yml中进行配置
spring:
thymeleaf:
mode: LEGACYHTML5
cache: false
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/youhuigou
username: root
password: 1367356
3:定义一个对象,存放数据
package com.li.controller;
public class Parameter {
private String id;
private String name;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
4: controller层
package com.li.controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping; @Controller
@RequestMapping("/home")
public class HomeController { @RequestMapping("/home1")
public String home1(Model model) {
model.addAttribute("param1", 3);
Parameter parameter=new Parameter();
parameter.setId("111111");
parameter.setName("liyafei");
model.addAttribute("parame", parameter);
return "home";
}
}
5:启动类
package com.li; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication
public class SpringBootModelAndThymeleaf { public static void main(String[] args){
SpringApplication.run(SpringBootModelAndThymeleaf.class, args);
}
}
6:前端展示home.html
<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
</head>
<body>
<h1>${param1}</h1>
<div class="media-heading">
<span th:text="${param1}"></span>
<span th:text="${parame.id}"></span>
<span th:text="${parame.name}"></span>
</div>
</body>
</html>
7:启动项目,进行访问
http://localhost:8080/home/home1
结果

8:系统层次图

springboot 使用model重定向到html模板,对数据进行展示的更多相关文章
- SpringBoot常用Starter介绍和整合模板引擎Freemaker、thymeleaf 4节课
1.SpringBoot Starter讲解 简介:介绍什么是SpringBoot Starter和主要作用 1.官网地址:https://docs.spring.io/spring-boot/doc ...
- SpringBoot thymeleaf使用方法,thymeleaf模板迭代
SpringBoot thymeleaf使用方法,thymeleaf模板迭代 SpringBoot thymeleaf 循环List.Map ============================= ...
- springboot中model,modelandview,modelmap的区别与联系
springboot 中Model,ModelAndView,ModelMap的区别与联系 Model是一个接口,它的实现类为ExtendedModelMap,继承ModelMap类 public c ...
- SpringBoot + Vue + ElementUI 实现后台管理系统模板 -- 后端篇(五): 数据表设计、使用 jwt、redis、sms 工具类完善注册登录逻辑
(1) 相关博文地址: SpringBoot + Vue + ElementUI 实现后台管理系统模板 -- 前端篇(一):搭建基本环境:https://www.cnblogs.com/l-y-h/p ...
- SpringBoot + Vue + ElementUI 实现后台管理系统模板 -- 后端篇(一): 搭建基本环境、整合 Swagger、MyBatisPlus、JSR303 以及国际化操作
相关 (1) 相关博文地址: SpringBoot + Vue + ElementUI 实现后台管理系统模板 -- 前端篇(一):搭建基本环境:https://www.cnblogs.com/l-y- ...
- django 简易博客开发 2 模板和数据查询
首先还是贴一下项目地址 https://github.com/goodspeedcheng/sblog 因为代码全在上面 上一篇博客我们介绍了 django的安装配置,新建project,新建a ...
- java poi 从服务器下载模板写入数据再导出
最近写了一个,Excel 的 写入和导出. 需求是这样的. 在新建合同的时候,会有导出合同的数据, 导出的模板是固定的,,需要在模板里面写入合同的信息. first : 下载模板 ...
- python操作三大主流数据库(5)python操作mysql⑤使用Jinja2模板提取优化页面展示
python操作mysql⑤使用Jinja2模板提取优化页面展示 在templates目录下的index.html.cat.html等页面有一些共同的元素,代码比较冗余可以使用模板提取公共代码,在各网 ...
- 背水一战 Windows 10 (51) - 控件(集合类): ItemsControl - 项模板选择器, 数据分组
[源码下载] 背水一战 Windows 10 (51) - 控件(集合类): ItemsControl - 项模板选择器, 数据分组 作者:webabcd 介绍背水一战 Windows 10 之 控件 ...
随机推荐
- select2 选择框插件
<select id="selBusi_type"><select> //初始化业务类型下拉 var initBusiTypeSel = function( ...
- [spring] org.objectweb.asm.ClassVisitor.visit(IILjava/lang/String;Ljav 解决
严重: Exception sending context initialized event to listener instance of class org.springframework.we ...
- day08<面向对象+>
面向对象(代码块的概述和分类) 面向对象(代码块的面试题) 面向对象(继承案例演示) 面向对象(继承的好处和弊端) 面向对象(Java中类的继承特点) 面向对象(继承的注意事项和什么时候使用继承) 面 ...
- 【RF库Collections测试】Dictionary Should Contain Sub Dictionary
Name:Dictionary Should Contain Sub DictionarySource:Collections <test library>Arguments:[ dict ...
- Python 进阶(三)面向对象编程基础
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAkMAAAFGCAIAAADmfgziAAAgAElEQVR4nOx993vT1v7/93/5EEt2Eg
- qq邮箱发送,mail from address must be same as authorization user
由于邮箱发送的邮箱账号更换,所以重新测试.结果一直出错,要不就是请求超时,要不就是未授权. 用smtp 开始的时候,端口使用495,结果是请求超时. 后来改成25,结果是未授权. 再后来听人说,有一个 ...
- php之常量
前面的话 常量在javascript中并不存在,在php中却是与变量并列的重要内容.常量类似变量,但常量一旦被定义就无法更改或撤销定义.常量最主要的作用是可以避免重复定义,篡改变量值,提高代码可维护性 ...
- fedora/centos7防火墙FirewallD详解
1 使用 FirewallD 构建动态防火墙 1.1 “守护进程” 1.2 静态防火墙(system-config-firewall/lokkit) 1.3 使用 iptables 和 ip6tabl ...
- 在腾讯云服务器上体验Docker
版权声明:本文由姚俊刚原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/85 来源:腾云阁 https://www.qclou ...
- JZOJ.5335【NOIP2017模拟8.24】早苗
Description