谷神后端代码模块化

本文详细描述了两个Java方法,用于在数据库中执行单行更新操作,包括参数解析、查询条件设置和乐观锁应用。
摘要由CSDN通过智能技术生成
selectOneForUpdate
/**
 * selectOneForUpdate
 *
 * @param $strTableName:string:表名
 * @param $form:map:表单参数
 * @param $options:object:参数可选项
 * @param $tipMsg:object:提示信息
 *
 * @return map
 *
 */
#function selectOneForUpdate($strTableName, $form, $options, $tipMsg)
	// 参数处理
	#if ($vs.util.isString($options))
		#set($options = $vs.util.fromJson($options))
	#end
	#if ($vs.util.isString($tipMsg))
		#set($tipMsg = '数据已变更,请刷新重试!')
	#end

	// 查询、更新条件
	#set($where = $vs.util.newMap())
	#if ($vs.util.isList($options))
		#foreach ($key in $options)
			$where.put($key, $form.get(key))
		#end
	#end
	#if ($vs.util.isMap($options))
		#foreach ($key in $vs.util.getMapKeys($options))
			$where.put($options.get($key), $form.get(key))
		#end
	#end

	// 查询
	#set($one = $vs.dbTools.selectOne($strTableName, $where))
	$vs.util.checkInput($one, $tipMsg)

	// 返回值初始化
	#set($result = $vs.util.newMap())
	$result.put('where', $where)
	$result.put('one', $one)

	// 返回
	return $result
#end

selectOneForSimpleUpdate
/**
 * selectOneForSimpleUpdate
 *
 * @param $strTableName:string:表名
 * @param $form:map:表单参数
 * @param $primaryKey:string:主键
 * @param $optimisticLock:string:乐观锁
 *
 * @return map
 *
 */
#function selectOneForSimpleUpdate($strTableName, $form, $primaryKey, $optimisticLock)
	// 参数处理
	#set($primaryKeyVar = $form.get($primaryKey))
	#set($optimisticLockVar = $form.get($optimisticLock))

	// 参数校验
	$vs.util.checkInput($primaryKeyVar, '主键不能为空!')
	$vs.util.checkInput($optimisticLockVar, '乐观锁不能为空!')

	// 查询、更新条件
	#set($where = $vs.util.newMap())
	$where.put($primaryKey, $primaryKeyVar)
	$where.put($optimisticLock, $optimisticLockVar)

	// 查询
	#set($one = $vs.dbTools.selectOne($strTableName, $where))
	$vs.util.checkInput($one, '数据已变更,请刷新重试!')


	// 返回值初始化
	#set($result = $vs.util.newMap())
	$result.put('where', $where)
	$result.put('one', $one)

	// 返回
	return $result
#end
  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值