mybatis 中in后面需要传一个参数的时候


    //club_payment_info取得項目
    List<ClubPaymentInfo> selectClubPaymentInfo(@Param("bankAccountNos") List<String> bankAccountNos);

    //club_group取得項目
    List<ClubGroup> selectClubGroup(@Param("bankAccountNos") List<String> bankAccountNos);

//    List<ClubPaymentHistory> selectInvoice();
 <select id="selectClubPaymentInfo" parameterType="List"
            resultType="com.sunflower.rm.web.domain.model.entity.ClubPaymentInfo">
        SELECT *
        FROM club_payment_info
        WHERE
        bank_account_no in
        <foreach item="item" index="index" collection="bankAccountNos" open="(" separator="," close=")">
            #{item}
        </foreach>

    </select>

    <select id="selectClubGroup" parameterType="List"
            resultType="com.sunflower.rm.web.domain.model.entity.ClubGroup">
        SELECT
       *
        FROM
        club_group
        WHERE
        bank_account_no in
        <foreach item="item" index="index" collection="bankAccountNos" open="(" separator="," close=")">
            #{item}
        </foreach>

    </select>

https://blog.csdn.net/qq_38157516/article/details/84036819

package com.sunflower.rm.web.domain.service;

import com.sunflower.rm.web.domain.mapper.RelateGolfCourseCodeMapper;
import com.sunflower.rm.web.domain.model.entity.ClubGroup;
import com.sunflower.rm.web.domain.model.entity.ClubPaymentHistory;
import com.sunflower.rm.web.domain.model.entity.ClubPaymentInfo;
import com.sunflower.rm.web.domain.model.request.N01_02_01_RelateGolfCourseCodeRequestDto;
import com.sunflower.rm.web.domain.model.response.N01_02_01_RelateGolfCourseCodeResponseDto;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;


@Service
public class RelateGolfCourseCodeService {

    @Resource
    private RelateGolfCourseCodeMapper relateGolfCourseCodeMapper;


    public ResponseEntity<N01_02_01_RelateGolfCourseCodeResponseDto> relateGolfCourseCode(N01_02_01_RelateGolfCourseCodeRequestDto n01_02_01_relateGolfCourseCodeRequestDto) {
        N01_02_01_RelateGolfCourseCodeResponseDto response = new N01_02_01_RelateGolfCourseCodeResponseDto();

        List<ClubPaymentHistory> clubPaymentHistories = relateGolfCourseCodeMapper.selectRelateGolfCourseCode(n01_02_01_relateGolfCourseCodeRequestDto);

        if (clubPaymentHistories.size()==0){
            response.setErrorCode("error.common.2002");
            return new ResponseEntity(response, HttpStatus.BAD_REQUEST);
        }

        List<String> bankAccountNos = clubPaymentHistories.stream()//口座番号List
                .map(item -> item.getBankAccountNo()).collect(Collectors.toList());
        //club
        List<ClubPaymentInfo> clubPaymentInfos  = relateGolfCourseCodeMapper.selectClubPaymentInfo(bankAccountNos);
        //group
        List<ClubGroup> clubGroupInfos  = relateGolfCourseCodeMapper.selectClubGroup(bankAccountNos);

        for (ClubPaymentHistory clubPaymentHistory: clubPaymentHistories) {
            List<ClubGroup> clubBankAccountNoList = clubGroupInfos.stream().filter(item->item.getBankAccountNo().equals(clubPaymentHistory.getBankAccountNo()) &&
                    item.getBankAccountName().equals(clubPaymentHistory.getBankAccountName()) &&
                    item.getBankName().equals(clubPaymentHistory.getBankName()) &&
                    item.getBankBranchName().equals(clubPaymentHistory.getBankBranchName())).collect(Collectors.toList());

            List<ClubPaymentInfo> BankAccountNoList = clubPaymentInfos.stream().filter(item->item.getBankAccountNo().equals(clubPaymentHistory.getBankAccountNo()) &&
                    item.getBankAccountName().equals(clubPaymentHistory.getBankAccountName()) &&
                    item.getBankName().equals(clubPaymentHistory.getBankName()) &&
                    item.getBankBranchName().equals(clubPaymentHistory.getBankBranchName())).collect(Collectors.toList());
            //group
            if(clubBankAccountNoList.size()>0){
                ClubGroup clubPaymentInfo = clubBankAccountNoList.get(0);
                clubPaymentHistory.setClubGroup(clubPaymentInfo.getClubGroupId());
                clubPaymentHistory.setClubGroupName(clubPaymentInfo.getClubGroupName());

            //club
            }else if(BankAccountNoList.size()>0){
                ClubPaymentInfo PaymentInfo = BankAccountNoList.get(0);
                clubPaymentHistory.setClubname(PaymentInfo.getClubname());
                clubPaymentHistory.setClubcode(PaymentInfo.getClubcode());
                List<ClubPaymentHistory> clubPayment = relateGolfCourseCodeMapper.selectClub(n01_02_01_relateGolfCourseCodeRequestDto);
                //判断状态  入金金额

            }
        }




        return new ResponseEntity(HttpStatus.OK);

    }

}
package com.sunflower.rm.web.domain.service;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sunflower.rm.web.domain.mapper.InitQuerySendMailBillOfPGMMapper;
import com.sunflower.rm.web.domain.model.base.BaseResponseDto;
import com.sunflower.rm.web.domain.model.base.Error;
import com.sunflower.rm.web.domain.model.request.R01_05_03_01_InitQuerySendMailBillOfPGMRequestDto;
import com.sunflower.rm.web.domain.model.response.R01_05_03_01_InitQuerySendMailBillOfPGMResponseDto;
import com.sunflower.rm.web.domain.model.response.R01_05_03_01_initQuerySendMailBillDetailOfPGMResponseDto;
import com.sunflower.rm.web.utils.StringUtil;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;

