SpringBoot入门学习

SpringBoot入门学习(一) 创建HelloWorld示例

SpringBoot:J2EE一站式解决方案
SpringCloud:分布式整体解决方案
首先是环境变量及软件版本:

JDK 1.8版本
Maven 3.3.5版本
IntelliJ IDEA 2018.2

修改maven配置文件:

以下代码是标识告知maven使用jdk1.8进行编译

<profile>
  <id>jdk-1.8</id>
  <activation>
  	   <activeByDefault>true</activeByDefault>
       <jdk>1.8</jdk>
  </activation>
  <properties>
	<maven.compiler.source>1.8</maven.compiler.source>
	<maven.compiler.target>1.8</maven.compiler.target>
	<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
  </properties>
</profile>
创建项目

此处需要注意的是,在创建项目是需要联网进行,否则会创建失败。你也可以去spring官网进行项目的创建,创建完成后会自动打包,你直接在IDEA中导入创建的项目包就可以了
在这里插入图片描述
1:项目名称
2:项目包名
3:选择变成语言
4:jar包还是war包,此处就选择jar包就行
5:jdk版本
在这里插入图片描述
项目创建成功后的目录
在这里插入图片描述
我们在自动生成的springboot_helloworld包中一个包并创建一个控制器类
在这里插入图片描述
控制器类代码如下:

package com.kangtutu.springboot_helloworld.ucontroller;

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

@RequestMapping("/hello")
@Controller
public class HelloWorldController {

    @RequestMapping("/demo")
    @ResponseBody
    public String demo(){
        return "HelloWorld";
    }
}

我们直接像页面输出"HelloWorld"

系统生成的SpringbootHelloworldApplication类中的代码如下:

@SpringBootApplication用来标明一个主程序类,说明这个一个SpringBoot应用

package com.kangtutu.springboot_helloworld;

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

@SpringBootApplication
public class SpringbootHelloworldApplication {

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

下面开始点击运行启动项目,项目启动成功后就会在控制台显示如下代码:
在这里插入图片描述

打开浏览器,输入localhost:8080/hello/demo,回车后我们就能看到页面上显示的"HelloWorld"
在这里插入图片描述

至此,一个使用SpringBoot创建的HelloWorld就完成了。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值