SpringBoot处理枚举数据类型

springboot中,controller与前端的交互,只能是json格式,也就是都认为是string字符串类型。枚举也一样,跟String类型一样,有一个地方要注意,传递枚举只能是get请求,不能是post。

附上代码

枚举声明

public enum CommType {
		BLUETOOTH, TCP, USB, IPC
	}

controller类处理

@GetMapping("/init/1")
	public Result<?> initDevice_1(@RequestParam(value="commtype") DeviceInfo.CommType commtype)

swagger展示

另外补充一句,如果controller中的参数是实体类,实体类的字段有枚举类型springboot是无法保存数据的。解决方案参考

https://blog.csdn.net/lanqibaoer/article/details/62215380

posted @ 2018-08-01 16:46  TroubleBoy丶  阅读(2357)  评论(0编辑  收藏  举报