背景
最近头发掉的厉害了,整理下SpringBoot系列及周边的技术,总的来看分为配置、日志、web、docker、数据访问、缓存、消息、检索、任务、安全、分布式、开发习惯、监控等,慢慢更新
简介
为了简化开发,尊崇约定大于配置的思想,干掉复杂的配置,让咱码农能把精力都用在开发上。
上手
- IDEA-创建项目-引入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
- IDEA生成了启动类
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
- 编写controller
@RestController
public class HelloController {
@RequestMapping("/hello")
public String getHello(){
return "Hello! SpringBoot";
}
}
这里的 @RestController 来看一下
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Controller
@ResponseBody
public @interface RestController {
/**
* The value may indicate a suggestion for a logical component name,
* to be turned into a Spring bean in case of an autodetected component.
* @return the suggested component name, if any (or empty String otherwise)
* @since 4.0.1
*/
@AliasFor(annotation = Controller.class)
String value() default "";
}
这里边放了@ResponseBody注解,所以HelloController 里边所有的方法都不用再写@ResponseBody注解了
- 启动项目并访问
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)