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 ...
随机推荐
- 动态设置 layui select 为选中状态
// 当前的select的id $('#type').val('你的value值'); //更新全部 layui.form.render();
- LOJ#6713. 「EC Final 2019」狄利克雷 k 次根 加强版
题目描述 定义两个函数 \(f, g: \{1, 2, \dots, n\} \rightarrow \mathbb Z\) 的狄利克雷卷积 \(f * g\) 为: \[ (f * g)(n) = ...
- 《爬虫学习》(三)(requests库使用)
requests库 虽然Python的标准库中 urllib模块已经包含了平常我们使用的大多数功能,但是它的 API 使用起来让人感觉不太好,而 Requests宣传是 “HTTP for Human ...
- springBoot日志快速上手简单配置
默认配置 日志级别从低到高分为: TRACE < DEBUG < INFO < WARN < ERROR < FATAL. 如果设置为 INFO ,则低于 INFO 的信 ...
- java篇 之 变量存放位置
一:在方法中声明的变量,即该变量是局部变量,每当程序调用方法时,系统都会为该方法建立一个方法栈,其所在方法中声明的变量就放在方法栈中,当方法结束系统会释放方法栈,其对应在该方法中声明的变量随着栈的销毁 ...
- [转] C++ CImage实现的全屏PNG截图
#include <atlimage.h> #include <atltime.h> #include <conio.h> //截取全屏保存为png CString ...
- SDNU_ACM_ICPC_2020_Winter_Practice_1st
A Petya is a big fan of mathematics, esecially its part related to fractions. Recently he learned th ...
- RTT学习之启动流程
总结RT-Thread的启动流程. 非运行时与运行时的image文件分别是什么样的,请画下来.是谁将 RW 段中的 RW-data(初始化的全局变量)搬运到 RAM 中? MDK环境下各种数据段存储 ...
- 【JavaScript基础#1】
" 目录 #. 概述 1. ECMAScript与JavaScript的关系 2. ECMAScript版本历史 3. 简单总结 #. 用法 1. 引入方式 2. 规范 3. 变量声明 ...
- 初探three.js几何体-Geometry
three.js几何体我们还没有说完,这一节我们说一说THREE.Geometry(),简单几何体都是继承了这个对象,使用它会相对麻烦一些,但是可操作性非常高,今天我们使用它制作一个自定义几何体-五角 ...