mybaits requestMap与requestType,以及对应的注解
有的时候不喜欢用xml配置文件,但是xml配置文件的开发使用简单,自己经常要用到;
因为代码维护的缘故,有的时候看别人的代码,可能存在大量的mappper文件,也不是你想用注解就用注解的;
下面我还是贴一段代码,BaseResultMap返回的是更多的result,而reulstType只返回一种类型;
resulstMap其实对应注解@Results,resultType对应的是@Result参考第二段代码
<resultMap id="BaseResultMap" type="XX.XXMatch">
<id column="i_id" jdbcType="BIGINT" property="iId" />
<result column="XX" jdbcType="VARCHAR" property="XX" />
<result column="XX" jdbcType="VARCHAR" property="XX" />
<result column="XX" jdbcType="VARCHAR" property="XX" />
<result column="XX" jdbcType="VARCHAR" property="XX" />
<result column="XX" jdbcType="TIMESTAMP" property="XX" />
<result column="d_create_time" jdbcType="TIMESTAMP" property="dCreateTime" />
<result column="d_update_time" jdbcType="TIMESTAMP" property="dUpdateTime" />
</resultMap>
<sql id="Base_Column_List">
XX, XX, XX, XX, XX, XX,
d_create_time, d_update_time
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from ipps_face_match
where i_id = #{iId,jdbcType=BIGINT}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
delete from ipps_face_match
where i_id = #{iId,jdbcType=BIGINT}
</delete>
<insert id="insert" parameterType="XX.XXMatch">
insert into ipps_face_match (XX, XX, XX,
XX, XX, XX,
d_create_time, d_update_time)
values (#{iId,jdbcType=BIGINT}, #{XX,jdbcType=VARCHAR}, #{XX,jdbcType=VARCHAR},
#{XX,jdbcType=VARCHAR}, #{XX,jdbcType=VARCHAR}, #{XX,jdbcType=TIMESTAMP},
#{dCreateTime,jdbcType=TIMESTAMP}, #{dUpdateTime,jdbcType=TIMESTAMP})
</insert>
@Insert("insert into t_alarm (index_code, happened_time, address,save_time)"
+ "values (#{indexCode}, #{happenedTime},#{address},#{saveTime})")
@Options(useGeneratedKeys = true)
int save(DeviceAlarm deviceAlarm);
//因为返回的字段就是*,所以还是写为*。如果查询一部分字段,不能使用*
@Select("select * from t_alarm order by id desc limit 3")
@Results({
@Result(id = true, column = "id", property = "id"),
@Result(column = "index_code", property = "indexCode"),
@Result(column = "happened_time", property = "happenedTime"),
@Result(column = "address", property = "address"),
@Result(column = "save_time", property = "saveTime"),
// map-underscore-to-camel-case = true 可以实现一样的效果
// @Result(column = "update_time", property = "updateTime"),
})
ArrayList<DeviceAlarm> findTopAlarms();
mybaits requestMap与requestType,以及对应的注解的更多相关文章
- 动态生成简约MVC请求接口|抛弃一切注解减少重复劳动吧
背景 目前创建一个后端请求接口给别人提供服务,无论是使用SpringMVC方式注解,还是使用SpringCloud的Feign注解,都是需要填写好@RequestMap.@Controller.@Pa ...
- Java Persistence with MyBatis 3(中文版) 第三章 使用XML配置SQL映射器
关系型数据库和SQL是经受时间考验和验证的数据存储机制.和其他的ORM 框架如Hibernate不同,MyBatis鼓励开发者可以直接使用数据库,而不是将其对开发者隐藏,因为这样可以充分发挥数据库服务 ...
- SSM框架整合的最新打开方式(打造最详细的SSM整合教程)
SSM整合 文章已托管到GitHub,大家可以去GitHub查看阅读,欢迎老板们前来Star!搜索关注微信公众号 [码出Offer] 领取各种学习资料! SSM 一.创建一个Maven项目 File ...
- springboot整合mybaits注解开发
springboot整合mybaits注解开发时,返回json或者map对象时,如果一个字段的value为空,需要更改springboot的配置文件 mybatis: configuration: c ...
- mybaits拦截器+自定义注解
实现目的:为了存储了公共字典表主键的其他表在查询的时候不用关联查询(所以拦截位置位于mybaits语句查询得出结果集后) 项目环境 :springboot+mybaits 实现步骤:自定义注解——自定 ...
- 8、Spring+Struts2+MyBaits(Spring注解+jdbc属性文件+log4j属性文件)
一.注解理论 使用注解来构造IoC容器 用注解来向Spring容器注册Bean.需要在applicationContext.xml中注册<context:component-scan base- ...
- 关于mybaits的注解@Param
一.含义 @param作为dao层的注解,为了解决多个参数时,参数类型不一致的问题. <select id="findEmpById" resultType="co ...
- mybaits的注解方式与配置文件方式比较
注解方式比配置文件方式简单了更多. 俩种配置 一个是制定配置文件路径,一个直接class指向dao层接口 只需加一个注解@**** 就能够实现 比写一个xml的配置文件简单更多.
- mybaits注解
基本的增删改 @Insert("insert into t_user values(null,#{username},#{password},#{account})") @Dele ...
随机推荐
- redis-start
start CAP BASE: 基本可用 Basically Available 软状态 Soft state 最终一致 Eventually consistent Redis:REmote DIct ...
- eclipse 切换主题Theme
eclipse切换主题theme 1. 打开help -> eclipse marketplace,搜索theme 2. 点击右侧安装后一直继续,直到安装完成 3. 安装完成后会重启eclips ...
- 一个汇编小demo
一个小demo: #include<stdio.h> void main(){ ; char *str="i=%d\n"; printf("begin\n&q ...
- 吴裕雄--天生自然神经网络与深度学习实战Python+Keras+TensorFlow:使用TensorFlow和Keras开发高级自然语言处理系统——LSTM网络原理以及使用LSTM实现人机问答系统
!mkdir '/content/gdrive/My Drive/conversation' ''' 将文本句子分解成单词,并构建词库 ''' path = '/content/gdrive/My D ...
- TensorFlow使用RNN实现手写数字识别
学习,笔记,有时间会加注释以及函数之间的逻辑关系. # https://www.cnblogs.com/felixwang2/p/9190664.html # https://www.cnblogs. ...
- ES-moreLikeThisQueryBuilder-文章推荐
//获取推荐文章 public Object getRecommendList2(String name) { NativeSearchQueryBuilder queryBuilder = new ...
- wsgiref模块
学习django框架之前,可以先学习一下wsgiref模块,熟悉前后端交互. 一.先介绍下wsgiref模块 WSGI(Web Server Gateway Interface)是一种规范,它定义了使 ...
- 15 FFT及其框图实现
FFT及其框图实现 \(FFT\)的全称为快速傅里叶变换,但是\(FFT\)并不是一种变换,而是实现\(DFT\)的一种快速算法.当\(N\)比较大时,使用\(FFT\)可大大减少进行\(DFT\)变 ...
- 矩阵matrix
矩阵matrix 1. 矩阵matrix 1.1. 定义由 m × n 个数aij排成的m行n列的数表称为m行n列的矩阵,简称m × n矩阵.记作: 这m×n 个数称为矩阵A的元素,简称为元,数aij ...
- SPOJ QTREE Query on a Tree【树链剖分模板题】
树链剖分,线段树维护~ #include <cstdio> #include <cstring> #include <iostream> #include < ...