最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

mybatis動態(tài)sql之新增與更新方式

 更新時間:2023年07月17日 09:55:10   作者:某猿蚊常叮  
這篇文章主要介紹了mybatis動態(tài)sql之新增與更新方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教

mybatis動態(tài)sql新增與更新

記錄一個簡單的mybatis動態(tài)sql例子

新增

<?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="org.ruiskey.mapper.UserMapper">
? ? <insert id="save">
? ? ? ? insert into user
? ? ? ? ? ? <trim prefix="(" suffix=")" suffixOverrides=",">
? ? ? ? ? ? ? ? <if test="id != null and id != ''">
? ? ? ? ? ? ? ? ? ? id,
? ? ? ? ? ? ? ? </if>
? ? ? ? ? ? ? ? <if test="username != null and username != ''">
? ? ? ? ? ? ? ? ? ? username,
? ? ? ? ? ? ? ? </if>
? ? ? ? ? ? ? ? <if test="password != null and password != ''">
? ? ? ? ? ? ? ? ? ? password,
? ? ? ? ? ? ? ? </if>
? ? ? ? ? ? ? ? <if test="nickname != null and nickname != ''">
? ? ? ? ? ? ? ? ? ? nickname,
? ? ? ? ? ? ? ? </if>
? ? ? ? ? ? ? ? <if test="email != null and email != ''">
? ? ? ? ? ? ? ? ? ? email,
? ? ? ? ? ? ? ? </if>
? ? ? ? ? ? ? ? <if test="phone != null and phone != ''">
? ? ? ? ? ? ? ? ? ? phone,
? ? ? ? ? ? ? ? </if>
? ? ? ? ? ? ? ? <if test="address != null and address != ''">
? ? ? ? ? ? ? ? ? ? address
? ? ? ? ? ? ? ? </if>
? ? ? ? ? ? </trim>
? ? ? ? ? ? <trim prefix="values (" suffix=")" suffixOverrides=",">
? ? ? ? ? ? ? ? <if test="id != null and id != ''">
? ? ? ? ? ? ? ? ? ? #{id},
? ? ? ? ? ? ? ? </if>
? ? ? ? ? ? ? ? <if test="username != null and username != ''">
? ? ? ? ? ? ? ? ? ? #{username},
? ? ? ? ? ? ? ? </if>
? ? ? ? ? ? ? ? <if test="password != null and password != ''">
? ? ? ? ? ? ? ? ? ? #{password},
? ? ? ? ? ? ? ? </if>
? ? ? ? ? ? ? ? <if test="nickname != null and nickname != ''">
? ? ? ? ? ? ? ? ? ? #{nickname},
? ? ? ? ? ? ? ? </if>
? ? ? ? ? ? ? ? <if test="email != null and email != ''">
? ? ? ? ? ? ? ? ? ? #{email},
? ? ? ? ? ? ? ? </if>
? ? ? ? ? ? ? ? <if test="phone != null and phone != ''">
? ? ? ? ? ? ? ? ? ? #{phone},
? ? ? ? ? ? ? ? </if>
? ? ? ? ? ? ? ? <if test="address != null and address != ''">
? ? ? ? ? ? ? ? ? ? #{address}
? ? ? ? ? ? ? ? </if>
? ? ? ? ? ? </trim>
? ? </insert>
</mapper>

更新

<update id="update">
? ? update user
? ? <set>
? ? ? ? <if test="username != null and username != ''">
? ? ? ? ? ? username = #{username}
? ? ? ? </if>
? ? ? ? <if test="password != null and password != ''">
? ? ? ? ? ? password = #{password}
? ? ? ? </if>
? ? ? ? <if test="nickname != null and nickname != ''">
? ? ? ? ? ? nickname = #{nickname}
? ? ? ? </if>
? ? ? ? <if test="email != null and email != ''">
? ? ? ? ? ? email = #{email}
? ? ? ? </if>
? ? ? ? <if test="phone != null and phone != ''">
? ? ? ? ? ? phone = #{phone}
? ? ? ? </if>
? ? ? ? <if test="address != null and address != ''">
? ? ? ? ? ? address = #{address}
? ? ? ? </if>
? ? </set>
? ? <where>
? ? ? ? id = #{id}
? ? </where>
</update>

mybatis動態(tài)SQL增刪改查

我們在對數(shù)據(jù)庫進行增刪改查的時候,很多時候我們并不確定我們要進行傳入的參數(shù)的個數(shù),種類以及是否為空。

此時我們就需要用到mybatis動態(tài)sql來對數(shù)據(jù)庫進行靈活的交互。

  • 步驟一:導(dǎo)入相關(guān)jar包,編寫連接數(shù)據(jù)庫的MybatisUtil工具類
  • 步驟二:在src下配置mybatis.xml配置文件。其中對數(shù)據(jù)庫連接,映射文件的加載進行配置。(簡寫配置可選)
  • 步驟三:建立實體類Student

  • 步驟四:增刪改查的方法以及映射文件StudentMapper.xml中配置的編寫。

