Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MySQL 字段类型是 tinyint(1) 却只能返回 0 / 1true / false 的原因与解决方法 #47

Open
troyzhxu opened this issue May 22, 2022 · 1 comment
Labels

Comments

@troyzhxu
Copy link
Owner

troyzhxu commented May 22, 2022

原因

这是因为 MySQL 会把 tinyint(1) 自动转为 bit 导致的。

1810e22875f30879e9ac602b9f97a00

参考:https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-reference-type-conversions.html

解决方案

只需在 MySQL 连接地址上加一个 tinyInt1isBit=false 参数即可,例如:

spring.datasource.url = jdbc:mysql://xxx/demo?tinyInt1isBit=false
@troyzhxu troyzhxu added the Q&A label May 22, 2022
@troyzhxu troyzhxu changed the title MySQL 字段类型是 tinyint(1) 却只能返回 0 / 1true / false MySQL 字段类型是 tinyint(1) 却只能返回 0 / 1true / false 的原因与解决方法 May 22, 2022
@troyzhxu
Copy link
Owner Author

troyzhxu commented Dec 7, 2022

或者,字段类型不要定义成 tinyint(1),直接定义成 tinyint

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant