springboot建父工程,整合Thymeleaf模板引擎
2023-06-13 09:13:24 时间
springboot整合Thymeleaf模板引擎
开发环境
- jdk:jdk1.8.0_212
- maven:apache-maven-3.6.2
- springboot版本:2.2.0 之前配置了一个快速入门课程,后面准备用springboot集成其他demo,为了后面方便集成,所以使用一个父工程来配置统一的依赖环境。
父工程构建
在快速入门课程的基础上做了一些修改,作为父工程
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<!--核心模块,包括自动配置支持、日志和YAML-->
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<!--测试模块,包括JUnit、Hamcrest、Mockito-->
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
引入Web模块,方便后面测试
<dependency>
<groupId>org.springframework.boot</groupId>
<!--web模块-->
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
创建controller类com.zjq.demo.controller.TestController,内容如下
@RestController
public class TestController {
@RequestMapping(value = "/hello")
public String hello(){
return "HelloWorld";
}
}
启动主程序,访问 http://localhost:8080/hello ,可以看到页面输出 HelloWorld
使用maven构建
1.使用idea,点击File,new >>project,老版idea可以直接用 SPRING INITIALIZR 新建项目,新版的idea需要添加
Spring Assistant插件,添加好后重启idea,点击File,new >>project,选择Spring Assistant,选择SDK版本,使用default https://start.spring.io/ 构建项目
4.可以看到pom.xml文件中自动引入了这些依赖
<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>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
引入Web模块,方便后面测
创建controller类com.zjq.demo.controller.TestController,内容如下
@RestController
public class TestController {
@RequestMapping(value = "/hello")
public String hello(){
return "HelloWorldByIdea";
}
}
启动主程序,访问 http://localhost:8080/hello ,可以看到页面输出 HelloWorldByIdea
相关文章
- Java项目毕业设计:基于springboot+vue的电影视频网站系统「建议收藏」
- springboot启动原理总结_Springboot启动流程
- springboot框架流程图_java流程框架
- 面试之springboot自动配置原理「建议收藏」
- SpringBoot 之 Web 使用 Thymeleaf 模板
- 基于SpringBoot+JWT+Redis跨域单点登录的实现
- SpringBoot 整合MybatisPlus 实现字段自动注入
- SpringBoot整合Redis[哨兵版]
- springboot启动监听线程_Springboot启动流程
- SpringBoot核心注解原理
- 1-SpringBoot基础
- SpringBoot+Mybatis以及jsp使用问题
- SpringBoot下ElasticSearch的使用
- 使用Postman 传递arraylist数据给springboot
- idea创建springboot父子工程_Springboot框架
- springboot多环境配置文件_Springboot教程
- springBoot整合Mybatis-Plus需要的依赖_springboot中文手册
- SpringBoot项目启动后再请求远程接口的实现方式
- Java面试集锦(一)之SpringBoot
- MyBatis-Plus代码生成器模板(SpringBoot版本)
- SpringBoot+SpringDataJpa @Query之 JPQL使用书写模板(模糊查询and条件查询)
- SpringBoot:模块探究之spring-boot-devtools
- SpringCloud 和 SpringBoot 版本选型
- SpringBoot之(二):基础篇—SpringBoot+Mybatis+MySql增删改查详解程序员
- 详解js插件ajaxupload实现图片上传(适用springboot)编程语言