赞
踩
定义枚举
- public enum BusinessTypeEnum {
- OUT(new Byte("1"),"出库"),
- IN(new Byte("2"),"入库"),
- ACCOUNT(new Byte("3"),"转移记账"),
- MOVE(new Byte("4"),"转储"),
- ;
-
- BusinessTypeEnum(Byte value, String name) {
- this.value = value;
- this.name = name;
- }
-
- BusinessTypeEnum() {
- }
-
- private Byte value;
-
- private String name;
-
- public Byte getValue() {
- return value;
- }
-
- public String getName() {
- return name;
- }
-
- /**
- * 通过value取枚举
- * @param value
- * @return
- */
- public static BusinessTypeEnum getTypeByValue(Byte value){
- if (null == value){
- return null;
- }
- for (BusinessTypeEnum enums : BusinessTypeEnum.values()) {
- if (enums.getValue().intValue() == value.intValue()) {
- return enums;
- }
- }
- return null;
- }
- }
switch+枚举用法
- public void BusinessBatchOperationMove(BusinessBatchOperationMoveDTO moveDTO) {
- MoveTypeHandleBaseDTO baseDTO = moveDTO.getBaseDTO();
- switch (BusinessTypeEnum.getTypeByValue(moveDTO.getBusinessType())) {//通过value取枚举
- case IN:
- handleInBatchOperate(baseDTO);
- break;
- case OUT:
- handleOutBatchOperate(baseDTO);
- break;
- case MOVE:
- handleMoveBatchOperate(baseDTO);
- break;
- case ACCOUNT:
- handleAccountBatchOperate(baseDTO);
- break;
- default:
- break;
- }
- handleMoveType(baseDTO);
- }
over
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。