SpringBoot:二、两种启动方式

SpringBoot的两种启动方式:

1. 第一种启动方式,如下面代码所示:

package com.tydic.controller.demo1;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

//标识该接口全部返回json格式,@RestController=@Controller+@ResponseBody
//@EnableAutoConfiguration 注入spring的容器
@EnableAutoConfiguration
@RestController
public class HelloWord{

    @RequestMapping("/index")
    public String index(){
        return "success";
    }

    @RequestMapping("/getMap")
    public Map getMap(){
        HashMap result = new HashMap<>();
        result.put("errorCode","200");
        result.put("errorMsg","成功..");
        return result;
    }
    public static void main(String[] args) {
        SpringApplication.run(HelloWord.class, args);
    }
}

2.第二种启动方式:

package com.tydic.controller.demo1;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

//标识该接口全部返回json格式,@RestController=@Controller+@ResponseBody
//@EnableAutoConfiguration 注入spring的容器
@EnableAutoConfiguration
@RestController
public class HelloWord{

    @RequestMapping("/index")
    public String index(){
        return "success";
    }

    @RequestMapping("/getMap")
    public Map getMap(){
        HashMap result = new HashMap<>();
        result.put("errorCode","200");
        result.put("errorMsg","成功..");
        return result;
    }
    public static void main(String[] args) {
        SpringApplication.run(HelloWord.class, args);
    }
}



package com.tydic.controller;

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

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

}

 

你可能感兴趣的:(springboot)