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模板,对数据进行展示的更多相关文章

  1. SpringBoot常用Starter介绍和整合模板引擎Freemaker、thymeleaf 4节课

    1.SpringBoot Starter讲解 简介:介绍什么是SpringBoot Starter和主要作用 1.官网地址:https://docs.spring.io/spring-boot/doc ...

  2. SpringBoot thymeleaf使用方法,thymeleaf模板迭代

    SpringBoot thymeleaf使用方法,thymeleaf模板迭代 SpringBoot thymeleaf 循环List.Map ============================= ...

  3. springboot中model,modelandview,modelmap的区别与联系

    springboot 中Model,ModelAndView,ModelMap的区别与联系 Model是一个接口,它的实现类为ExtendedModelMap,继承ModelMap类 public c ...

  4. SpringBoot + Vue + ElementUI 实现后台管理系统模板 -- 后端篇(五): 数据表设计、使用 jwt、redis、sms 工具类完善注册登录逻辑

    (1) 相关博文地址: SpringBoot + Vue + ElementUI 实现后台管理系统模板 -- 前端篇(一):搭建基本环境:https://www.cnblogs.com/l-y-h/p ...

  5. SpringBoot + Vue + ElementUI 实现后台管理系统模板 -- 后端篇(一): 搭建基本环境、整合 Swagger、MyBatisPlus、JSR303 以及国际化操作

    相关 (1) 相关博文地址: SpringBoot + Vue + ElementUI 实现后台管理系统模板 -- 前端篇(一):搭建基本环境:https://www.cnblogs.com/l-y- ...

  6. django 简易博客开发 2 模板和数据查询

    首先还是贴一下项目地址  https://github.com/goodspeedcheng/sblog   因为代码全在上面 上一篇博客我们介绍了 django的安装配置,新建project,新建a ...

  7. java poi 从服务器下载模板写入数据再导出

    最近写了一个,Excel 的 写入和导出.   需求是这样的.   在新建合同的时候,会有导出合同的数据,    导出的模板是固定的,,需要在模板里面写入合同的信息. first   :  下载模板 ...

  8. python操作三大主流数据库(5)python操作mysql⑤使用Jinja2模板提取优化页面展示

    python操作mysql⑤使用Jinja2模板提取优化页面展示 在templates目录下的index.html.cat.html等页面有一些共同的元素,代码比较冗余可以使用模板提取公共代码,在各网 ...

  9. 背水一战 Windows 10 (51) - 控件(集合类): ItemsControl - 项模板选择器, 数据分组

    [源码下载] 背水一战 Windows 10 (51) - 控件(集合类): ItemsControl - 项模板选择器, 数据分组 作者:webabcd 介绍背水一战 Windows 10 之 控件 ...

随机推荐

  1. Sqlserver2005:深入了解php执行sqlserver存储过程procedure:odbc_exe、odbc_execute

    以下存储过程(伪代码): -- 伪代码,假设相关操作是成功的 alter procedure pr_test as begin set nocount on update tab set col='n ...

  2. HDU2717BFS

    /* WA了12发简直不能忍! . 题意非常简单.从正整数a变为b有三种方法: +1,-1.*2 特殊情况一:a与b相等不须要搜索 特殊情况二:a>b时.结果必定是a-b不需搜 特殊情况三:比較 ...

  3. iOS调用系统相册、相机 显示中文标题

    解决手机语言已经设置显示中文 在调用系统相册.相机界面 时显示英文问题, 在 info.plist里面添加Localized resources can be mixed          YES 表 ...

  4. ELK5.X使用X-Pack配置密码

    一.前言 前面使用ELK5.X+logback搭建日志平台,但是,当访问kibana 时,直接就可以访问了,如果设置登录名和密码,是不是更好呢?答案是肯定的,这里使用X-Pack来配置登录名和密码. ...

  5. Python 练习题:统计系统剩余内存

    #!/usr/bin/env python #-*- coding:utf-8 -*- ''' 统计系统内存信息 ''' with open('/proc/meminfo') as fd: for l ...

  6. RecyclerView的通用适配器,和滚动时不加载图片的封装

    对于RecyclerView我们需要使用RecyclerAdapter,使用方式与ListViewAdapter类似,具体代码大家可以在网上搜索,这里就只教大家使用封装后的简洁RecyclerAdap ...

  7. 第四篇:GPU 并行编程的存储系统架构

    前言 在用 CUDA 对 GPU 进行并行编程的过程中,除了需要对线程架构要有深刻的认识外,也需要对存储系统架构有深入的了解. 这两个部分是 GPU 编程中最为基础,也是最为重要的部分,需要花时间去理 ...

  8. 好用的在线Markdown编辑器

    dillinger.io 支持在线编辑,导出为html格式等.

  9. Oracle 12C卸载图文教程

    第一步:找到自己的Oracle安装目录.我的目录是:D:\app\u01\product\12.1.0\dbhome_1\deinstall ,然后点击bat文件.出现如下等待画面.   第二步:耐心 ...

  10. MQTT的学习研究(十五) MQTT 和android整合文章

    详细参考:  How to Implement Push Notifications for Android http://tokudu.com/2010/how-to-implement-push- ...