I called the stored procedure from XML. The result returned by the stored procedure contains special characters. The type received by XML is map. The result I got is incorrect. The "." in the figure below is split
Comment From: harawata
Hello @feng199464 ,
In MyBatis, dot is used describe nested objects.
You should use AS
in the query to assign an alias.
Closing as this is a duplicate of #13 .
Comment From: feng199464
你好@feng199464,
在 MyBatis 中,dot 用于描述嵌套对象。 您应该
AS
在查询中使用来分配别名。关闭,因为这是#13的副本。 I have used the as alias, but the field value will be converted to the field name display. The field name converted from the field value is dynamic, which I can't control
Comment From: harawata
I think you are now talking about mapping from HashMap
to JSON.
It has nothing to do with MyBatis.
Please elaborate if I misunderstood.
Comment From: feng199464
我认为您现在正在谈论从
HashMap
到 JSON 的映射。 它与 MyBatis 无关。 如果我误解了,请详细说明。 My problem is that the data format returned from mybatis to HashMap is incorrect
Comment From: harawata
Okay, then please create a small demo project like these and share it on your repository. I need it to understand your problem correctly.
Comment From: feng199464
Okay, then please create a small demo project like these and share it on your repository. I need it to understand your problem correctly.
CREATE TABLE mybatis_demo
(
id
int NOT NULL,
name
varchar(255) DEFAULT NULL,
age
int DEFAULT NULL,
PRIMARY KEY (id
)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO mybatis_demo
VALUES (1, 'dsad', 13);
https://github.com/feng199464/mybatisdemo.git
Comment From: harawata
Ah...you assign an alias that contains a dot. 😅 I cannot think of a good solution, then. You may have to assign a column alias that does not contain dot in the query and replace the map key afterwards.
Comment From: feng199464
Okay, then please create a small demo project like these and share it on your repository. I need it to understand your problem correctly.
CREATE TABLE
mybatis_demo
(id
int NOT NULL,name
varchar(255) DEFAULT NULL,age
int DEFAULT NULL, PRIMARY KEY (id
) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;INSERT INTO
mybatis_demo
VALUES (1, 'dsad', 13);https://github.com/feng199464/mybatisdemo.git
In mybatis, if the field alias has a decimal point, it cannot be resolved if it is returned to the map, but my current business needs to dynamically convert the field row value into field column display, for example:
ID | subject | score | name |
1 | english | 90 | lucy |
2 | math | 90 | lucy |
3 | math | 100 | jack |
4 | chinese | 85 | tom |
↓
↓
english | math | chinese | name
90 | 90 | 0 | lucy
0 | 100 | 0 | jack
0 | 0 | 85 | tom
I drew a watch
The above figure shows a row of scores for each user. Now I will dynamically convert the account name value into field display
The following figure shows the converted data
I can't restrict users from adding special characters "."
Comment From: feng199464
Ah...you assign an alias that contains a dot. 😅 I cannot think of a good solution, then. You may have to assign a column alias that does not contain dot in the query and replace the map key afterwards.
When users add data, they use the date as the name of the course. For example: 7.23 English class
Comment From: harawata
If you have no control over column aliases, there may be something wrong with your project's design. You should check if the query is vulnerable to SQL injection.
Anyway, MyBatis is working as designed.
Comment From: harawata
Duplicate of #13