Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
邬吉朋
practical_train
Commits
0187724f
Commit
0187724f
authored
Sep 04, 2026
by
wujipeng
Browse files
bug修复
parent
d5eeb4b1
Changes
2
Show whitespace changes
Inline
Side-by-side
practical-business/src/main/resources/com/platform/business/mapper/StudentScoreMapper.xml
View file @
0187724f
...
...
@@ -100,7 +100,8 @@
AND COALESCE(peer.mark_flag, 0) = 1
AND peer.score IS NOT NULL
AND peer.score
>
es.score
) AS rank,
<!-- rank是MySQL 8.0窗口函数保留字,别名必须转义,否则分页查询会直接返回500。 -->
) AS `rank`,
(
SELECT COUNT(*)
FROM exam_student peer
...
...
@@ -159,7 +160,8 @@
AND COALESCE(peer.mark_flag, 0) = 1
AND peer.score IS NOT NULL
AND peer.score
>
es.score
) AS rank,
<!-- 与分页查询保持一致,避免打开单场成绩详情时再次触发保留字语法错误。 -->
) AS `rank`,
(
SELECT COUNT(*)
FROM exam_student peer
...
...
practical-business/src/test/java/com/platform/business/mapper/StudentLearningMapperXmlTest.java
View file @
0187724f
...
...
@@ -8,13 +8,19 @@ import org.junit.jupiter.api.Test;
import
java.io.ByteArrayOutputStream
;
import
java.io.InputStream
;
import
java.nio.charset.StandardCharsets
;
import
java.util.regex.Pattern
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertFalse
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertTrue
;
/** 解析两个学生专用Mapper,并约束成绩SQL兼容MySQL 5.7。 */
class
StudentLearningMapperXmlTest
{
/** 匹配没有使用反引号转义的rank别名,防止MySQL 8.0保留字兼容问题回归。 */
private
static
final
Pattern
UNQUOTED_RANK_ALIAS
=
Pattern
.
compile
(
"\\bas\\s+rank\\b"
,
Pattern
.
CASE_INSENSITIVE
);
@Test
void
studentExamMapperShouldRegisterOnlineExamStatements
()
throws
Exception
{
Configuration
configuration
=
parse
(
"com/platform/business/mapper/StudentExamCenterMapper.xml"
);
...
...
@@ -27,7 +33,7 @@ class StudentLearningMapperXmlTest {
}
@Test
void
studentScoreMapperShouldRegisterAggregationAnd
AvoidWindowFunctions
()
throws
Exception
{
void
studentScoreMapperShouldRegisterAggregationAnd
RemainMysqlCompatible
()
throws
Exception
{
String
resource
=
"com/platform/business/mapper/StudentScoreMapper.xml"
;
Configuration
configuration
=
parse
(
resource
);
assertTrue
(
configuration
.
hasStatement
(
...
...
@@ -41,6 +47,9 @@ class StudentLearningMapperXmlTest {
assertFalse
(
xml
.
contains
(
" over ("
));
assertFalse
(
xml
.
contains
(
"dense_rank("
));
assertFalse
(
xml
.
contains
(
"rank()"
));
assertFalse
(
UNQUOTED_RANK_ALIAS
.
matcher
(
xml
).
find
());
// 分页和详情都需要返回rank字段;两处必须保留转义后的别名,避免修复时遗漏任一路径。
assertEquals
(
2
,
xml
.
split
(
"as `rank`"
,
-
1
).
length
-
1
);
}
private
Configuration
parse
(
String
resource
)
throws
Exception
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment