当前位置:   article > 正文

java switch case 参数变量使用枚举_java switch case 后面 枚举.name

java switch case 后面 枚举.name

定义枚举

  1. public enum BusinessTypeEnum {
  2. OUT(new Byte("1"),"出库"),
  3. IN(new Byte("2"),"入库"),
  4. ACCOUNT(new Byte("3"),"转移记账"),
  5. MOVE(new Byte("4"),"转储"),
  6. ;
  7. BusinessTypeEnum(Byte value, String name) {
  8. this.value = value;
  9. this.name = name;
  10. }
  11. BusinessTypeEnum() {
  12. }
  13. private Byte value;
  14. private String name;
  15. public Byte getValue() {
  16. return value;
  17. }
  18. public String getName() {
  19. return name;
  20. }
  21. /**
  22. * 通过value取枚举
  23. * @param value
  24. * @return
  25. */
  26. public static BusinessTypeEnum getTypeByValue(Byte value){
  27. if (null == value){
  28. return null;
  29. }
  30. for (BusinessTypeEnum enums : BusinessTypeEnum.values()) {
  31. if (enums.getValue().intValue() == value.intValue()) {
  32. return enums;
  33. }
  34. }
  35. return null;
  36. }
  37. }

 

 

switch+枚举用法

  1. public void BusinessBatchOperationMove(BusinessBatchOperationMoveDTO moveDTO) {
  2. MoveTypeHandleBaseDTO baseDTO = moveDTO.getBaseDTO();
  3. switch (BusinessTypeEnum.getTypeByValue(moveDTO.getBusinessType())) {//通过value取枚举
  4. case IN:
  5. handleInBatchOperate(baseDTO);
  6. break;
  7. case OUT:
  8. handleOutBatchOperate(baseDTO);
  9. break;
  10. case MOVE:
  11. handleMoveBatchOperate(baseDTO);
  12. break;
  13. case ACCOUNT:
  14. handleAccountBatchOperate(baseDTO);
  15. break;
  16. default:
  17. break;
  18. }
  19. handleMoveType(baseDTO);
  20. }

over

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/729128
推荐阅读
相关标签
  

闽ICP备14008679号