SpringBoot使用筆記

<!--導入配置文件處理器,配置文件進行綁定就會有提示-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>

@RequestParam

 @GetMapping("/hello")
    public String hello(@RequestParam(value = "name", defaultValue = "World") String name) {
        return String.format("Hello %s!", name);
    }

http://localhost:8080/hello 返回Hello World!
http://localhost:8080/hello?name=Amy 返回Hello Amy!

@EnableAutoConfiguration 開啓自動化配置
@SpringBootApplication 來標註一個主程序類,說明這是一個Spring Boot應用
@ConfigurationProperties(prefix = “person”) 配置文件值注入
在這裏插入圖片描述
在這裏插入圖片描述
配置類@Configuration------>Spring配置文件 、使用@Bean給容器中添加組件

@Configuration
public class AllConfiguration extends WebMvcConfigurerAdapter{
	//準備框架中需要維護的攔截器對象<bean>
	@Bean
	public CartInterceptor cartIntInit(){
		return new CartInterceptor();
	}
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章