数据库中有一张表,这张表有一个字段是C00001,C00002,C00003……这样递增的,给一段自动按照这种规律生成的java代码。类似的也可以

解决方案 »

  1.   

    就是说C99999是最多的?
    随便写下  
            String append [] = new String[]{"C00000","C0000","C000","C00","C0","C"};
           String str_id = "C00111";
           int int_id =  Integer.parseInt(str_id.substring(1));
           String new_str_id = String.valueOf( int_id + 1);
           new_str_id = append[new_str_id.length()] + new_str_id;
           System.out.println(new_str_id);
      

  2.   

    如果是要自己生成的话分成两段嘛 字母一段  数字一段。当后面数字到达99999的时候 字母就增加。字母增加直接转成char就可以直接加了。 public static void main(String[] args) {
    char c = 'a';
    System.out.println(++c);
    }
      

  3.   


          String str_id = "C09999";
            char start = str_id.substring(0,1).charAt(0);
            int int_id =  Integer.parseInt(str_id.substring(1));
            if(int_id==99999){
                   int_id = 0;
                   ++start;
            }
            String new_str_id = String.valueOf(++int_id );
            String append [] = new String[]{start+"00000",start+"0000",start+"000",start+"00",start+"0",start+""};
            new_str_id = append[new_str_id.length()] + new_str_id;
            System.out.println(new_str_id);
      

  4.   

    public String getNewEmployeeNo(String employeeNo) {
    int i = Integer.parseInt(employeeNo) + 1;
    String newEmpNo = String.format("%" + 6 + "s", i).replace(' ', '0');
    return newEmpNo;
    }
    这个是我在公司实习的时候做的项目用到的类似的一块,规则是让6位String类型数字实现自增长,和你的要求比较类似,你试着看下吧,有必要可以自己改改
      

  5.   

    触发器吧,每次max + 1
      

  6.   

    final AtomicInteger counter = new AtomicInteger(0);String s = String.format("C%05d",counter.incrementAndGet());