新手快速搭建springboot项目

这篇具有很好参考价值的文章主要介绍了新手快速搭建springboot项目。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

一、创建项目

1.1、创建项目

新手快速搭建springboot项目

1.2、配置编码

新手快速搭建springboot项目

1.3、取消无用提示

新手快速搭建springboot项目

1.4、取消无用参数提示

新手快速搭建springboot项目

二、添加POM父依赖

<!-- 两种方式添加父依赖或者import方式 -->
<parent>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-parent</artifactId>
  <version>2.5.7</version>
</parent>

maven的pom文件手动更新

添加完成maven的pom文件之后,会自动更新,也可能不会自动更新,那么我们需要手动更新它。

新手快速搭建springboot项目

三、支持SpringMVC

<dependencies>
    <!-- 支持SpringMVC -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>

四、创建启动类、rest接口

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class StartApplication {

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

}

五、配置插件

配置完成后,maven打包可以生成可执行jar文件

<build>
  <plugins>
      <!-- 打包成可执行jar -->
      <plugin>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>
      <!-- 配置跳过测试 -->
      <plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <configuration>
              <skip>true</skip>
          </configuration>
      </plugin>
      <!-- 配置jdk版本11 -->
      <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <configuration>
              <source>11</source>
              <target>11</target>
              <encoding>utf-8</encoding>
          </configuration>
      </plugin>
  </plugins>

</build>

六、添加thymeleaf模板

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

七、添加配置

在resources文件夹下,创建application.properties

在resources文件夹下,创建templates文件夹

# 应用名称
spring.application.name=thymeleaf
# 应用服务 WEB 访问端口
server.port=8080
# THYMELEAF (ThymeleafAutoConfiguration)
# 开启模板缓存(默认值: true )
spring.thymeleaf.cache=false
# 检查模板是否存在,然后再呈现
spring.thymeleaf.check-template=true
# 检查模板位置是否正确(默认值 :true )
spring.thymeleaf.check-template-location=true
#Content-Type 的值(默认值: text/html )
spring.thymeleaf.content-type=text/html
# 开启 MVC Thymeleaf 视图解析(默认值: true )
spring.thymeleaf.enabled=true
# 模板编码
spring.thymeleaf.encoding=UTF-8
# 要被排除在解析之外的视图名称列表,⽤逗号分隔
spring.thymeleaf.excluded-view-names=
# 要运⽤于模板之上的模板模式。另⻅ StandardTemplate-ModeHandlers( 默认值: HTML5)
spring.thymeleaf.mode=HTML5
# 在构建 URL 时添加到视图名称前的前缀(默认值: classpath:/templates/ )
spring.thymeleaf.prefix=classpath:/templates/
# 在构建 URL 时添加到视图名称后的后缀(默认值: .html )
spring.thymeleaf.suffix=.html

八、添加controller

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class IndexController {

    @RequestMapping("/index")
    public ModelAndView index(){
        ModelAndView mv = new ModelAndView();

        mv.setViewName("index");

        return mv;
    }

}
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

@RestController
public class HelloController {

    @GetMapping("/Hello")
    public String Hello(){
        return "haha";
    }
}
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * rest测试controller
 */
@RestController
public class RestIndexController {
    
    @GetMapping("/restIndex")
    public String index(){
        return "rest";
    }
    
}

九、添加html

在templates下创建index.html

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" >
<head>
    <meta charset="UTF-8">
    <title>index</title>
</head>
<body>
index
</body>
</html>

十、访问

需要maven执行编译,否则容易404

http://localhost:8080/index文章来源地址https://www.toymoban.com/news/detail-489890.html

