SpringBoot【新手学习记录篇】

1. 启动方式:

  1. 在idea中的application.java右键run as
  2. 命令行进入项目目录,使用命令 mvn spring-boot:run
  3. 使用mvn install进行打包,然后进入target目录,会出现一个jar包,例如名字叫做a.jar;使用 java -jar a.jar。后面可以加上参数,作为配置

2. 配置文件

  可以使用properties文件,也可以使用yml文件【推荐.】

3. Controller的使用

@Controller 处理HTTP请求
@RestController

Spring4之后加上的注解,原来返回JSON需要

@ResponseBody配合@Controller使用

@RequestMapping 配置URL映射
@PathVariable 获取URL中的数据【获取url的形式如http://xxxx.com/hello/100;注解的mapping是/hello/{id}】
@RequestParam 获取请求参数的值【获取url的形式如http://xxxx.com/hello?id=100】
@GetMapping 组合注解【类似的还有@PostMapping等,等同于对方方式的RequestMapping】
posted @ 2018-06-29 15:49  是小毛吖  阅读(122)  评论(0编辑  收藏  举报
转载请注明出处