Spring Boot框架学习

一、什么是Spring Boot?

spring boot 来简化Sprin应用开发。

二、构建spring boot项目

1、使用Maven构建spring boot项目
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述2、在pom.xml中修改jdk版本

 <properties>
  	<java.version>1.8</java.version>
  </properties>

3、注入spring boot启动器坐标

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

4、编写一个主程序

package com.hgu.action;

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


@SpringBootApplication  //来标注一个主程序类,说明是一个Spring boot应用
public class helloworld {

	public static void main(String[] args){
		
		//spring启动起来
		SpringApplication.run(helloworld.class,args);
	}
}

5、编写业务逻辑

package com.hgu.action;

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

@Controller  //处理请求
public class controller {
	
	@ResponseBody//把返回值写给浏览器
	@RequestMapping("/hello")//接收浏览器发来的hello
	public String hello(){
		return "hello world";
	}
}

猜你喜欢

转载自blog.csdn.net/cqn9012/article/details/87857013