到了这里,关于新手快速搭建springboot项目的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 快速搭建SpringBoot3.x项目

    上一小节中我们从0到1 使用Vite搭建了一个Vue3项目,并集成了Element Plus 实现了一个简单的增删改查页面。 这一篇中我们将使用IDEA快速搭建一个SpringBoot3.x的项目。 1、File-new-project 2、选择“Spring Initializr”,点击next; 3、选择spring boot版本及添加相关依赖 这一步我们需要选择

    2024年02月08日
    浏览(25)
  • 快速搭建一个简单的SpringBoot项目-详细步骤

    前言 本文章仅供大家参考,如果对大家有起到帮助的话可以点赞支持一下~ 主要发布是为了本人以后能方便的搭建一个SpringBoot项目的框架!!! 源码路径在文章最下方! 1.选择Spring Initializr 2.点击下一步 3.修改jdk的版本,再点击下一步 注意! 4.选中Spring Web,再下一步 5.给项目

    2024年02月10日
    浏览(27)
  • 芋道SpringBoot配置Maven、创建SpringBoot项目、创建Web接口、读取配置信息

    🌹作者主页:青花锁 🌹简介:Java领域优质创作者🏆、Java微服务架构公号作者😄 🌹简历模板、学习资料、面试题库、技术互助 🌹文末获取联系方式 📝 第一章 芋道 Spring Boot 快速入门 芋道 SpringBoot是一款国产的SpringCloud微服务框架,包括Outh2.0、微服务网关、微服务注册中

    2024年04月23日
    浏览(26)
  • SpringBoot(项目创建使用+配置文件+日志文件)

    目录 1. Spring Boot 项目创建 2. 写一个 Hello World 并运行 3. 配置文件的作用及格式 4. properties 配置文件的基本语法  5. 读取配置文件 6. yml 配置文件说明 7. properties 和 yml 的区别 8. SpringBoot 日志文件 8.1 日志的作用 8.2 自定义日志打印 8.3 日志的级别 8.4 日志持久化 8.5 更简单的实现

    2024年01月22日
    浏览(40)
  • 若依框架(一)使用若依框架从0到1快速搭建springboot + vue 项目

    1、下载若依框架代码 进入若依官网,选择源码地址,软后选择RuoYi-Vue前端分离版本,这个版本是由SpringBoot + Vue进行前后端分离开发的。 点击之后进入到gitee,点击 “克隆/下载”,选择下载方式,可以实用git命令进行git克隆,也可以直接选择下载zip,这里推荐新手就下载z

    2024年02月16日
    浏览(25)
  • 如何快速搭建自己的阿里云服务器(宝塔)并且部署springboot+vue项目(全网最全)

    对于新手或者学生党来说,有时候就想租一个云服务器来玩玩或者练练手,duck不必花那么多钱去租个服务器。这些云服务厂商对学生和新手还是相当友好的。下面将教你如何快速搭建自己的阿里云服务器,完成云服务器的部署。 现在阿里云对于新用户来说,还是挺仗义的,

    2024年02月04日
    浏览(66)
  • 22、springboot的Profile(通过yml配置文件配置 profile,快速切换项目的开发环境)

    就是通过 配置的 profile 快速切换开发环境。 ▲ 1. 声明Profile ▲ 2. 设置活动Profile 演示如何通过profile配置文件,来快速切换开发环境。 步骤: 1、 添加一个正式环境用的yml----application-dev.yml,写对应的正式环境配置 添加一个测试环境用的yml----application-test.yml,写对应的测试环

    2024年02月02日
    浏览(33)
  • Vue cli创建项目时键盘操作无效;vue3.0项目搭建自定义配置

    在创建vue3.0项目时,在建好的文件夹,鼠标右键 git bash 使用 vue create my-vue3.0创建新项目时,键盘方向键失效,无法选中对应的选项(交互提示符不工作) 方案一 使用电脑自带的 cmd 运行 vue create my-vue3.0。 方案一 在 git bash 窗口中用 winpty vue.cmd create demo 命令创建项目。只是换

    2024年04月09日
    浏览(30)
  • uniapp和springboot微信小程序开发实战:前端架构搭建之HBuilder X创建项目以及目录介绍

    HBuilder是DCloud(数字天堂)推出的一款支持HTML5的Web开

    2024年02月09日
    浏览(35)
  • 使用SpringBoot一小时快速搭建一个简单后台管理(增删改查)(超详细教程) 各大技术基础教学、实战项目开发教学

     最近也是临近期末了,各种的期末大作业,后台管理也是很多地方需要用到的,为了方便大家能快速上手,快速搭建一个简单的后台管理,我花了两天时间整理了一下 我会从0开始介绍,从数据库的设计到前端页面的引入最后到后端代码的编写,你只需要会一点前端的基础和

    2023年04月13日
    浏览(76)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包