2018年9月7日

mybatis instr 字串 要串接 字串裡又有雙引號

<select id="selectLatestTemplateByVolume" parameterType="String" resultMap="ccpAsyncJobResultMap">
<bind name="jobCmdInfo" value="'volumeId&quot;:&quot;'+_parameter+'&quot;'" /><!-- volumeId":_parameter" -->
SELECT * FROM cloud.async_job
where instance_type='Template'
and job_cmd='org.apache.cloudstack.api.command.user.template.CreateTemplateCmd'
<![CDATA[ and instr(job_cmd_info,#{jobCmdInfo})>0 ]]>
order by id desc
limit 1
</select>


如果傳入是個map ( accountId=1, volumeUuid="123123123")
寫法又不太一樣


<select id="selectLatestTemplateByVolume" parameterType="Map" resultMap="ccpAsyncJobResultMap">
<bind name="jobCmdInfo" value="'volumeId&quot;:&quot;'+volumeUuid+'&quot;'" /><!-- volumeId":#{volumeUuid}" -->

SELECT * FROM cloud.async_job
where instance_type='Template'
and job_cmd='org.apache.cloudstack.api.command.user.template.CreateTemplateCmd'
<![CDATA[ and instr(job_cmd_info,#{jobCmdInfo})>0 ]]>
order by id desc
limit 1
</select>

沒有留言:

張貼留言