SpringBoot入门项目-helloWorld

SpringBoot入门web项目-helloWorld


项目构建

1. 用idea构建Maven项目

file -> new -> maven -> next -> 输入groupId与ArtifactId(可输入springboot) -> next -> finish。

2. 添加maven依赖

pom.xml中添加如下:

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.1.RELEASE</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>
3. 构建SpringBoot启动程序

src/main/java新建包com.au,然后构建MySpringBootApplication类作为启动类。

package com.au;

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

/**
 * @ClassName MySpringBootApplication
 * @Author Au
 * @Date 2019/11/5 14:41
 * @Description
 **/

 // @SpringBootApplication标注该类为启动类
@SpringBootApplication
public class MySpringBootApplication {
    public static void main(String[] args) {
        SpringApplication.run(MySpringBootApplication.class);
    }
}

此时一个SpringBoot项目已经构建好了。

4. 创建一个Controller类用于测试

com.au下创建controller包,再创建Controller_test1类。

package com.au.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @ClassName Controller_test1
 * @Author Au
 * @Date 2019/11/5 14:52
 * @Description
 **/
@Controller
public class Controller_test1 {
    @RequestMapping("/quick")
    @ResponseBody
    public String quick(){
        return "hello springboot";
    }
}

5. 浏览器测试

因为SpringBoot已经内嵌了tomcat,所以可以从浏览器访问,运行MySpringBootApplication中的main方法,然后浏览器输入localhost:8080/quick即可看到hello springboot字样。

idea快速构建SpringBoot项目

1. file -> new project -> Spring Initializr -> next -> 输入group等信息 -> next -> Web -> 勾选Spring Web -> 输入项目名 -> finish。

idea设置项目热部署

共三步:
1. 添加pom依赖。

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
    <optional>true</optional>
</dependency>

2. file -> settings -> Build,Execution,Deployment -> Compiler -> 勾选Build project automatically。
3. ctrl+shift+alt+/ -> Registry -> 勾选compiler.automake.allow.wher.app.running。
然后重启项目即可达到热部署的效果。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值