myBaits SQL
2019独角兽企业重金招聘Python工程师标准>>>
myBaits SQL
增:
void addService(Service service);
<insert id="addService" parameterType="com.dsl.entity.Service">
insert into service_DSL (service_id,status,account_id,cost_id,unix_host,os_username,login_passwd)
values (service_seq_DSL.nextval,1,#{account_id},#{cost_id},#{unix_host},#{os_username},#{login_passwd})
</insert>
void save(Cost cost);
<insert id="save" parameterType="com.dsl.entity.Cost">
<!-- #{}中的字符串是实体对象中的属性名,不是表中的字段名
当传入参数为null时,MyBatis无法判断其类型,那么在处理参数值时就会有错误。
要想解决这个问题,需要给这些可以为null的参数明确设置类型,格式是jdbcType=类型(大写)。
注:一般表中字段太多了,挨个去判断是否可以为null麻烦,索性都写上jdbcType算了。-->
insert into cost_DSL values(cost_seq_DSL.nextval,
#{name,jdbcType=VARCHAR},
#{base_duration,jdbcType=INTEGER},
#{base_cost,jdbcType=DOUBLE},
#{unit_cost,jdbcType=DOUBLE},
#{status,jdbcType=CHAR},
#{descr,jdbcType=VARCHAR},
#{creatime,jdbcType=TIMESTAMP},
#{startime,jdbcType=TIMESTAMP},
#{cost_type,jdbcType=CHAR})
</insert>
void addAdmin(Admin admin);
<insert id="addAdmin" parameterType="com.dsl.entity.Admin">
<selectKey keyProperty="admin_id" order="BEFORE" resultType="Integer">
select admin_seq_DSL.nextval from dual
</selectKey>
insert into admin_info_DSL (admin_id,admin_code,password,name,telephone,email)
values (#{admin_id},#{admin_code},#{password},#{name},#{telephone},#{email})
</insert>
int insertSelective(User record);
<insert id="insertSelective" parameterType="com.cn.hnust.pojo.User" >
insert into user_t
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="id != null" >
id,
</if>
<if test="userName != null" >
user_name,
</if>
<if test="password != null" >
password,
</if>
<if test="age != null" >
age,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="id != null" >
#{id,jdbcType=INTEGER},
</if>
<if test="userName != null" >
#{userName,jdbcType=VARCHAR},
</if>
<if test="password != null" >
#{password,jdbcType=VARCHAR},
</if>
<if test="age != null" >
#{age,jdbcType=INTEGER},
</if>
</trim>
</insert>
删:
void delete(Integer id);
<delete id="delete" parameterType="Integer">
delete from cost_DSL where cost_id=#{id}
</delete>
改:
void modify(Cost cost);
<update id="modify" parameterType="com.dsl.entity.Cost">
update cost_DSL set name=#{name},
cost_type=#{cost_type},
base_duration=#{base_duration,jdbcType=INTEGER},
base_cost=#{base_cost,jdbcType=DOUBLE},
unit_cost=#{unit_cost,jdbcType=DOUBLE},
descr=#{descr,jdbcType=VARCHAR}
where cost_id=#{cost_id}
</update>
void modifyAccount(Account account);
<update id="modifyAccount" parameterType="com.dsl.entity.Account">
update account_DSL
<set>
<if test='real_name!=null && !real_name.equals("")'>
real_name=#{real_name,jdbcType=VARCHAR},
</if>
<if test='login_passwd!=null && !login_passwd.equals("")'>
login_passwd=#{login_passwd,jdbcType=VARCHAR},
</if>
<if test='telephone!=null && !telephone.equals("")'>
telephone=#{telephone,jdbcType=VARCHAR},
</if>
<if test='recommender_id!=null && !recommender_id.equals("")'>
recommender_id=#{recommender_id,jdbcType=INTEGER},
</if>
<if test='occupation!=null && !occupation.equals("")'>
occupation=#{occupation,jdbcType=VARCHAR},
</if>
<if test='mailaddress!=null && !mailaddress.equals("")'>
mailaddress=#{mailaddress,jdbcType=VARCHAR},
</if>
<if test='zipcode!=null && !zipcode.equals("")'>
zipcode=#{zipcode,jdbcType=VARCHAR},
</if>
<if test='qq!=null && !qq.equals("")'>
qq=#{qq,jdbcType=VARCHAR},
</if>
</set> where account_id=#{account_id}
</update>
void resetPwd(Map<String,Object> map);
<update id="resetPwd" parameterType="hashmap">
update admin_info_DSL set password=#{defaultPwd} where admin_id in
<foreach collection="pwdList"
item="pwd"
open="("
separator=","
close=")">
#{pwd}
</foreach>
</update>
查:
Cost findById(Integer id);
<select id="findById" parameterType="Integer" resultType="com.dsl.entity.Cost">
select * from cost_DSL where cost_id=#{id}
</select>
List<Account> findByPage(AccountPage page);
<select id="findByPage" parameterType="com.dsl.entity.page.AccountPage" resultType="com.dsl.entity.Account">
select * from(select a.*,row_number() over(order by account_id)p from account_DSL a
<where>
<if test='idcardNo!=null && !idcardNo.equals("")'>
and idcard_no=#{idcardNo}
</if>
<if test='realName!=null && !realName.equals("")'>
and real_name=#{realName}
</if>
<if test='loginName!=null && !loginName.equals("")'>
and login_name=#{loginName}
</if>
<if test='status!=null && !status.equals("") && !status.equals("-1")'>
and status=#{status}
</if>
</where>)where p between #{begin} and #{end}
</select>
List<Admin> findAdminByPage(AdminPage page);
<select id="findAdminByPage" parameterType="com.dsl.entity.page.AdminPage" resultMap="adminMap">
select * from(select a.*,row_number() over(order by admin_id)p from admin_info_DSL a
where admin_id in (
select ai.admin_id from admin_info_DSL ai
left join admin_role_DSL ar on ar.admin_id=ai.admin_id
left join role_info_DSL ri on ri.role_id=ar.role_id
left join role_module_DSL rm on rm.role_id=ri.role_id
left join module_info_DSL mi on mi.module_id=rm.module_id
<where>
<if test='roleName!=null&&!roleName.equals("")'>
and ri.name like '%'||#{roleName}||'%'
</if>
<if test="moduleId!=null">
and mi.module_id=#{moduleId}
</if>
</where>
)) where p between #{begin} and #{end}
</select>
<resultMap id="adminMap" type="com.dsl.entity.Admin">
<id column="admin_id" property="admin_id"/>
<collection select="findRoleByAdminId"
column="admin_id"
javaType="arraylist"
ofType="com.dsl.entity.Role"
property="roles">
</collection>
</resultMap>
<select id="findRoleByAdminId" parameterType="Integer" resultType="com.dsl.entity.Role">
select * from role_info_DSL where role_id in(select role_id from admin_role_DSL where admin_id=#{admin_id})
</select>
User selectByPrimaryKey(Integer id);
<resultMap id="BaseResultMap" type="com.cn.hnust.pojo.User" >
<id column="id" property="id" jdbcType="INTEGER" />
<result column="user_name" property="userName" jdbcType="VARCHAR" />
<result column="password" property="password" jdbcType="VARCHAR" />
<result column="age" property="age" jdbcType="INTEGER" />
</resultMap>
<sql id="Base_Column_List" >
id, user_name, password, age
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
<include refid="Base_Column_List" />
from user_t
where id = #{id,jdbcType=INTEGER}
</select>
转载于:https://my.oschina.net/dslcode/blog/1591219
myBaits SQL相关推荐
- 开发指南专题十四:JEECG微云快速开发平台MiniDao 介绍
开发指南专题十四:JEECG微云快速开发平台MiniDao 介绍 13.MiniDao 介绍 13.1. MiniDao简介及特征 MiniDao是Jeecg自己的持久化解决方案,具备了Hibern ...
- MiniDao持久层 Vs Mybatis
MiniDao简介及特征 MiniDao是Jeecg自己的持久化解决方案,集成Hibernate实体维护和Mybaits SQL分离的两大优点.具有以下特征 l O/R mapping不用设置xm ...
- MiniDao 比Mybatis还灵活实用的J2EE 持久层轻量级解决方案
MiniDao 详细地址:http://zhangdaiscott.github.io/MiniDao/ 源码下载地址:http://code.google.com/p/jeecg/downloads ...
- IntelliJ IDEA 插件推荐
1.GenerateAllSetter 自动生成类set方法 2.GsonFormat 根据JSON创建实体 3.Lombok plugin 简化代码 4. .ignore 忽略git提交文件 5.A ...
- java 必备面试必备
1.JDK 和 JRE 有什么区别? JDK(Java Development Kit),Java开发工具包 JRE(Java Runtime Environment),Java运行环境 JDK中包含 ...
- 40.MyBaits懒加载、一二级缓存、模糊查询、分页查询、动态SQL
MyBaits_Day04 第一节.作业 <!-- 对getAllCateAndGoods做实现--><select id="getAllCateAndGoods" ...
- mybaits的模糊查询_mybatis模糊查询防止SQL注入(很详细)
SQL注入,大家都不陌生,是一种常见的攻击方式.攻击者在界面的表单信息或URL上输入一些奇怪的SQL片段(例如"or '1'='1'"这样的语句),有可能入侵参数检验不足的应用程序 ...
- mybaits十四:使用if和where标签构建动态sql
<where>标签会在sql语句中加上 'where',并且会去掉'and'(使用where标签的话,and就要放在语句的前面,比如'and ename = #{ename}', 如果放在 ...
- Mybaits自定义SQL
最近有个同事要包装一个可以执行sql语句的功能用的是mybatis 最开始他想到的方案是拿到数据库连接再执行sql语句. 后来出了某些错误来问我,为了寻求比较快的解决方法于是我就试试了下下面的方法. ...
最新文章
- 工厂模式的python实现
- Errors occurred during the build. Errors running builder 'Validation' on pro
- 64位WINDOWS 使用PL SQL DEVELOPER 连接ORACLE 出错问题解决
- oracle asm 删除diskgroup,ASM磁盘组删除DISK操作
- 求C n m(从n个数中选m个数,有多少种组合?问题)暴力—递归——回归数学公式,三种方法,层层优化!
- AGC 019F.Yes or No(思路 组合)
- Layer 2 DAO 基础协议 Metis 上线 Alpha 测试网
- word把选择答案弄到题目里_怎样将word中后面的答案和题目合并到一起 - 卡饭网...
- linux 按序号创建文件夹,在Linux终端中创建M3U播放列表的方法
- 阿里云重磅推出物联网安全运营中心Link SOC 1
- JAVA 中文简体繁体转换
- 如何批量将 PPT 幻灯片文档转换为 XPS 格式
- Threejs3D模型爆炸效果
- 项目-1.CROSSFORMER论文与代码解析(CrossFormer: A Versatile Vision Transformer Based on Cross-scale Attention)
- golang下文件锁的使用
- 谷歌发现利用零日漏洞的攻击、黑客通过漏洞入侵红十字会|2月17日全球网络安全热点
- 火狐开发----Web开发者工具
- Mac单机多实例Mysql(8.0.16)主从配置
- login shell和non-login shell
- html5 video首次观看禁止快进,Video Speed Controller - 快进/后退/回看在线视频
热门文章
- 客户端JavaScript加密数据,服务端Java解密数据
- 如何启用漫游用户功能
- boost::timer
- .Net桌面程序的旗舰--参加亚控科技组态王7.0发布有感
- 使用 Artifactory 1分钟搭建 CocoaPod 私服
- Base64实现图片的编码和解码
- VMware vSphere 6.5 配置文档
- centos静态IP配置方法
- 揪出“凶手”——实战WinDbg分析电脑蓝屏原因
- Driver for device rausb0 has been compiled with version 22