![](/img/trans.png)
[英]How to update the table value field which type is bit using mybatis in mysql?
[英]how mybatis process Boolean field using mysql type tinyint?
我將 mysql 類型 tinyint(1) 用於 rabbitmqFlag 字段。但是,並非例外,實際上,值 -1 或 >0 將映射到 true.other 將映射到 false。 通常,我們認為 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 不處理數值。
它只返回ResultSet#getBoolean
的結果。
根據驅動源代碼注釋,是為了兼容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.