接口访问参考:https://blog.csdn.net/hanjun0612/article/details/81625395

PS:调用接口和跳转网页

主要区别是

1 调用接口是 @RestController

跳转网页是:@Controller

2 跳转网页,需要增加

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

一,IDEA创建项目

File-->New-->Project-->Spring Initializr

然后选择 web和web-starter

然后我们看一下搭建好的项目结构:

二,搭建

先添加POM依赖

pom

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
</dependencies>

然后添加配置文件

这里主要添加 application.yml和 application-dev.yml  就可以了

application.yml:(它会通过active:dev去调用application-dev.yml)

spring:
profiles:
active: dev
datasource:
url: jdbc:mysql://ip地址:3306/testdb?serverTimezone=UTC
username: root
password: root
jpa:
generate-ddl: false
hibernate:
ddl-auto: none
show-sql: true
thymeleaf:
prefix: classpath:/templates/
suffix: .html
mode: HTML5
encoding: UTF-8
cache: false
servlet:
content-type: text/html

application-dev.yml

server:
servlet:
context-path:
port: 8081

DemoApplication:

@SpringBootApplication
public class DemoApplication { public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
} }

User

@Entity
@Table(name = "user", catalog = "testdb")
@DynamicUpdate
public class User {
private Integer id;
private String uuid;
private String userName;
private String password;
private Date createTime;
private Integer age; @Id
@GeneratedValue
@Column(name = "id")
public Integer getId() {
return id;
} public void setId(Integer id) {
this.id = id;
} @Column(name = "uuid")
public String getUuid() {
return uuid;
} public void setUuid(String uuid) {
this.uuid = uuid;
} @Column(name = "username")
public String getUserName() {
return userName;
} public void setUserName(String userName) {
this.userName = userName;
} @Column(name = "password")
public String getPassword() {
return password;
} public void setPassword(String password) {
this.password = password;
} @Column(name = "createtime")
public Date getCreateTime() {
return createTime;
} public void setCreateTime(Date createTime) {
this.createTime = createTime;
} @Column(name = "age")
public Integer getAge() {
return age;
} public void setAge(Integer age) {
this.age = age;
}
}

UserRepository

@Repository
public interface UserRepository extends JpaRepository<User,Integer> {
}

HelloController

@Controller
public class HelloController { @Autowired
UserRepository userRepository; @RequestMapping("/index.do")
public String say(ModelMap mode) {
User user=userRepository.findById(3).get();
mode.addAttribute("user", user);
return "say";
}
}

say.html

<span th:text="${user.userName}"></span>
hello
</body>

最后效果:

springboot 简单搭建(thymeleaf 视图显示)的更多相关文章

  1. springboot 简单搭建

    springboot的入门请参考:https://blog.csdn.net/hanjun0612/article/details/81538449 这里就简单看下搭建: 一,看一下项目结构: 创建一 ...

  2. 三、SpringBoot整合Thymeleaf视图

    目录 3.1 Thymeleaf视图介绍 3.2 创建SpringBoot项目 3.2 配置Thymeleaf 3.3 编写Demo 3.4 小结 3.1 Thymeleaf视图介绍 先看下官网的介绍 ...

  3. 7 — 简单了解springboot中的thymeleaf

    1.官网学习地址 https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html 2.什么是thymeleaf? 一张图看明白: 解读: ...

  4. 简单的SpringBoot环境搭建

    开始搭建前请确认您的计算机中的Maven已正确配置 一:使用IDEA创建一个Maven项目,图中第一个指针请选择自己正在使用的JDK版本,指针二请打勾,选中指针三所指向的类型并点击Next 二:填写G ...

  5. 超详细,新手都能看懂 !使用SpringBoot+Dubbo 搭建一个简单的分布式服务

    来自:JavaGuide Github 地址:https://github.com/Snailclimb/springboot-integration-examples 目录: 使用 SpringBo ...

  6. 使用 SpringBoot+Dubbo 搭建一个简单分布式服务

    实战之前,先来看几个重要的概念 开始实战之前,我们先来简单的了解一下这样几个概念:Dubbo.RPC.分布式.由于本文的目的是带大家使用SpringBoot+Dubbo 搭建一个简单的分布式服务,所以 ...

  7. 零配置简单搭建SpringMVC 项目

    SpringMVC是比较常用的JavaWeb框架,非常轻便强悍,能简化Web开发,大大提高开发效率,在各种Web程序中广泛应用.本文采用Java Config的方式搭建SpringMVC项目,并对Sp ...

  8. SpringBoot 同时整合thymeleaf html、vue html和jsp

    问题描述 SpringBoot如何同时访问html和jsp SpringBoot访问html页面可以,访问jsp页面报错 SpringBoot如何同时整合thymeleaf html.vue html ...

  9. springboot简单入门笔记

    一.Spring Boot 入门 1.Spring Boot 简介 简化Spring应用开发的一个框架: 整个Spring技术栈的一个大整合: J2EE开发的一站式解决方案: 2.微服务 2014,m ...

随机推荐

  1. Java文件系统

    Java7 引入了新的输入/输出2(NIO.2)API并提供了一个新的I/O API. 它向Java类库添加了三个包:java.nio.file,java.nio.file.attribute和jav ...

  2. 2019-9-25-如何让-USB-设备不显示安全删除硬件弹出选项

    title author date CreateTime categories 如何让 USB 设备不显示安全删除硬件弹出选项 lindexi 2019-09-25 11:58:19 +0800 20 ...

  3. Linux 进程间通信 共享内存

    1.特点: 1)共享内存是一种最为高效的进程间通信方式,进程可以直接读写内存,而不需要任何数据的拷贝.如管道当在内核空间创建以后,用户空间需要内存  拷贝,需要拷贝数据,所以效率低. 2)为了在多个进 ...

  4. PHP72w安装

    PHP72w #  rpm  -Uvh   https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm #  rpm ...

  5. final和abstract关键字的作用

    final和abstract关键字的作用 final和abstract是功能相反的两个关键字,可以对比记忆 abstract可以用来修饰类和方法,不能用来修饰属性和构造方法:使用abstract修饰的 ...

  6. GC线程是否为守护线程?

    GC是垃圾收集的意思,Java提供的GC功能可以自动监测对象是否超过作用域从而达到自动回收内存的目的,从而有效的防止内存泄露.要请求垃圾收集,可以调用下面的方法之一:System.gc()或Runti ...

  7. 网址URL知识

    URL由三部分组成:资源类型.存放资源的主机域名.资源文件名. URL的一般语法格式为: (带方括号[]的为可选项): protocol :// hostname[:port] / path / [; ...

  8. CentOS7-安装最新版本GIT(git version 2.18.0)

    Git安装方式有两种一种是yum安装一种是编译安装: 一.yum命令安装,此方法简单,会自动安装依赖的包,而且会从源里安装最新的版本,如果仓库不是最新的话安装的也不是最新Git. sudo yum i ...

  9. mysql开启慢查询报错:

    1.进入mysql命令行:#mysql -uroot -p123456,执行下面的命令开启慢查询报错: set global slow_query_log=on; set global long_qu ...

  10. kafka?kafaka! kafka...

    kafka?kafaka! Kafka... kafka是什么? 答:Kafka是由Apache软件基金会开发的一个开源流处理平台,由Scala和Java编写.Kafka是一种高吞吐量的分布式发布订阅 ...