springboot_@RestController,@SpringBootApplication註解

app + controller分離:

<1>controller使用:

@RestController:

整合了@Controller和@ResponseBody,加入了restful特性。

package org.jin.springboot3.controller;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

//@Controller
@RestController
public class BookController {
	@RequestMapping("/{path}")
    //@ResponseBody
	public String show(@PathVariable String path) {
		return "show : " + path;
	}
}

<2>app使用:

@SpringBootApplication:

整合了@EnableAutoConfigure和@ComponentScan,可以同時包含多個controller。

package org.jin.springboot3.app;

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

//@EnableAutoConfiguration
//@ComponentScan("org.jin.springboot3.controller")
@SpringBootApplication(scanBasePackages={"org.jin.springboot3.controller"})
public class Application {

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

}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章