• Enum遇到下拉框


    package com.zj.tool;
    
    public enum WeekDay {
        Mon("Monday",1),
        Tue("Tuesday",2),
        Wed("Wednesday",3),
        Thu("Thursday",4),
        Fri("Friday",5),
        Sat("Saturday",6),
        Sun("Sunday",7);
    
        /**定义枚举类型自己的属性**/
        private final String day;
        private final int dayNum;
        private WeekDay(String day,int dayNum) {
            this.day = day;
            this.dayNum = dayNum;
        }
    
        
        public int getDayNum()
        {
            return dayNum;
        }
    
    
        /**定义枚举类型自己的方法**/
        public static void printDay(int i){
            switch(i){
                case 1: System.out.println(WeekDay.Mon); break;
                case 2: System.out.println(WeekDay.Tue);break;
                case 3: System.out.println(WeekDay.Wed);break;
                case 4: System.out.println(WeekDay.Thu);break;
                case 5: System.out.println(WeekDay.Fri);break;
                case 6: System.out.println(WeekDay.Sat);break;
                case 7: System.out.println(WeekDay.Sun);break;
                default:System.out.println("wrong number!");
            }
        }
    
        public String getDay() {
            return day;
        }
        public static void main(String args[]) {
            for (WeekDay day : WeekDay.values()) {
                System.out.println(day + "====>" + day.getDay()+ "====>" + day.getDayNum());
            }
            WeekDay.printDay(5);
        }
    }

    一个很实际的问题,数据库里面存的是数字但是页面要显示字符串,此时就i显示出enum的好处了

  • 相关阅读:
    MQTT Client软件-MQTTBox
    Eclipse
    Ant + ivy的安装
    常用消息中间件比较
    各种MQTT server功能比較
    消息中间件的对比
    RabbitMQ Performance Testing Tool 性能测试工具
    Eureka 简介
    win10 localhost 解析为::1 的解决办法
    JSP中过滤器的设置
  • 原文地址:https://www.cnblogs.com/rocky-AGE-24/p/5500106.html
Copyright © 2020-2023  润新知