生成唯一code

    private String getCode() {
        List<String> ptypeCodeList = mapper.findCodeList();
        String code = "";
        for(int i=0;i<ptypeCodeList.size();i++) {
            code = "TY"+i;
            if(!ptypeCodeList.contains(code)) {
                return code;
            }
        }
        return "TY"+ptypeCodeList.size();
    }

这种方法需要遍历数据库,仅适用于数据库中的数据量较小的情况。

猜你喜欢

转载自www.cnblogs.com/excellencesy/p/10069500.html