• 使用intellij创建空mvn项目
  • 在mvn中增加parent:spring-boot-starter-parent,dep:spring-boot-starter-web
  • 新增HelloController
package hello;

import org.springframework.boot.*;
import org.springframework.boot.autoconfigure.*;
import org.springframework.stereotype.*;
import org.springframework.web.bind.annotation.*;

@Controller
@EnableAutoConfiguration
public class SampleController {

    @RequestMapping("/")
    @ResponseBody
    String home() {
        return "Hello World!";
    }

    public static void main(String[] args) throws Exception {
        SpringApplication.run(SampleController.class, args);
    }
}
  • run SampleController.main 启动服务
  • http://localhost:8080/访问服务
  • 修改上面的文件为application文件

@SpringBootApplication
public class MainClass {
    public static void main(String[] args) throws Exception {
        SpringApplication.run(MainClass.class, args);
    }
}
  • 新建一个RestController ```java

@RestController public class GreetingCont{ @RequestMapping(“/greeting”) public Greet greeting(@RequestParam(value=”name”, defaultValue=”World”) String name) { return new Greet(counter.incrementAndGet(), String.format(template, name)); } }

* Spring doc

http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle
=======
1)Spring在项目中的作用
2)Spring的使用难点
3)Spring的原理

* Spring中使用Json
只需要返回带有get和set的bean就行,下面的设置在Spring中有默认值
 ```text
  produces= MediaType.APPLICATION_JSON_UTF8_VALUE
  public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
  Controller / RestController
  		<dependency>
  			<groupId>com.alibaba</groupId>
  			<artifactId>fastjson</artifactId>
  			<version>1.2.20</version>
  		</dependency>
   


  • Spring的启动流程 1)启动Spring 核心 IOC等 2)根据注解进行Spring组件初始化 3)根据配置信息对特定的bean进行初始化和修改变量操作 4)启动第三方jar包 5)运行客户代码,正式启动