首页 > 其他分享 >手写Mapper的映射文件(通用)

手写Mapper的映射文件(通用)

时间:2024-02-24 10:13:00浏览次数:30  
标签:Mapper 映射 title content video aid article 手写 id

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="cn.edu.neu.hello_mybatis.mapper.ArticleMapper">
<select id="selectArticle" resultType="article">
SELECT * FROM article where aid=#{aid}
</select>


<insert id="addArticle" parameterType="article">
insert into article values(null,#{title},#{content},#{titlepic},#{video})
</insert>

<insert id="addPK" parameterType="article" useGeneratedKeys="true" keyProperty="aid">
insert into article values(null,#{title},#{content},#{titlepic},#{video})
</insert>

<insert id="insertPKBack" parameterType="article">
<selectKey keyProperty="aid" resultType="int" order="AFTER">
select LAST_INSERT_ID()
</selectKey>
insert into article values(null,#{title},#{content},#{titlepic},#{video})
</insert>


<update id="update" parameterType="article">
update article set title=#{title},content=#{content} where aid=#{aid}
</update>

<delete id="delete" parameterType="int">
delete from article where aid=#{aid}
</delete>

<resultMap id="custResultMap" type="article">
<!-- property:需要映射到JavaBean 的属性名称。column:数据表的列名或者标签别名。 -->
<id property="id" column="id" />
<result property="custId" column="cid"/>
<result property="name" column="name"/>
</resultMap>

<select id="custResultMapList" resultMap="custResultMap">
select id, custid cid,name name,age age from customer
</select>


<sql id="articleColumns">
aid,title,content,titlepic,video
</sql>

<select id="getSql" resultType="article">
select
<include refid="articleColumns"/>
from article
</select>

<select id="getArticleAndComment" resultMap="articleWithComment">
SELECT a.*,c.cid c_id,c.content c_content,c.author
FROM article a,comment c
WHERE a.aid=c.aid AND a.aid = #{aid}
</select>
<resultMap id="articleWithComment" type="Article">
<id property="aid" column="aid" />
<result property="title" column="title" />
<result property="content" column="content" />
<collection property="commentList" ofType="Comment">
<id property="cid" column="c_id" />
<result property="content" column="c_content" />
<result property="author" column="author" />
</collection>
</resultMap>

 

第二种
<update id="update">
update sys_user
<set>
<if test="username != null">
username = #{username},
</if>
<!-- <if test="password != null">-->
<!-- password = #{password}-->
<!-- </if>-->
<if test="nickname != null">
nickname = #{nickname},
</if>
<if test="email != null">
email = #{email},
</if>
<if test="phone != null">
phone = #{phone},
</if>
<if test="address != null">
address = #{address}
</if>
</set>
<where>
id = #{id}
</where>
</update>
</mapper>

标签:Mapper,映射,title,content,video,aid,article,手写,id
From: https://www.cnblogs.com/stevenduxiang/p/18030799

相关文章

  • mybatis—mapper.xml里的多种写法举例
    mybatis—mapper.xml里的多种写法举例目录mybatis—mapper.xml里的多种写法举例向一个表里插入另一个表的一些数据并进行取舍需要查询的select后的字段如果有不少语句都一致的话可以考虑单独提出来更新删除in语句面对集合和字符串<trim>标签<choose>标签判断<when>、<other......
  • 在mapper.xml中编写sql规则和常见函数写法
    在mapper.xml中编写规则和常见函数写法目录在mapper.xml中编写规则和常见函数写法service传到mapper.xml常见查询语句的写法group_concatcasewhenelseendCOALESCEDUAL模糊查询写法关于where1=1xml中不能存在的特殊字符——特殊转义或<![CDATA[]]>sql编写的一些......
  • .netCore之Automapper映射封装
    1.Automapper解说Automapper是一个对象与对象的关系映射库,目的就是帮助你实现源类型到目标类型的对象之间的映射2.Automapper的封装A.中间件中添加注册点击查看代码//Automapper映射builder.Services.AddAutoMapper(typeof(AutoMapperConfigs));B.添加特性公共类获取......
  • LSTM使用MNIST手写数字识别实战的代码和心得
    RNN的架构除了RNN类中的模型不同,其他的构架与CNN类似,如果还没有阅读过CNN文章的可以点击下方链接进入:CNN使用MNIST手写数字识别实战的代码和心得LSTM(LongShort-TermMemory长短时记忆网络)虽然在MNIST手写数字识别方面不擅长,但是也可以进行使用,效果比CNN略显逊色对LSTM使用......
  • CNN使用MNIST手写数字识别实战的代码和心得
    CNN(ConvolutionalNeuralNetwork)卷积神经网络对于MNIST手写数字识别的实战代码和心得首先是对代码结构思路进行思路图展示,如下:参数和原理剖析:因为MNIST图片为长和宽相同的28像素,为黑白两色,所以图片的高度为1,为灰度通道。在传入的时候,我定义的BATCH_SIZE为512,所以具体的......
  • 23 - 集合与映射类型
    集合与映射类型集合类型(SetType)集合类型对象是由具有唯一性的可哈希对象所组成的无序多项集。由于集合类型是无序的,它并不记录元素位置或插入顺序,因此集合类型不支持索引、切片或其他序列类的操作。类型对应关键字构造函数是否可变是否可哈希setsetset()可......
  • RxJS中高阶映射操作符的全面讲解:switchMap, mergeMap, concatMap (and exhaustMap)
    原文链接:https://blog.angular-university.io/rxjs-higher-order-mapping/有一些在日常开发中常用的RxJS的操作符是高阶操作符:switchMap,mergeMap,concatMap,以及exhaustMap。举个例子,程序中大多数的网络请求都是通过以上某个操作符来完成的,所以为了能够写出几乎所有反应式编程,必须......
  • Mybatis---结果映射-自动映射
    https://mybatis.org/mybatis-3/zh_CN/sqlmap-xml.html#Auto-mapping 正如你在前面一节看到的,在简单的场景下,MyBatis可以为你自动映射查询结果。但如果遇到复杂的场景,你需要构建一个结果映射。但是在本节中,你将看到,你可以混合使用这两种策略。让我们深入了解一下自动映射是怎......
  • Python用GAN生成对抗性神经网络判别模型拟合多维数组、分类识别手写数字图像可视化
    全文链接:https://tecdat.cn/?p=33566原文出处:拓端数据部落公众号生成对抗网络(GAN)是一种神经网络,可以生成类似于人类产生的材料,如图像、音乐、语音或文本。最近我们被客户要求撰写关于GAN生成对抗性神经网络的研究报告,包括一些图形和统计输出。近年来,GAN一直是研究的热门话题。F......
  • 解决MyBatis Mapper 的XML文件SQL语句无法自动提示问题
    一、问题1.问题场景IDEA中MyBatis编写mapper的SQL语句的时候无法提示SQL和数据库2.问题描述无法正常方便的使用IDEA的提示功能,更准确无误的编写代码3.本解决方案优势亲测可用,一劳永逸(IDEA版本IntelliJIDEA2021.1.3 )目的在于对Mybatis的Mapper.XML中sql语句进行提示......