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);
	}

}

 

你可能感兴趣的:(springboot)