動態SQL的sql標籤和foreach標籤

2022-09-19 20:54:12 字數 1636 閱讀 9319

title=#,

author=#,

update blog

where views=#

注意:使用sql片段主要是為了實現sql片段的復用,如果sql語句涉及到了多表查詢,就不建議使用sql片段。總的來說,sql片段適用於單錶查詢

//使用foreach查詢

listgetblogforeach(map map);

select * from blog

id=#

public void getblogforeach()

sqlsession.close();

}

pooleddatasource forcefully closed/removed all connections.

pooleddatasource forcefully closed/removed all connections.

pooleddatasource forcefully closed/removed all connections.

pooleddatasource forcefully closed/removed all connections.

opening jdbc connection

created connection 418958713.

setting autocommit to false on jdbc connection [com.mysql.jdbc.jdbc4connection@18f8cd79]

==> preparing: select * from blog where ( id=? or id=? )

==> parameters: 1(integer), 2(integer)

<== columns: id, title, author, create_time, views

<== row: 1, mybatis, 小落, 2022-01-26 15:45:58.0, 9999

<== row: 2, 微服務11, 小落11, 2022-01-26 15:45:58.0, 1000

<== total: 2

blog(id=1, title=mybatis, author=小落, createtime=wed jan 26 15:45:58 cst 2022, views=9999)

blog(id=2, title=微服務11, author=小落11, createtime=wed jan 26 15:45:58 cst 2022, views=1000)

resetting autocommit to true on jdbc connection [com.mysql.jdbc.jdbc4connection@18f8cd79]

closing jdbc connection [com.mysql.jdbc.jdbc4connection@18f8cd79]

returned connection 418958713 to pool.

Mybaits動態sql之sql標籤

使用sql標籤可以重複利用該標籤中的sql語句,需要與include標籤配合使用。舉乙個例子,重複利用id,name,age basesql id name,age sql query resulttype user parametertype user select refid basesql i...

MyBatis 動態sql標籤

findbyaccount parametertype com.lin.entity.account resulttype com.lin.entity.account select from account test id 0 id if test username null and userna...

動態SQL常用標籤

select from blog title and author preparing select from blog where title select from blog where author 這裡的and被自動去掉了 select from blog where title and a...