【Springboot学习】从零开始学习Springboot(二)

  个人学习Springboot的记录,一些坑问题我会整合起来并给出解决方法,遇到问题的地方将使用Q1:<问题描述> Q2:<问题描述>这样的序号来表示,根据序号去文章下面找解决方法即可。

JavaBean

JavaBean是为了保证Java应用的向后兼容性而提出的,只要类的属性是由get和set方法来获取和赋值的都是JavaBean。

Java bean 是个什么概念?

注解

java注解

引导类

REST风格

相同的路径可以根据不同的访问方法来区分对资源进行何种操作。

描述模块的名称通常使用复数,也就是加s的格式描述,如http://localhost/users

 

//普通写法
@RequestMapping(value="/books")
@ResponseBody
public String getByDelete(Integer id){
    System.out.println("springboot is not running" + id);
    return "springboot is not running";
}
//普通访问
//http://localhost/books?id=1
//RESTful写法
@RequestMapping(value="/books/{id}",method = RequestMethod.DELETE)
@ResponseBody
public String getByDelete(@PathVariable Integer id){
    System.out.println("springboot is not running" + id);
    return "springboot is not running";
}
//RESTfulf访问
//http://localhost/books/1

简化:

    • @Controller@ResponseBody可以简化写为@RestCtroller
    • @RequestMapping(method = RequestMethod.POST)可以简化为@PostMapping,其他同理。
    • @RequestMapping(value="/id",method = RequestMethod.POST)简化为@PostMapping("/{id}"),其他同理
    • @RequestMapping(value="/books")可以拿到类定义的前面来,这样类内的所有方法就不用写了

常用注解:

参考链接:

 

posted @ 2022-06-23 20:07  Texley  阅读(51)  评论(0)    收藏  举报