public static SqlParamsPairs getUpdateFromObject(Object po) throws Exception{
		
		//用来存放insert语句
		StringBuffer updateSql = new StringBuffer();
		
		//用来存放where语句
		StringBuffer whereSql = new StringBuffer();
		
		//用来存放参数值
		List<Object> params = new ArrayList<Object>();
		
		//用来存储id
		Object idValue = null;
		
		//分析表名
		String tableName = getTableName(po.getClass());
		
		updateSql.append("update " + tableName + " set");
		
		//分析列
		Field[] fields = po.getClass().getDeclaredFields();
		
		//用于计数
		int count = 0;
		for (int i = 0; i < fields.length; i++) {
			Field f = fields[i];
			
			//获取具体参数值
			Method getter = getGetter(po.getClass(),f);
			
			if(getter == null){
				continue;
			}
			
			Object value = getter.invoke(po);
			if(value == null){
				//如果参数值是null就直接跳过（不允许覆盖为null值，规范要求更新的每个字段都要有值，没有值就是空字符串）
				continue;
			}
			
			Transient tranAnno = getter.getAnnotation(Transient.class);
			if(tranAnno != null){
				//如果有 Transient 标记直接跳过
				continue;
			}
			
			//获取字段名
			String columnName = getColumnNameFromGetter(getter,f);
			
			//看看是不是主键
			Id idAnno = getter.getAnnotation(Id.class);
			if(idAnno != null){
				//如果是主键
				whereSql.append(columnName + " = ?");
				idValue = value;
				continue;
			}
			
			//如果是普通列
			params.add(value);
			
			if(count!=0){
				updateSql.append(",");
			}
			updateSql.append(" " + columnName + " = ?");
			
			count++;
		}
		
		updateSql.append(" where ");
		updateSql.append(whereSql);
		params.add(idValue);
		
		SqlParamsPairs sqlAndParams = new SqlParamsPairs(updateSql.toString(),params.toArray());
		logger.debug(sqlAndParams.toString());
		
		return sqlAndParams;
		
	}
public static SqlParamsPairs getUpdateFromObject ( Object po ) throws Exception { StringBuffer updateSql = new StringBuffer ( ) ; StringBuffer whereSql = new StringBuffer ( ) ; List < Object > params = new ArrayList < Object > ( ) ; Object idValue = null ; String tableName = getTableName ( po . getClass ( ) ) ; updateSql . append ( "update " + tableName + " set" ) ; Field [ ] fields = po . getClass ( ) . getDeclaredFields ( ) ; int count = 0 ; for ( int i = 0 ; i < fields . length ; i ++ ) { Field f = fields [ i ] ; Method getter = getGetter ( po . getClass ( ) , f ) ; if ( getter == null ) { continue ; } Object value = getter . invoke ( po ) ; if ( value == null ) { continue ; } Transient tranAnno = getter . getAnnotation ( Transient . class ) ; if ( tranAnno != null ) { continue ; } String columnName = getColumnNameFromGetter ( getter , f ) ; Id idAnno = getter . getAnnotation ( Id . class ) ; if ( idAnno != null ) { whereSql . append ( columnName + " = ?" ) ; idValue = value ; continue ; } params . add ( value ) ; if ( count != 0 ) { updateSql . append ( "," ) ; } updateSql . append ( " " + columnName + " = ?" ) ; count ++ ; } updateSql . append ( " where " ) ; updateSql . append ( whereSql ) ; params . add ( idValue ) ; SqlParamsPairs sqlAndParams = new SqlParamsPairs ( updateSql . toString ( ) , params . toArray ( ) ) ; logger . debug ( sqlAndParams . toString ( ) ) ; return sqlAndParams ; }
从对象中获取update语句
@param po
@return
@throws Exception