mybatis注解方式和xml方式的使用

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("  <script> "+
 62                " SELECT  * " +
 63                     " from  cn_device_call_log d "+
 64                         " <where> "+
 65                             " d.community_id=#{communityId}"+
 66                             " <if test='startTime != null'> "+
 67                                 " and DATE_FORMAT(d.event_time, '%m-%d-%Y') <![CDATA[>=]]> DATE_FORMAT(#{startTime}, '%m-%d-%Y')"+ 
 68                             " </if> "+
 69                             " <if test='endTime != null'> "+
 70                                 " and DATE_FORMAT(d.event_time, '%m-%d-%Y') <![CDATA[<=]]> DATE_FORMAT(#{endTime}, '%m-%d-%Y')"+ 
 71                             " </if> "+
 72                             " <if test='queryContent != null'> "+
 73                                 " and (d.sender like concat('%', #{queryContent}, '%')"
 74                                 + " or d.receiver like concat('%', #{queryContent}, '%'))"+
 75                             " </if> "+    
 76                             " order by creation_time desc" +    
 77                         " </where>"+
 78                 " </script> ")
 79     List<DeviceCallLogDO> findList(@Param("communityId")String communityId, 
 80             @Param("startTime")Date startTime, @Param("endTime")Date endTime, @Param("queryContent")String queryContent);
 81     
 82     @ResultMap("deviceCallLogDO")
 83     @Select("  <script> "+
 84                " SELECT  * " +
 85                     " from  cn_device_call_log d "+
 86                         " <where> "+
 87                             " d.community_id=#{communityId}"+
 88                             " <if test='startTime != null'> "+
 89                                 " and DATE_FORMAT(d.event_time, '%m-%d-%Y') <![CDATA[>=]]> DATE_FORMAT(#{startTime}, '%m-%d-%Y')"+ 
 90                             " </if> "+
 91                             " <if test='endTime != null'> "+
 92                                 " and DATE_FORMAT(d.event_time, '%m-%d-%Y') <![CDATA[<=]]> DATE_FORMAT(#{endTime}, '%m-%d-%Y')"+ 
 93                             " </if> "+
 94                             " <if test='queryContent != null'> "+
 95                                 " and (d.sender like concat('%', #{queryContent}, '%')"
 96                                 + " or d.receiver like concat('%', #{queryContent}, '%'))"+
 97                             " </if> "+    
 98                             " order by creation_time desc" +    
 99                         " </where> limit #{pageNo},#{pageSize}"+
100                 " </script> ")
101     List<DeviceCallLogDO> 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>

 

转载于:https://www.cnblogs.com/xjatj/p/9277426.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值