MyBatis中的SQL语句总结(不断更新) PS:要记得

主要还是总结真的有各种各样的好处啊

1.传入一个ID链表和开始时间,结束时间,根据时间以及ID遍历,得到的数据中的某一列(字段)相加

输入:List<Long> ids    startTime   endTime

XML

<select id="getElectricByDevIdsAndTimes" resultMap="ElectricHour">
		select sum(total_power_)totalPower
		from dt_electric_hour
		where time_>=#{startTime} and time_&lt; #{endTime}
		<if test="@Ognl@isNotEmpty(devIds)">
			and dev_id_ in
			<foreach close=")" collection="devIds" item="id" open="(" separator=",">#{id}</foreach>
		</if>
	</select>

mapper

ElectricHour getElectricByDevIdsAndTimes(@Param("devIds") List<Long> devIds, @Param("startTime") Date startTime, @Param("endTime") Date endTime);

猜你喜欢

转载自blog.csdn.net/qq_39091546/article/details/106721754