[英]how mybatis process Boolean field using mysql type tinyint?
I use mysql type tinyint(1) for rabbitmqFlag field.BUT,not as excepted,actually,the value -1 or >0 will map to true.other will map to false.我将 mysql 类型 tinyint(1) 用于 rabbitmqFlag 字段。但是,并非例外,实际上,值 -1 或 >0 将映射到 true.other 将映射到 false。 Usually,we think 0 is false,other is true.Why?通常,我们认为 0 为假,其他为真。为什么?
@Data
public class User implements Serializable {
private Long id;
private String name;
private Integer age;
private Boolean rabbitmqFlag;
}
@Mapper
public interface UserMapper {
@Select("SELECT * FROM user1 WHERE rabbitmq_flag = 0")
List<User> findUnSend();
}
MyBatis does not process the numeric value. MyBatis 不处理数值。
It just returns the result of ResultSet#getBoolean
.它只返回ResultSet#getBoolean
的结果。
According to the driver's source code comment , it's for compatibility with the ODBC driver, etc..根据驱动源代码注释,是为了兼容ODBC驱动等。
public Boolean createFromLong(long l) {
// Goes back to ODBC driver compatibility, and VB/Automation Languages/COM, where in Windows "-1" can mean true as well.
return (l == -1 || l > 0);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.