java查詢sql動態查詢需要的字段


方法一:使用“trim”標簽。

<select id="selTest" parameterType="mocha.framework.entiey.SnDocCountDef" resultMap="BaseResultMap">
  select 
      <trim suffixOverrides="," >
      <if test="bodefId != null" >
        bodef_id,
      </if>
      <if test="bodefName != null" >
        bodef_name,
      </if>
      <if test="bodefType != null" >
        bodef_type,
      </if>
      <if test="addTime != null" >
        add_time,
      </if>
      <if test="extend1 != null" >
        extend1,
      </if>
    </trim>
  from sn_doc_count_def
  </select>

此時,如果給“if”后面對應的參數傳入值,在查詢時 就會添加上對應的字段。

方法二:使用“${}”傳入參數。

<select id="selTest" parameterType="mocha.framework.entiey.SnDocCountDef" resultMap="BaseResultMap">
  select ${sql} from sn_doc_count_def
</select>

在${sql}處傳入需要查詢的字段,即可實現動態查詢字段的sql。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM