All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.gccloud.starter.common.utils.LambdaUtils Maven / Gradle / Ivy

package com.gccloud.starter.common.utils;

import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.gccloud.starter.common.exception.GlobalException;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class LambdaUtils {

    /**
     * 获取属性名
     *
     * @param func
     * @param 
     * @return
     */
    public static  String getFieldName(SFunction func) {
        String implMethodName = com.baomidou.mybatisplus.core.toolkit.LambdaUtils.resolve(func).getImplMethodName();
        String prefix = null;
        if (implMethodName.startsWith("get")) {
            prefix = "get";
        } else if (implMethodName.startsWith("is")) {
            prefix = "is";
        }
        if (prefix == null) {
            throw new GlobalException("无效的getter方法: " + implMethodName);
        }
        implMethodName = implMethodName.replace(prefix, "");
        String fieldName = Character.toLowerCase(implMethodName.charAt(0)) + implMethodName.substring(1);
        return fieldName;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy