一、SpringBoot环境搭建

本系列博客都是基于maven项目的
环境约束
–jdk1.8:Spring Boot 推荐jdk1.7及以上;java version "1.8.0_112"
–maven3.x:maven 3.3以上版本;Apache Maven 3.3.9
–IntelliJIDEA2017:IntelliJ IDEA 2017.2.2 x64、STS
–SpringBoot 1.5.9.RELEASE:1.5.9;

1.首先要去网上现在maven,具体可以百度。然后打开给给maven 的settings.xml配置文件的profiles标签添加如下配置


  jdk-1.8
  
    true
    1.8
  
  
    1.8
    1.8
    1.8
  

  1. 给自己的idea配置maven (File->Setting-> Build, Execution, Deployment->BulidTools ->maven)


    dd.png
  2. 在pom.xml中导入spring boot相关的依赖

  
        org.springframework.boot
        spring-boot-starter-parent
        1.5.9.RELEASE
    
    
        
            org.springframework.boot
            spring-boot-starter-web
        
    
  1. 编写一个主程序;启动Spring Boot应用
package com.flyz;

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

@SpringBootApplication
public class App {

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

  1. 编写相关的Controller、Service
package com.flyz.controller;

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

//@ResponseBody// 该注解标识这个类的所有方法返回的数据直接写给浏览器,(如果是对象,则会转成json数据)
//@Controller  //  RestController 等价于  @ResponseBody @Controller 同时写上


@RestController
public class HelloController {

    @RequestMapping("/index")
    public String hello(){

        return "welcome to SpringBoot";
    }
}

运行项目(App类)

JDFAN7_Z~U}8J}SE~~K9LIK.png

值得注意的是:
RestController:代表是返回JSON字符串给前台
Controller:注解是返回页面(比如结合thymeleaf)

你可能感兴趣的:(一、SpringBoot环境搭建)