restFul风格两种实现方式

restFul风格实现1

作用:可以动态的接收url中的地址。
语法:

1.url中的地址如果是参数,则需要使用/分割
2.controller方法接收参数时,需要使{}号来获取
3.如果需要获取参数信息,则使用特定的注解标识
@RequestMapping("/page/{moduleName}")
public String module(@PathVariable String moduleName){
     return moduleName;
 }

restFul风格实现2

需要指定访问请求类型,并且根据特定的类型执行业务。
那么,什么叫指定访问请求类型?

请求类型常见的有多少种?

1.post  执行入库操作
2.get  执行查询的操作
3.put  执行更新操作
4.delete 执行删除操作
@RequestMapping(value = "/page/{moduleName}",method = RequestMethod.GET)
 public String module(@PathVariable String moduleName){
     return moduleName;
 }

简化restFul风格实现2的代码

@GetMapping("/page/{moduleName}")
public String module(@PathVariable String moduleName){
    return moduleName;
}

你可能感兴趣的:(restful,java,后端)