首页 > 其他分享 >insert daoSupport

insert daoSupport

时间:2023-04-23 17:36:10浏览次数:32  
标签:insert poMap Object cols str table null daoSupport


public static Map po2Map(Object po) {
		Map poMap = new HashMap();
		Map map = new HashMap();
		try {
			map = BeanUtils.describe(po);
		} catch (Exception ex) {
		}
		Object[] keyArray = map.keySet().toArray();
		for (int i = 0; i < keyArray.length; i++) {
			String str = keyArray[i].toString();
			if (str != null && !str.equals("class")) {
				if (map.get(str) != null) {
					poMap.put(str, map.get(str));
				}
			}
		}

		Method[] ms =po.getClass().getMethods();
		for(Method m:ms){
			String name = m.getName();

			if(name.startsWith("get")){
				if(m.getAnnotation(NotDbField.class)!=null){
					poMap.remove(getFieldName(name)); 
				} 
			}

		}
		return poMap;
	}

public void insert(String table, Object po) {

		Map poMap =  ReflectionUtil.po2Map(po);

		table = this.dbRouter.getTableName( table);
		this.jdbcDaoSupport.insert(table, poMap);
	}
public void insert(String table, Map fields) {
		String sql = "";

		try {

			Assert.hasText(table, "表名不能为空");
			Assert.notEmpty(fields, "字段不能为空");
			table = quoteCol(table);

			Object[] cols = fields.keySet().toArray();
			Object[] values = new Object[cols.length];
			for (int i = 0; i < cols.length; i++) {
				if (fields.get(cols[i]) == null) {
					values[i] = null;
				} else {
					values[i] = fields.get(cols[i]).toString();
				}
				cols[i] = quoteCol(cols[i].toString());
			}

			sql = "INSERT INTO " + table + " ("
					+ StringUtil.implode(", ", cols) + ") VALUES ("
					+ StringUtil.implodeValue(", ", values) + ")";

			jdbcTemplate.update(sql, values);
		} catch (Exception e) {
			e.printStackTrace();
			throw new DBRuntimeException(e, sql);
		}
	}

标签:insert,poMap,Object,cols,str,table,null,daoSupport
From: https://blog.51cto.com/u_16085348/6218430

相关文章

  • QT中在使用QMediaPlaylist类的insertMedia函数插入新播放文件后,出现播放顺序错误的分
    我下面的这段代码的意图是:当前的播放队列中插入一个播放文件到队首,使其为下一个播放文件。但是并没有达到我的预期。于是在代码中加入一段调试程序,将当前的播放文件的序号打印出来。 调试之后的结果如下:发现无论向播放队列中插入几次,当前的播放序列都是1。如果想要在播放......
  • jdbc insert数据后获取ID
    有时insert数据,数据ID为自动生成,需要获取ID。 以下就是获取ID的方法:publicstaticStringinsertByID(Stringsql,IDataBaseBeanbean,ArrayList<Object>keyvalueList,ArrayList<Class<?>>classtypeList,SingleDataSourcedatasource)throwsSQLException{ Connectionconn=......
  • MsSql 根据表名和条件,生成Insert语句
    ALTERproc[dbo].[proc_insert](@tablenamevarchar(256),@wherevarchar(max))asbeginsetnocountondeclare@sqlstrvarchar(MAX)declare@sqlstr1varchar(MAX)declare@sqlstr2varchar(MAX)select@sqlstr='select''INSERT'+@tablename......
  • mysql insert|replace语法
    insert语法replace语法版权声明:本文所有权归作者!商业用途转载请联系作者授权!非商业用途转载,请标明本文链接及出处!赞成、反驳、不解的小伙伴,欢迎一起交流!......
  • pretter 报 error Insert `·` prettier/prettier
    <c-switch:switchList="['自取','外送']"@change="switchChange"></c-switch>原因是//switchList里面的数组逗号后面要有一个空格<c-switch:switchList="['自取','外送']"@change="switchChange&quo......
  • Insert a scratch project into a ppt (MSPowerPoinT file)在powerpoint中播放Scratch
    Insertascratchprojectintoappt(MSPowerPoinTfile)在powerpoint中播放Scratch动画Contributedbyliupeng,March01,20120Comments4BookmarksAsupersimplewaytoinsertasbtoappt,asfollows:超级简单的实现Scratch的sb文件在ppt中播放,具体......
  • SearchInsert
    packageBisectionMethod;/***35.搜索插入位置*给定一个排序数组和一个目标值,在数组中找到目标值,并返回其索引。如果目标值不存在于数组中,返回它将会被按顺序插入的位置。*请必须使用时间复杂度为O(logn)的算法。***/publicclassSearchInsert{publi......
  • SELECT INTO 和 INSERT INTO SELECT 两种表复制语句
    Insert是T-sql中常用语句,InsertINTOtable(field1,field2,...)values(value1,value2,...)这种形式的在应用程序开发中必不可少。但我们在开发、测试过程中,经常会遇到需要......
  • 添加删除修改(insert,update,【delete和truncate】)
                    ......
  • 仅当指定列列表,且SET IDENTITY_INSERT为ON时,才能对自增列赋值
    #情景今天在做达梦数据库(DM7)的适配工作,发现了如上错误,#原因主要原因就是达梦数据库和oracle比较类似,你目前设置了主键自增,然后呢,现在还想手动设置主键,这咋能行呢#解......