mybatis動態操作mysql資料庫

2021-09-26 07:35:26 字數 896 閱讀 3095

建立表

create table $ (

`$` $

not null auto_increment

default null

comment "$"

,primary key (`id`)

0">

,unique key `index_1` ($)

) engine=innodb default charset=utf8 comment= #;

刪除表

drop table $

清空表資料

truncate table $

插入資料

insert into $

$ values

#

根據唯一索引或者主鍵的資料來自動更新資料(唯一索引或者主鍵重複時,更新,不重複時插入)

insert into $

$ values

#

on duplicate key update

$=values($)

update $ set

$ = #

where

id = #

查詢資料

select * from $ 

where 1 = 1

0">

and

$ like concat('%',replace(replace(#,'%','/%'),'_','/_'),'%')

mybatis動態查詢

當我們需要查詢companylist 對應company表 但是資料又不僅僅只來自company表時,例如 我們還需要area表的省市區名稱時,可以這樣寫 會更優雅點 ps 個人覺得 1.companymodel 企業entity company對應的model 的定義 企業company表對應的m...

mybatis 動態排序

mybatis動態排序目前知道的方式有兩種 1.通過pagehelper com.github.pagehelper pagehelper 版本5.1.4 stringbuffer orderby new stringbuffer 欄位名稱 排序方式 pagehelper.startpage vo....

mybatis動態標籤

動態條件判斷 select from user where 1 1 and username 動態where select from user username 動態遍歷 select from user where id in 其中 標籤 類似於switch,按順序判斷 when 中的條件出否成立...