Java - @Param 参数过多

函数中参数数量超过7时,Sonar Lint会弹出警告。

Method has 8 parameters, which is greater than 7 authorized.

List<CellSearchDetail> getCellSearchResult(
    Integer tankId,
    @Param("rack") Integer rack,
    @Param("box") Integer box,
    @Param("locationStatus") String locationStatus,
    @Param("from") String from,
    @Param("to")String to,
    @Param("cellName") String cellName,
    @Param("projectId") String projectId
);

解决方案:

将参数封装在类中。

List<CellSearchDetail> getCellSearchResult(@Param("searchCell")CellSearchDTO searchCell);
@Data
public class CellSearchDTO {
    private Integer tankId;
    private Integer rack;
    private Integer box;
    private String locationStatus;
    private String from;
    private String to;
    private String cellName;
    private String projectId;
}

在Mapper.xml中通过test过滤null。

<select id="getCellSearchResult" resultMap="cellSearchDetailMap">
    select l.id, concat_ws("-", l.`tank_id`, l.`rack`, l.`box`, l.`row`, l.`column`) as position, l.location_status, c.cell_id, c.cell_name, c.project_id, c.cell_generation, c.freezing_by, c.freezing_date from location l
    left join cell c on l.cell_id = c.cell_id
    where l.tank_id = #{searchCell.tankId}
    <if test="searchCell.rack != null">
        and l.rack = #{searchCell.rack}
    </if>
    <if test="searchCell.box != null">
        and l.box = #{searchCell.box}
    </if>
    <if test="searchCell.locationStatus != null">
        and l.location_status = #{searchCell.locationStatus}
    </if>
    <if test="searchCell.from != null">
        and c.freezing_date &gt;= #{searchCell.from}
    </if>
    <if test="searchCell.to != null">
        and c.freezing_date &lt;= #{searchCell.to}
    </if>
    <if test="searchCell.cellName != null">
        and c.cell_name like CONCAT('%',#{searchCell.cellName},'%')
    </if>
    <if test="searchCell.projectId != null">
        and c.project_id like CONCAT('%',#{searchCell.projectId},'%')
    </if>
</select>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值