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