spring boot 笔记(一):pom,注解

来源:互联网 发布:手机网络不卡玩游戏卡 编辑:程序博客网 时间:2024/05/20 09:06

使用spring boot也有一段时间了,但许多用法包括原理都还没搞懂,遇到错误就去网上查,实在不能说理解了该框架。于是新开一个系列博客,来记录spring boot的知识点。

pom

使用intellij idea新建的spring boot web项目,pom只有两个依赖:
spring-boot-starter-web:包括包括自动配置支持、日志和YAML等核心模块
spring-boot-starter-test:包括JUnit、Hamcrest、Mockito等测试模块

额外添加如下配置:

<dependency>    <groupId>org.springframework.boot</groupId>    <artifactId>spring-boot-devtools</artifactId>    <optional>true</optional></dependency><plugin>    <groupId>org.springframework.boot</groupId>    <artifactId>spring-boot-maven-plugin</artifactId>    <configuration>        <fork>true</fork>    </configuration></plugin>

方便热部署调试

注解

@Controller
配合InternalResourceViewResolver可以返回指定页面
@ResponseBody
返回某种形式的数据(json或者xml)
@RestController
@Controller和@ResponseBody的组合

到这里,建议返回页面的controller和返回数据(json)的controller分开写,因为这样的话,在返回数据的类上就可以直接使用@RestController而不用在方法上使用@ResponseBody了。

原创粉丝点击