Last active
December 30, 2021 13:18
-
-
Save jeffgbutler/5df477b4f72f5461a8cc32fb7cf4669b to your computer and use it in GitHub Desktop.
MyBatis Dynamic SQL Limit and Offset
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Select({ | |
"${selectStatement}", | |
"LIMIT #{parameters.limit} OFFSET #{parameters.offset}" | |
}) | |
@ResultMap("TLecturesResult") | |
List<TLectures> selectByExampleWithLimitAndOffset(SelectStatementProvider selectStatement); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void selectByExampleWithLimitAndOffset() throws JsonProcessingException { | |
SelectStatementProvider selectStatement = select(id, ispublish) | |
.from(TLecturesDynamicSqlSupport.TLectures) | |
.where(id, isEqualTo("id")) | |
.orderBy(ispublish.descending()) | |
.build() | |
.render(RenderingStrategy.MYBATIS3); | |
selectStatement.getParameters().put("limit", 1); | |
selectStatement.getParameters().put("offset", 1); | |
List<TLectures> tLectures = tLecturesMapper.selectByExampleWithLimitAndOffset(selectStatement); | |
tLectures.forEach( | |
(tLecture) -> { | |
try { | |
objectMapper.writeValueAsString(tLectures); | |
} catch (JsonProcessingException e) { | |
e.printStackTrace(); | |
} | |
} | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Turns out I really missed something. Sorry for taking your time.