1. 程式人生 > >mybatis報錯:Cause: java.sql.SQLException: Operand should contain 1 column(s)\n;

mybatis報錯:Cause: java.sql.SQLException: Operand should contain 1 column(s)\n;

mybatis配置:

<select id="queryDubboConfig" parameterType="map" resultMap="DubboConfigDO">
        SELECT
        (app_name, project_name, project_branch, interface_name, dubbo_app_name, dubbo_interface, dubbo_group,
        dubbo_version, dubbo_protocol, jar_group_id, jar_artifact_id, jar_version, dubbo_method_name, result_type,
        result_class, result_value_type, result_value)
        FROM `dubbo_configuration`
        <trim
prefix="WHERE" prefixOverrides="AND | OR">
<if test="null != projectName"> AND project_name = #{projectName} </if> <if test="null != projectBranch"> AND project_branch = #{projectBranch} </if> <if
test="null != interfaceName">
AND interface_name = #{interfaceName} </if> <if test="null != dubboAppName"> AND dubbo_app_name = #{dubboAppName} </if> <if test="null != dubboInterface"> AND dubbo_interface = #{dubboInterface} </if
>
<if test="null != jarGroupId"> AND jar_group_id = #{jarGroupId} </if> <if test="null != jarArtifactId"> AND jar_artifact_id = #{jarArtifactId} </if> <if test="null != jarArtifactId"> AND jar_version = #{jarVersion} </if> </trim> </select>

後來發現,把 select 到 from中間的查詢條件最外層的”()”就好了。
改成:

<select id="queryDubboConfig" parameterType="map" resultMap="DubboConfigDO">
        SELECT
        app_name, project_name, project_branch, interface_name, dubbo_app_name, dubbo_interface, dubbo_group,
        dubbo_version, dubbo_protocol, jar_group_id, jar_artifact_id, jar_version, dubbo_method_name, result_type,
        result_class, result_value_type, result_value
        FROM `dubbo_configuration`
        <trim prefix="WHERE" prefixOverrides="AND | OR">
            <if test="null != projectName">
                AND project_name = #{projectName}
            </if>
            <if test="null != projectBranch">
                AND project_branch = #{projectBranch}
            </if>
            <if test="null != interfaceName">
                AND interface_name = #{interfaceName}
            </if>
            <if test="null != dubboAppName">
                AND dubbo_app_name = #{dubboAppName}
            </if>
            <if test="null != dubboInterface">
                AND dubbo_interface = #{dubboInterface}
            </if>
            <if test="null != jarGroupId">
                AND jar_group_id = #{jarGroupId}
            </if>
            <if test="null != jarArtifactId">
                AND jar_artifact_id = #{jarArtifactId}
            </if>
            <if test="null != jarArtifactId">
                AND jar_version = #{jarVersion}
            </if>
        </trim>
    </select>