登录
首页 >  数据库 >  MySQL

Mybatis 鍔ㄦ€佹壒閲忎慨鏀?/a>

来源:SegmentFault

时间:2023-01-21 14:25:52 233浏览 收藏

亲爱的编程学习爱好者,如果你点开了这篇文章,说明你对《Mybatis 鍔ㄦ€佹壒閲忎慨鏀?/a>》很感兴趣。本篇文章就来给大家详细解析一下,主要介绍一下MySQL、Java、mybatis、鍚庣,希望所有认真读完的童鞋们,都有实质性的提高。

update document_answer set where document_id=#{documentId} and id=#{answer.id}

杩欐牱鍐欑殑璇濓紝鎴戜滑鐨刴apper灞傛帴鏀剁殑鍙傛暟锛屽簲璇ヤ负锛?/p>

int patchByDocumentId(@Param("documentId") Long documentId,@Param("answers") UpdateDocumentAnswer answers);

瀹炵幇鏄彲浠ュ疄鐜扮殑锛屼絾鏄洜涓洪渶瑕佹墽琛屽鏉pdate璇彞锛屾晥鐜囨槸鐪熺殑涓嶆暍鎭淮銆?/p>

濡傛灉澶у鏈夊皾璇曡繃锛岄兘浼氱煡閬擄紝for寰幆鎵цsql璇彞鏄湡鐨勮涓嶅緱鐨勩€備竴鏉℃櫘閫氱殑sql锛屾垜浠兘瑕佷紭鍖栧畬鍐嶄紭鍖栵紝鏇村埆璇翠竴涓柟娉曡鎵ц澶氭潯sql璇彞浜嗐€?/p>

鎵€鏈夊氨鍟ュ嫆锛燂紵

814268e3ly1fhlpr4j24rj20hs0840ts

鎺ㄨ崘澶у浣跨敤 鐧惧害銆丅ing銆丟oogle杩涜鎼滅储馃懆馃捇

鎴戜滑鎯冲埌杩囪繖绉嶉棶棰橈紝澶ф鐜囧埆浜轰篃浼氶亣涓婄殑锛屾悳涓€鎼滐紝纭疄鏈夌瓟妗堜綆銆?/p>

鎵€浠ユ垜浠帴鐫€杩涘叆鎬濊€冧簩鍚с€傪煆?/p>

鎬濊€冧簩锛?/h3>

杩樿寰楁枃绔犲墠闈㈡墍璇达細灏辨槸甯屾湜閫氳繃涓€鏉pdate璇彞锛屾牴鎹笉鍚岀殑鏉′欢鏀瑰彉澶氭潯闇€瑕佹敼鍙樼殑鏁版嵁銆?/p>

鎴戜滑鐩存帴 鎼滄€庝箞涓€鏉pdate鐢ㄤ笉鍚屾潯浠朵慨鏀瑰鏉℃暟鎹嫆

灏辨槸浼氭悳鍒颁竴涓笅闈㈢殑杩欐牱鐨剆ql璇彞銆?/p>

update 琛ㄥ悕 set 
鍒?=
    case
        when 鏉′欢1 then 鍊?
        when 鏉′欢2 then 鍊? end,
鍒?=
    case
        when 鏉′欢1 then 鍊?
        when 鏉′欢2 then 鍊? end,
where 鏉′欢

璇村疄璇濓紝鐪嬪埌杩欐潯璇彞鐨勯偅涓€鍒伙紝鎰熻鑷繁鍙堟病鏈夊杩噈ysql浜嗭紝杩瀋rud宸ョ▼甯堥兘绠椾笉涓婏紙鎹傝劯锛夈€?/p>

瑙i噴锛?/p>

鎴戜滑瑕?淇敼鍒?锛?褰搘hen 鏉′欢1 婊¤冻鏃讹紝鍒欏皢 鍒? 淇敼涓?then 鍚庨潰璺熺潃鐨?鍊?锛寃hen 鏉′欢2 婊¤冻锛屽垯灏嗗垪1淇敼涓簍hen 鍚庨潰璺熺潃鐨勫€?銆?/p>

