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();
	}
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章