Skip to content

Mybaits-plus 默认开启 `m...

Updated: at 17:51

Mybaits-plus 默认开启 mapunderscoretocamelcase 驼峰命名规则映射。当 mapunderscoretocamelcasetrue ,java 类中的字段定义为小写下划线规则时,这个 java 类不能成功接收到 mybatis 查询的结果。比如:

<select id="getAlarmCountToday" resultType="com.example.demo.device.model.SomeResponse">
    SELECT
        SUM(IF(DATE(alarm_time) = CURRENT_DATE AND alarm_type = 'c_alms', 1, 0)) AS c_alms,
        SUM(IF(DATE(alarm_time) = CURRENT_DATE AND alarm_type = 'b_alms', 1, 0)) AS b_alms,
        SUM(IF(DATE(alarm_time) = CURRENT_DATE AND alarm_type = 'n_alms', 1, 0)) AS n_alms
    FROM device_alarm_record
    WHERE tenant_id = #{tenantId}
</select>
@Data
public SomeResponse {
    private String n_alms;
    private String c_alms;
    private String b_alms;
}