杩欐牱涓€鏍凤紝鎴戜滑灏卞彲浠ユ墽琛屽鏉¤鍙ヤ簡鍟娿€?/p>

2.瀹炵幇

鎴戜滑灏嗕箣鍓嶇殑mapper灞傜殑鎺ュ彛浼犲叆鐨勫弬鏁板仛涓€涓嬫洿鏀广€?/p>

int patchByDocumentId(@Param("documentId") Long documentId,@Param("answers") List answers);

mapper.xml鐨勫疄鐜板涓嬶細


    update document_answer
    
                    when id=#{answer.id} then #{answer.templateQuestionId}
                
                    when id=#{answer.id} then #{answer.answer}
                
                    when id=#{answer.id} then #{answer.comments}
                
        document_id=#{documentId}
        
            and id in
            
                #{answer.id}
            

鐢熸垚鐨剆ql鏃ュ織

update document_answer 
SET 
template_question_id = 
    case 
        when id=? then ? 
        when id=? then ? end, 
answer = 
    case 
        when id=? then ? 
        when id=? then ? end, 
comments = 
    case 
        when id=? then ? 
        when id=? then ? end 
WHERE document_id=? and id in ( ? , ? )

鎹笂鎴戜滑鎯宠鐨勫€硷細

update document_answer 
SET 
template_question_id = 
    case 
        when id=1 then 2 
        when id=1 then 3 end, 
answer = 
    case 
        when id=1 then '鍐呭1' 
        when id=2 then '鍐呭2' end, 
comments = 
    case 
        when id=1 then '璇勮1' 
        when id=2 then '璇勮2' end 
WHERE document_id=2 and id in ( 1 , 2 )

鎵ц瑙勫垯锛?涓婇潰杩欑鏂瑰紡锛屾洿鏂扮殑璁板綍鐨勬暟閲忓彇鍐充簬list闆嗗悎鐨勬暟閲忥紝涓旀瘡鏉¤褰曚腑鐨勫€煎拰瀵瑰簲璁板綍鐨処D鏄竴涓€瀵瑰簲鐨勩€?/p>

缁撴潫浜嗭紝鍛ㄦ棩鏇存枃涓€绡囥€?/p>

鍚庤

鎴戜滑涓€璧峰姞娌瑰惂

浣犲ソ锛屾垜鏄崥涓?code>瀹佸湪鏄?/code>锛?a href="https://link.segmentfault.com/?enc=%2BUsIMbWgRAKPDWv3rYJYiw%3D%3D.lCZdRlkE02K1yC5SiDBeXoX39UZJkF7g2%2BkZBkSe1bTD2LqWWrAl5nS0Q%2Be2It3msMSHItoJ0bgSyYieK8%2BliQ%3D%3D" rel="nofollow">涓婚〉

甯屾湜鏈瘒鏂囩珷鑳借浣犳劅鍒版湁鎵€鏀惰幏锛侊紒锛?/p>

绁?鎴戜滑:寰呭埆鏃ョ浉瑙佹椂锛岄兘宸叉湁鎵€鎴?/code>銆?/p>

娆㈣繋澶у涓€璧疯璁洪棶棰橉煒侊紝韬轰簡馃泴

鐭ヤ箮 | 瀹佸湪鏄?/a>

绠€涔?| 瀹佸湪鏄?/a>

CSDN | 瀹佸湪鏄?/a>

鎺橀噾 | 瀹佸湪鏄?

鍗氬鍥?| 瀹佸湪鏄?/a>

以上就是《Mybatis 鍔ㄦ€佹壒閲忎慨鏀?/a>》的详细内容,更多关于mysql的资料请关注golang学习网公众号!

声明:本文转载于:SegmentFault 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>
评论列表