MyBatis で動的クエリを作成するときに、where 句で型ハンドラーを使用できますか?
ブール値を char に変換する必要があります。false は「N」に、true は「Y」に変換されます。列の値ストアは Y または N のいずれかです。
MyBatis で動的クエリを作成するときに、where 句で型ハンドラーを使用できますか?
ブール値を char に変換する必要があります。false は「N」に、true は「Y」に変換されます。列の値ストアは Y または N のいずれかです。
はい、MyBatis タイプハンドラーを使用できます
public class YesNoBooleanTypeHandler extends BaseTypeHandler<Boolean> {
    @Override
    public void setNonNullParameter(PreparedStatement ps, int i, Boolean parameter, JdbcType jdbcType)
            throws SQLException {
        ps.setString(i, convert(parameter));
    }
    @Override
    public Boolean getNullableResult(ResultSet rs, String columnName)
            throws SQLException {
        return convert(rs.getString(columnName));
    }
    @Override
    public Boolean getNullableResult(ResultSet rs, int columnIndex)
            throws SQLException {
        return convert(rs.getString(columnIndex));
    }
    @Override
    public Boolean getNullableResult(CallableStatement cs, int columnIndex)
            throws SQLException {
        return convert(cs.getString(columnIndex));
    }
    private String convert(Boolean b) {
        return b ? "Y" : "N";
    }
    private Boolean convert(String s) {
        return s.equals("Y");
    }
}
Mapper.xml where 句:
... WHERE your_bool = #{yourBool,typeHandler=YesNoBooleanTypeHandler} ...