<select id="getDistinctPin1" resultType="String" parameterType="com.example.pmp.pojo.dto.sense.senseDataDto"> SELECT [FAI_26_1_Value] AS pin1 FROM [MESDataCenter].[dbo].[m_D8X_Main_Line3_01_M8_t] <include refid="distinctQuery"/> </select> <select id="getDistinctPin2" resultType="String" parameterType="com.example.pmp.pojo.dto.sense.senseDataDto"> SELECT [FAI_26_2_Value] AS pin2 FROM [MESDataCenter].[dbo].[m_D8X_Main_Line3_01_M8_t] <include refid="distinctQuery"/> </select> <select id="getDistinctPin3" resultType="String" parameterType="com.example.pmp.pojo.dto.sense.senseDataDto"> SELECT [FAI_26_3_Value] AS pin3 FROM [MESDataCenter].[dbo].[m_D8X_Main_Line3_01_M8_t] <include refid="distinctQuery"/> </select>优化mapper.xml中的这些代码
时间: 2024-04-15 08:27:03 浏览: 213
你可以通过使用动态SQL来优化这些代码。下面是一种可能的优化方式:
```xml
<!-- 定义一个可重用的SQL片段 -->
<sql id="distinctQuery">
SELECT DISTINCT ${column} AS value
FROM [MESDataCenter].[dbo].[m_D8X_Main_Line3_01_M8_t]
</sql>
<!-- 调用getDistinctPin1时,传递对应的列名 -->
<select id="getDistinctPin1" resultType="String" parameterType="com.example.pmp.pojo.dto.sense.senseDataDto">
<include refid="distinctQuery">
<property name="column" value="FAI_26_1_Value"/>
</include>
</select>
<!-- 调用getDistinctPin2时,传递对应的列名 -->
<select id="getDistinctPin2" resultType="String" parameterType="com.example.pmp.pojo.dto.sense.senseDataDto">
<include refid="distinctQuery">
<property name="column" value="FAI_26_2_Value"/>
</include>
</select>
<!-- 调用getDistinctPin3时,传递对应的列名 -->
<select id="getDistinctPin3" resultType="String" parameterType="com.example.pmp.pojo.dto.sense.senseDataDto">
<include refid="distinctQuery">
<property name="column" value="FAI_26_3_Value"/>
</include>
</select>
```
通过使用动态SQL和可重用的SQL片段,你可以避免代码的重复,并且通过设置不同的列名来获取不同的查询结果。这样可以更好地优化mapper.xml中的代码。
阅读全文