@Service
public class InitQuerySendMailBillOfPGMService {
    @Resource
    private InitQuerySendMailBillOfPGMMapper initQuerySendMailBillOfPGMMapper;

    public ResponseEntity initQuerySendMailBillOfPGMService(R01_05_03_01_InitQuerySendMailBillOfPGMRequestDto r01_05_03_01_initQuerySendMailBillOfPGMRequestDto) {
        BaseResponseDto response = new BaseResponseDto();
        //入力データがないの場合、エラーとする。
        if (StringUtil.isEmptyOrNull(r01_05_03_01_initQuerySendMailBillOfPGMRequestDto.getPaymentMonth())) {
            response.setError(new Error("warns.itemRequired"));
            return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST);
        }
        String paymentMonth = r01_05_03_01_initQuerySendMailBillOfPGMRequestDto.getPaymentMonth();
        List<R01_05_03_01_InitQuerySendMailBillOfPGMResponseDto> r01_05_03_01_InitQuerySendMailBillOfPGMResponseDtoList = initQuerySendMailBillOfPGMMapper.selectInitQuerySendMailBillOfPGM(paymentMonth);
        //取得データがないの場合、エラーとする
        if (r01_05_03_01_InitQuerySendMailBillOfPGMResponseDtoList.size() == 0) {
            response.setError(new Error("error.common.2002"));
            return new ResponseEntity(response, HttpStatus.OK);
        }
        List<R01_05_03_01_initQuerySendMailBillDetailOfPGMResponseDto> r01_05_03_01_InitQuerySendMailBillDetailOfPGMResponseDtoList = initQuerySendMailBillOfPGMMapper.selectRequestDetail(paymentMonth);

        for (R01_05_03_01_InitQuerySendMailBillOfPGMResponseDto dataInfo : r01_05_03_01_InitQuerySendMailBillOfPGMResponseDtoList) {
            List<R01_05_03_01_initQuerySendMailBillDetailOfPGMResponseDto> detailList = r01_05_03_01_InitQuerySendMailBillDetailOfPGMResponseDtoList.stream()
                    .filter(item -> item.getGroupId().equals(dataInfo.getGroupId())).collect(Collectors.toList());
            dataInfo.setDetailList(detailList);
        }
        return new ResponseEntity<>((new PageInfo<>(r01_05_03_01_InitQuerySendMailBillOfPGMResponseDtoList)), HttpStatus.OK);
    }

}

Mybatis plus使用in查询出错的问题可以有多种原因。根据引用\[1\]和引用\[2\]的内容,可能的原因之一是在使用QueryWrapper方法时,如果参数是String类型,Mybatis plus会默认在参数的前面和后面加上单引号。这可能导致查询出错,因为数据库的字段类型可能不是字符串类型,而加上单引号后会导致类型不匹配。 另外,根据引用\[3\]的内容,如果入的参数一个List或数组,需要使用collection属性来指定参数类型。如果入的是多个参数,可以将它们封装成一个Map,其collection属性的值为Map的key。 因此,解决Mybatis plus使用in查询出错的问题,可以尝试以下几个步骤: 1. 检查参数类型是否正确,如果是字符串类型,可以尝试去掉参数前后的单引号。 2. 如果参数一个List或数组,确保使用了collection属性来指定参数类型。 3. 如果入的是多个参数,尝试将它们封装成一个Map,并使用collection属性的值为Map的key。 希望以上解答对您有帮助。如果还有其他问题,请随时提问。 #### 引用[.reference_title] - *1* *2* [Mybatis plus使用in查询出错如何解决](https://blog.csdn.net/weixin_39588084/article/details/111790883)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [mybatis-plus 使用In查询](https://blog.csdn.net/fwdwqdwq/article/details/126463006)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

谛仙0

本人已实现,编写不易

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值