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

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

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

import java.lang.reflect.Field;

import org.apache.ibatis.jdbc.SQL;

/**
 * mybatis delete entity provider
 * @author jch
 *
 */
public class DeleteEntityProvider extends BaseProvider{

	public String delete(Object entity){
		Class cls = entity.getClass();
		SQL sql = new SQL();
		
		sql.DELETE_FROM(getTableName(entity));
		
		Field[] fields = cls.getDeclaredFields();
		
		if(null != entity){
			
			for (int i = 0; i < fields.length; i++) {
				Field field = fields[i];
				field.setAccessible(true);
				
				try {
					Object value = field.get(entity);
					if(null != value){
						
						sql.WHERE(getColName(field)+"=#{"+field.getName()+"}");
					}
				} catch (IllegalArgumentException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (IllegalAccessException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
		
		System.out.println(sql);
		
		return sql.toString();
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy