SpringBoot学习--环境搭建

本文介绍如何使用SpringBoot快速搭建项目,包括环境配置、项目构建及简单应用实例。通过本教程,读者可以学会基本的SpringBoot应用程序搭建过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

SpringBoot学习–环境搭建

SpringBoot的优点:

  • 快速构建项目
  • 对主流开发框架无配置集成
  • 项目可独立运行,无须外部以来Servlet容器
  • 提供运行时的应用监控
  • 极大地提高了开发和部署的效率
  • 与云计算天然集成

SpringBoot的缺点:

  • 对JSP的支持不友好,SpringBoot官方推荐使用thymeleaf

环境要求

项目构建

1.在eclipse中,通过file->new->other->spring stater project

这里写图片描述

2.点击next

这里写图片描述

3.勾选web模块支持

这里写图片描述

4.项目构建完成,其中DemoApplication.java是自动生成的SpringBoot启动类

这里写图片描述

5.打开DemoApplication.java文件,添加hello方法。这里采用SpringBoot推荐的@RestController注解,其实就是@Cotroller和@ResponseBody的集合。注意:如果想要另建一个Controller文件,请将该Controller所在的包放于DemoApplication.java同包之下,否则该Controller中的方法无法被访问。

package com.gss.springboot;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/*@SpringBootApplication注解是Spring Boot的核心注解,它其实是一个组合注解,具体的可以参考SpringBoot的源码*/
@SpringBootApplication
@RestController
public class DemoApplication {

    @RequestMapping("/hello")
    public String hello() {
        return "Hello SpringBoot";
    }

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

6.直接run Java Application启动SpringBoot应用

7.浏览器上访问地址,这里的8099端口号可以在application.properties文件中进行配置

这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值