首页 技术 正文
技术 2022年11月20日
0 收藏 966 点赞 4,915 浏览 1545 个字

转与拼接:

MyBatis 是支持普通 SQL查询,存储过程和高级映射的优秀持久层框架。MyBatis 消除了几乎所有的JDBC代码和参数的手工设置以及结果集的检索。MyBatis 使用简单的 XML或注解用于配置和原始映射,将接口和 Java 的POJOs(Plain Old Java Objects,普通的 Java对象)映射成数据库中的记录。

在mybatis的xml配置文件中,有时可以看到<![  CDATA[   ]  ]>  ,表示不应由xml解析器进行解析的文本数据,

  早在xml中”<,>,&”等 都是非法的,”<“在xml解析中表示新元素开始,

  加了cdata[],里面内容会被解析器忽略,

 在实际使用中,一般将符号替换

 &lt; < 小于
&gt; > 大于
&amp; & 和号
&apos; 省略号
&quot; 引号

例子

resultMap表示结果集是集合类型,
resultType是直接表示返回类型的(对应着我们的model对象中的实体),而resultMap则是对外部ResultMap的引用(提前定义了db和model之间的隐射key-->value关系),
但是resultType跟resultMap不能同时存在。
parameterType设置是参数类型
<select id="currentDateData" resultType="Procurement" >
select
<include refid="allColumn" />
from procurement
<where> <![CDATA[DATEDIFF(NOW(),createDate)<6 and DATEDIFF(NOW(),createDate)>0 ]]> </where>
order by refreshDatetime desc
</select>################
<resultMap id="UserResultMap" type="com.xixicat.domain.UserInfo">
<result property="id" column="id" />
<result property="username" column="username" />
<result property="sex" column="sex" />
</resultMap>
<select id="getUserInfoMap" resultMap="UserResultMap">
select id,username,sex from user_info
</select>##################################

trim标识为格式化标识,可以与其他标识完成where和set的功能

prefix  前缀增加   suffix  后缀增加    prefixOverrides 自动判断前置   suffixOverrides 自动判断后置

接着来测试一下,在user.xml中添加

<update id="updateUserTrim" parameterType="User">
UPDATE User 
      <trim prefix="SET" suffixOverrides="," suffix="WHERE id = #{id}" >  
    <if test="userName != null and userName != '' ">  
            userName = #{userName},
        </if>
        <if test="password != null and password != '' ">  
             password=#{password},
        </if>  
  </trim>
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,075
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,551
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,399
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,176
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,811
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,893