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是無法保存數據的。解決方案參考