添加數(shù)據(jù)

insert 對應(yīng)的映射文件中配置:

通過傳入數(shù)組參數(shù)刪除

deleteArray對應(yīng)的映射文件中配置:

通過傳入List集合參數(shù)進行刪除

deleteList 對應(yīng)的映射文件中配置:

更新數(shù)據(jù)

update 對應(yīng)的映射文件中配置:

神奇的是:

查找數(shù)據(jù)

findAll對應(yīng)的映射文件配置

總結(jié)

以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • Java多線程產(chǎn)生死鎖的必要條件

    Java多線程產(chǎn)生死鎖的必要條件

    今天小編就為大家分享一篇關(guān)于Java多線程產(chǎn)生死鎖的必要條件,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧
    2019-01-01
  • rabbitmq中routingkey的作用說明

    rabbitmq中routingkey的作用說明

    這篇文章主要介紹了rabbitmq中routingkey的作用說明,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-06-06
  • JAVA截取字符串的幾種常用方法

    JAVA截取字符串的幾種常用方法

    這篇文章主要給大家介紹了關(guān)于JAVA截取字符串的幾種常用方法, 在處理字符串的過程中有很多情況下會遇到需要截取字符串的情況,文中通過代碼介紹的非常詳細,需要的朋友可以參考下
    2023-09-09
  • SpringBoot集成Drools打造動態(tài)規(guī)則管理模板引擎

    SpringBoot集成Drools打造動態(tài)規(guī)則管理模板引擎

    本文詳解SpringBoot與Drools的整合方法,涵蓋依賴管理、規(guī)則文件編寫、KieService配置等,旨在通過規(guī)則引擎實現(xiàn)業(yè)務(wù)邏輯動態(tài)化管理,提升微服務(wù)應(yīng)用的靈活性、可維護性及快速部署能力,對SpringBoot Drools相關(guān)知識感興趣的朋友一起看看吧
    2025-07-07
  • springboot?ConfigurationProperties的綁定源碼示例解析

    springboot?ConfigurationProperties的綁定源碼示例解析

    這篇文章主要為大家介紹了springboot?ConfigurationProperties的綁定源碼示例解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-09-09
  • 淺談springboot之JoinPoint的getSignature方法

    淺談springboot之JoinPoint的getSignature方法

    這篇文章主要介紹了springboot之JoinPoint的getSignature方法,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-06-06
  • Spring?Boot中@Import三種使用方式實例詳解

    Spring?Boot中@Import三種使用方式實例詳解

    這篇文章主要介紹了Spring?Boot中@Import三種使用方式,主要有引入普通類,引入importSelector的實現(xiàn)類及引入importBeanDefinitionRegister的實現(xiàn)類,結(jié)合實例代碼給大家講解的非常詳細,需要的朋友可以參考下
    2022-11-11
  • PowerDesigner連接數(shù)據(jù)庫的實例詳解

    PowerDesigner連接數(shù)據(jù)庫的實例詳解

    這篇文章主要介紹了PowerDesigner連接數(shù)據(jù)庫的實例詳解的相關(guān)資料,如有疑問請留言或者到本站社區(qū)交流討論,需要的朋友可以參考下
    2017-10-10
  • springboot之@KafkaListener注解自動裝配流程分享

    springboot之@KafkaListener注解自動裝配流程分享

    @KafkaListener是Spring Kafka框架提供的注解,Spring Boot對其提供了原生支持,通過引入依賴并在配置文件中加入Kafka相關(guān)配置,可以觸發(fā)Kafka組件的自動狀態(tài),掃描@KafkaListener注解是Spring Boot自動裝配的一部分
    2026-01-01
  • 如何在Java中實現(xiàn)一個散列表

    如何在Java中實現(xiàn)一個散列表

    這篇文章主要介紹了如何在Java中實現(xiàn)一個散列表,建一個HashMap,以String類型為Key,Int類型為Value,下文具體的操作過程需要的小伙伴可以參考一下
    2022-04-04

最新評論

深圳市| 宜黄县| 沂水县| 鄂州市| 台湾省| 仁布县| 邵阳县| 潮州市| 明溪县| 柞水县| 咸阳市| 商城县| 会宁县| 盐津县| 乌兰县| 信宜市| 广昌县| 德阳市| 弥渡县| 会泽县| 都江堰市| 松江区| 杭州市| 乐业县| 中山市| 礼泉县| 望江县| 垫江县| 漳平市| 通渭县| 化州市| 天水市| 盐城市| 大英县| 德保县| 高安市| 兴文县| 布尔津县| 全椒县| 和田县| 鄂伦春自治旗|