Spring boot中 RestFull风格
Posted NewWorldForU
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Spring boot中 RestFull风格相关的知识,希望对你有一定的参考价值。
第一种:
package com.rabbitmqdemo.demo;
import lombok.Data;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @auther
* @date 2020/1/9 17:13
* @description
*/
@Data
class User
String name;
int age;
String address;
public User(String name, int age, String address)
this.name = name;
this.age = age;
this.address = address;
@RestController
public class DemoController
//http://localhost:8099/aa/zjhhhh/118/北京
@RequestMapping("/aa/name/age/address")
public String a(
@PathVariable("name") String name,
@PathVariable("age") int age,
@PathVariable("address") String address
)
User user = new User(name, age, address);
return user.toString();
第二种:
package com.rabbitmqdemo.demo;
import lombok.Data;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @auther
* @date 2020/1/9 17:13
* @description
*/
@Data
class User
String name;
Integer age;
String address;
public User(String name, Integer age, String address)
this.name = name;
this.age = age;
this.address = address;
@RestController
public class DemoController
//http://localhost:8099/aa/zjhhhh/118/北京
@RequestMapping("/aa/name/age/address")
public String a(User user)
return user.toString();
如果url传入的参数可以用一个对象接收的话,可以简写。
以上是关于Spring boot中 RestFull风格的主要内容,如果未能解决你的问题,请参考以下文章