好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

Java实现转跳不同系统使用枚举加switch的方式示例

因有个判断需要处理不同系统类型跳转不同系统。考虑用 switch + 枚举 的方式。

具体使用案例如下:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

package com.b2b测试数据mon.constant;

import com.base.utils.base.stringutils;

/**

  * 系统类型枚举

  * @author shijing

  */

public enum systemtype {

   erp( 0 , "erp" ),

   order_platform( 1 , "订货平台" ),

   personal( 2 , "个人中心系统" ),

   shop_mall( 3 , "商城" ),

   partner( 4 , "伙伴系统" );

   private int value;

   private string desc;

   systemtype( int value ,string desc) {

     this .value = value;

     this .desc = desc;

   }

   public int getvalue() {

     return value;

   }

   public string getdesc() {

     return desc;

   }

   /**

    * 通过value取枚举

    * @param value

    * @return

    */

   public static systemtype gettypebyvalue(string value){

     if (stringutils.isnull(value)){

       return null ;

     }

     int valuekey = integer.parseint(value);

     for (systemtype enums : systemtype.values()) {

       if (enums.getvalue() == valuekey) {

         return enums;

       }

     }

     return null ;

   }

   /**

    * 通过value取描述

    * @param value

    * @return

    */

   public static string getdescbyvalue( int value) {

     for (systemtype enums : systemtype.values()) {

       if (enums.getvalue() == value) {

         return enums.getdesc();

       }

     }

     return "" ;

   }

}

switch+枚举的使用案例:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

/**

    * 区分不同系统类型,登录不同系统

    * @author shijing

    * @param parammap

    * @param checkdata

    * @return

    * @throws exception

    */

   private erpresponse getloginresponse(map<string, object> parammap, erpresponse checkdata) throws exception {

     erpresponse logindata = null ;

     map<string,object> user= (map<string, object>) checkdata.getdata();

     //获取user的系统类型,然后区分是哪个系统实例用户登录

     string sysbasetype = (string) user.get( "sys_base_type" );

     systemtype systemtype = systemtype.gettypebyvalue(sysbasetype);

     switch (systemtype){

       case erp:

         erplogin((string) user.get( "user_id" ));

         logindata.setdata(user);

         break ;

       case order_platform:

         //订货平台

         orderplatformloginbycheck(parammap);

         logindata.setdata(user);

         break ;

       case personal:

         //个人中心

         logindata = personallogin(user);

         break ;

       default :

         logger.info( "系统类型不满足" );

         break ;

     }

     return logindata;

   }

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对的支持。如果你想了解更多相关内容请查看下面相关链接

查看更多关于Java实现转跳不同系统使用枚举加switch的方式示例的详细内容...

  阅读:13次