mybatis: MyBatis on Spring Boot 4.2.0 - annotation and XML mappers, result maps, dynamic SQL, PageHelper, @MybatisTest, seven real transcripts
Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b3obqqePfZ9m2Jk5Ub
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
fc8bc933d5
commit
8d8c28e2e5
@@ -0,0 +1,66 @@
|
||||
## service.page(none, pageNum=2, pageSize=10) -> PageHelper rewrote the query and added a count query
|
||||
==> Preparing: SELECT count(0) FROM product p
|
||||
==> Parameters:
|
||||
<== Total: 1
|
||||
==> Preparing: SELECT p.id, p.name, p.price, p.stock, p.active, p.category_id FROM product p ORDER BY p.id LIMIT ? OFFSET ?
|
||||
==> Parameters: 10(Integer), 10(Long)
|
||||
<== Total: 10
|
||||
pageNum=2 pageSize=10 size=10 total=45 pages=5
|
||||
hasPreviousPage=true hasNextPage=true
|
||||
ids on this page: [11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
|
||||
|
||||
## filter + sort + page: the dynamic SQL and the paging compose
|
||||
==> Preparing: SELECT count(0) FROM product p WHERE p.active = ? AND p.category_id IN (?)
|
||||
==> Parameters: true(Boolean), 2(Long)
|
||||
<== Total: 1
|
||||
==> Preparing: SELECT p.id, p.name, p.price, p.stock, p.active, p.category_id FROM product p WHERE p.active = ? AND p.category_id IN (?) ORDER BY p.price DESC, p.id LIMIT ?
|
||||
==> Parameters: true(Boolean), 2(Long), 5(Integer)
|
||||
<== Total: 5
|
||||
total=13 pages=3 ids: [43, 37, 34, 31, 28]
|
||||
|
||||
## last page and a page past the end (reasonable=false)
|
||||
page 5: size=5 hasNextPage=false
|
||||
page 9: size=0 total=45 list=Page{count=true, pageNum=9, pageSize=10, startRow=80, endRow=90, total=45, pages=5, reasonable=false, pageSizeZero=false}[]
|
||||
|
||||
## TRAP: startPage(1, 5), then an unrelated query, then the search you meant to page
|
||||
unrelated query:
|
||||
==> Preparing: SELECT count(0) FROM product p WHERE p.id IN (?)
|
||||
==> Parameters: 1(Long)
|
||||
<== Total: 1
|
||||
==> Preparing: SELECT p.id, p.name, p.price, p.stock, p.active, p.category_id FROM product p WHERE p.id IN ( ? ) ORDER BY p.id LIMIT ?
|
||||
==> Parameters: 1(Long), 5(Integer)
|
||||
<== Total: 1
|
||||
the search you meant to page:
|
||||
==> Preparing: SELECT p.id, p.name, p.price, p.stock, p.active, p.category_id FROM product p ORDER BY p.id
|
||||
==> Parameters:
|
||||
<== Total: 45
|
||||
rows returned by the search: 45 (expected 5)
|
||||
|
||||
## TRAP: startPage(1, 5) and no query afterwards
|
||||
ThreadLocal page still set on this thread: true (pageSize=5)
|
||||
next unrelated query on the same thread returned 5 rows instead of 7
|
||||
==> Preparing: SELECT count(0) FROM product p WHERE p.id IN (?, ?, ?, ?, ?, ?, ?)
|
||||
==> Parameters: 1(Long), 2(Long), 3(Long), 4(Long), 5(Long), 6(Long), 7(Long)
|
||||
<== Total: 1
|
||||
==> Preparing: SELECT p.id, p.name, p.price, p.stock, p.active, p.category_id FROM product p WHERE p.id IN ( ? , ? , ? , ? , ? , ? , ? ) ORDER BY p.id LIMIT ?
|
||||
==> Parameters: 1(Long), 2(Long), 3(Long), 4(Long), 5(Long), 6(Long), 7(Long), 5(Integer)
|
||||
<== Total: 5
|
||||
after PageHelper.clearPage(): ThreadLocal page = null
|
||||
|
||||
## RowBounds(offset=10, limit=5) with PageHelper on the classpath: PageHelper turns it into LIMIT/OFFSET
|
||||
==> Preparing: SELECT p.id, p.name, p.price, p.stock, p.active, p.category_id FROM product p ORDER BY p.id LIMIT ? OFFSET ?
|
||||
==> Parameters: 5(Integer), 10(Long)
|
||||
<== Total: 5
|
||||
ids returned: [11, 12, 13, 14, 15]
|
||||
|
||||
## hand-written LIMIT/OFFSET (no plugin)
|
||||
==> Preparing: SELECT p.id, p.name, p.price, p.stock, p.active, p.category_id FROM product p ORDER BY p.id LIMIT ? OFFSET ?
|
||||
==> Parameters: 5(Integer), 10(Integer)
|
||||
<== Total: 5
|
||||
ids returned: [11, 12, 13, 14, 15]
|
||||
|
||||
## the lambda form when something fails: is a page left parked on the thread?
|
||||
A) lambda throws before any query: caught boom
|
||||
ThreadLocal page afterwards: still set, pageSize=5
|
||||
B) query fails inside the lambda: caught BadSqlGrammarException
|
||||
ThreadLocal page afterwards: null
|
||||
Reference in New Issue
Block a user