Mybatis的注解方式的使用:
1 package com.hikvision.building.cloud.neptune.device.biz.domain.mapper; 2 3 import java.util.Date; 4 import java.util.List; 5 6 import org.apache.ibatis.annotations.Insert; 7 import org.apache.ibatis.annotations.Mapper; 8 import org.apache.ibatis.annotations.Options; 9 import org.apache.ibatis.annotations.Param; 10 import org.apache.ibatis.annotations.Result; 11 import org.apache.ibatis.annotations.ResultMap; 12 import org.apache.ibatis.annotations.Results; 13 import org.apache.ibatis.annotations.Select; 14 import org.apache.ibatis.annotations.Update; 15 16 import com.hikvision.building.cloud.neptune.device.biz.domain.DeviceCallLogDO; 17 18 /** 19 * 设备呼叫日志 20 * @author like15 21 * @version 2017年11月15日下午5:02:15 22 * @since 2017年11月15日 23 */ 24 @Mapper 25 public interface DeviceCallLogMapper { 26 27 @Results(id="deviceCallLogDO",value={ 28 @Result(property = "id", column = "id"), 29 @Result(property = "tenantId", column = "tenant_id"), 30 @Result(property = "communityId", column = "community_id"), 31 @Result(property = "devSerial", column = "dev_serial"), 32 @Result(property = "sender", column = "sender"), 33 @Result(property = "receiver", column = "receiver"), 34 @Result(property = "duration", column = "duration"), 35 @Result(property = "eventTime", column = "event_time"), 36 @Result(property = "state", column = "state"), 37 @Result(property = "remark", column = "remark"), 38 @Result(property = "callId", column = "call_id"), 39 @Result(property = "creationTime", column = "creation_time"), 40 @Result(property = "updateTime", column = "update_time"), 41 }) 42 43 44 @Select("select * from cn_device_call_log where dev_serial=#{devSerial} and call_id=#{callId}") 45 DeviceCallLogDO findByCallId(@Param("devSerial")String devSerial, @Param("callId")String callId); 46 47 @Insert("INSERT INTO cn_device_call_log(id,tenant_id,community_id,dev_serial,sender,receiver,duration,event_time,state,remark," 48 + "call_id,creation_time,update_time)" 49 + "VALUES(#{id},#{tenantId},#{communityId},#{devSerial},#{sender},#{receiver},#{duration},#{eventTime},#{state},#{remark}," 50 + "#{callId},#{creationTime},#{updateTime})") 51 @Options(useGeneratedKeys = false, keyProperty = "id") 52 int addDeviceCallLogInfo(DeviceCallLogDO info); 53 54 @Update("UPDATE cn_device_call_log SET state=#{state}, duration=#{duration} where dev_serial=#{devSerial} and call_id=#{callId}") 55 int updateByCallId(@Param("duration")int duration, @Param("state")int state, @Param("devSerial")String devSerial, @Param("callId")String callId); 56 57 @Update("UPDATE cn_device_call_log SET state=#{state} where dev_serial=#{devSerial} and call_id=#{callId}") 58 int updateByDevSerialCallId(@Param("state")int state, @Param("devSerial")String devSerial, @Param("callId")String callId); 59 60 @ResultMap("deviceCallLogDO") 61 @Select(" ") 79 ListfindList(@Param("communityId")String communityId, 80 @Param("startTime")Date startTime, @Param("endTime")Date endTime, @Param("queryContent")String queryContent); 81 82 @ResultMap("deviceCallLogDO") 83 @Select(" ") 101 List findListPage(@Param("communityId")String communityId, 102 @Param("startTime")Date startTime, @Param("endTime")Date endTime, @Param("queryContent")String queryContent, 103 @Param("pageNo")int pageNo, @Param("pageSize")int pageSize); 104 }
Mybatis的xml的使用
xml version="1.0" encoding="UTF-8" ?> DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> <settings> <setting name="cacheEnabled" value="true"/> <setting name="lazyLoadingEnabled" value="true"/> <setting name="multipleResultSetsEnabled" value="true"/> <setting name="useColumnLabel" value="true"/> <setting name="useGeneratedKeys" value="false"/> <setting name="autoMappingBehavior" value="PARTIAL"/> <setting name="autoMappingUnknownColumnBehavior" value="WARNING"/> <setting name="defaultExecutorType" value="SIMPLE"/> <setting name="defaultStatementTimeout" value="25"/> <setting name="defaultFetchSize" value="100"/> <setting name="safeRowBoundsEnabled" value="false"/> <setting name="mapUnderscoreToCamelCase" value="false"/> <setting name="localCacheScope" value="SESSION"/> <setting name="jdbcTypeForNull" value="OTHER"/> <setting name="lazyLoadTriggerMethods" value="equals,clone,hashCode,toString"/> settings> configuration>