com.tmsps.ne4spring.orm.SqlServerUtil Maven / Gradle / Ivy
package com.tmsps.ne4spring.orm;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.sql.ResultSet;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.tmsps.ne4spring.annotation.PK;
import com.tmsps.ne4spring.orm.model.DataModel;
import com.tmsps.ne4spring.utils.StrUtil;
public class SqlServerUtil {
static Logger log = LoggerFactory.getLogger(MySQLUtil.class);
public static String getInsSQL(final Class extends DataModel> clazz) {
int i = 0;
StringBuilder sb = new StringBuilder("insert into ");
// 获取表名称
sb.append(ClassUtil.getTableName(clazz)).append("(");
// 获取class中需要映射的属性名
List names = ClassUtil.getPropertyName(clazz);
for (i = 0; i < names.size() - 1; i++) {
// 生成映射的insert 语句
sb.append('[').append(names.get(i)).append("],");
}
sb.append('[').append(names.get(names.size() - 1)).append(']');
sb.append(") values (");
for (i = 0; i < names.size() - 1; i++) {
// 生成映射的占位符
sb.append("? , ");
}
sb.append("?)");
log.debug(sb.toString());
return sb.toString();
}
public static String getTemplateInsSQL(final String tableName,final List