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

club.chlab.mybatis.provider.BaseProvider Maven / Gradle / Ivy

The newest version!
package club.chlab.mybatis.provider;

import java.lang.reflect.Field;

import club.chlab.mybatis.annotations.Column;
import club.chlab.mybatis.annotations.Table;

/**
 * Base provider
 * @author jch
 *
 */
public class BaseProvider {

	public boolean isEmpty(Object o){
		
		return null == o || "".equals(o.toString().trim());
	}
	
	public String getTableName(Object entity){
		Class cls = entity.getClass();
		if (cls.isAnnotationPresent(Table.class)
				&& !isEmpty(cls.getAnnotation(Table.class).name())) {
			Table annotation = cls.getAnnotation(Table.class);

			return annotation.name();
		} else {

			return cls.getSimpleName();
		}
	}

	
	public String getColName(Field field){
		field.setAccessible(true);
		
		Column annotation = field.getAnnotation(Column.class);
		if(null == annotation || isEmpty(annotation.name())){
			
			return field.getName();
		}
		else{
			
			return annotation.name();
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy