使用postman测试接口,其中一个参数为枚举类型,如何传入参数?
1 枚举类型:
- public enum UserCourseOrderSourceType{
- USER_BUY(1,"用户下单购买"),
- OFFLINE_BUY(2,"后台添加专栏");
-
- private Integer code;
- private String name;
-
-
- UserCourseOrderSourceType(Integer code, String name) {
- this.code = code;
- this.name = name;
- }
-
- public Integer getCode() {
- return code;
- }
-
- public String getName() {
- return name;
- }
-
- private static final Map<Integer, UserCourseOrderSourceType> CACHE = new HashMap<Integer, UserCourseOrderSourceType>();
-
- static {
- for (UserCourseOrderSourceType val : UserCourseOrderSourceType.values()) {
- CACHE.put(val.getCode(), val);
- }
- }
-
- /**
- * 根据code值来转换为枚举类型
- */
- public static UserCourseOrderSourceType parse(Integer code) {
- return CACHE.get(code);
- }
-
- }
2 java实体类:
- public class CreateShopGoodsOrderReqDTO implements Serializable {
-
- /**
- */
- private static final long serialVersionUID = 6507306131413105949L;
- private Integer goodsId;//商品id
- private Integer userId;//用户id
- private UserCourseOrderSourceType sourceType;//订单来源
-
-
- }
3、controller控制类
- @PostMapping("/saveOrder")
- public ResponseDTO<UserCourseOrderResDTO> saveOrder(@RequestBody CreateShopGoodsOrderReqDTO reqDTO) {
- log.info("saveOrder - reqDTO:{}", JSON.toJSONString(reqDTO));
- return ResponseDTO.success(userCourseOrderService.saveOrder(reqDTO));
- }
4 Postman使用json传入参数为:
{
"goodsId":11,
"userId":1,
"sourceType":"USER_BUY" --枚举传参
}
5、后台接收的结果
标签:code,java,postman,枚举,private,UserCourseOrderSourceType,json,Integer,public From: https://www.cnblogs.com/DeveloperPan/p/17151504.html