var pat = patientInfo.Id_pat; Dictionary<string, object> param = new Dictionary<string, object>(); 将pat存入param中
时间: 2024-01-25 20:05:13 浏览: 70
好的,你想要将 `pat` 存入 `param` 字典中,我可以为你提供一些示例代码,请参考以下代码:
```csharp
var pat = patientInfo.Id_pat;
Dictionary<string, object> param = new Dictionary<string, object>();
param.Add("pat", pat);
```
这里我使用 `Add` 方法将 `pat` 存入了 `param` 字典中,你可以根据自己的实际需求进行修改。
相关问题
@Query(nativeQuery = true,value = "SELECT a.id , e.created_date FROM jg_bed a,jg_checkin_bed b ,jg_checkin c , jg_elder d, jg_checkout e WHERE a.id = b.bed_id and b.checkin_id = c.id and c.elder_id = d.id and d.id = e.elder_id and c.usage = ?1 and c.move_in_status =?2 and a.tenant_id = ?3 " + " <if test='queryData != null'> " + " and e.checkout_date between = #{queryData.bedCheckOutStartTime} and #{queryData.bedCheckOutEndTime}" + " and a.bed_status = #{queryData.bedStatus} " + "</if>") List<Map<String,String>>getCheckOutTimeAndBedId(String usage, String moveInStatusCheckOutDoing , String tenantId, @Param("queryData") QueryData queryData);有问题么 请改正
在这个查询语句中,使用了 MyBatis 的动态 SQL,但是 `<if>` 标签中的语句不完整,应该将 `between` 和 `=` 分开,并且 `=` 后面应该是 `#{queryData.bedCheckOutEndTime}` 而不是 `#{queryData.bedCheckOutStartTime}`。正确的语句应该是:
```
SELECT a.id, e.created_date
FROM jg_bed a, jg_checkin_bed b, jg_checkin c, jg_elder d, jg_checkout e
WHERE a.id = b.bed_id
AND b.checkin_id = c.id
AND c.elder_id = d.id
AND d.id = e.elder_id
AND c.usage = #{usage}
AND c.move_in_status = #{moveInStatusCheckOutDoing}
AND a.tenant_id = #{tenantId}
<if test='queryData != null'>
AND e.checkout_date BETWEEN #{queryData.bedCheckOutStartTime} AND #{queryData.bedCheckOutEndTime}
AND a.bed_status = #{queryData.bedStatus}
</if>
```
@Query(nativeQuery = true,value = "SELECT a.id , e.created_date FROM jg_bed a,jg_checkin_bed b ,jg_checkin c , jg_elder d, jg_checkout e WHERE a.id = b.bed_id and b.checkin_id = c.id and c.elder_id = d.id and d.id = e.elder_id and c.usage = ?1 and c.move_in_status =?2 and a.tenant_id = ?3 and ") List<Map<String,String>>getCheckOutTimeAndBedId(String usage, String moveInStatusCheckOutDoing , String tenantId, QueryData queryData); 如何动态拼接上queryData中的条件 有则查询,无则不查询
您可以使用动态SQL的方式来拼接上queryData中的条件,例如:
```java
@Query(nativeQuery = true, value = "SELECT a.id, e.created_date FROM jg_bed a, jg_checkin_bed b, jg_checkin c, jg_elder d, jg_checkout e " +
"WHERE a.id = b.bed_id AND b.checkin_id = c.id AND c.elder_id = d.id AND d.id = e.elder_id AND c.usage = ?1 AND c.move_in_status = ?2 " +
"AND a.tenant_id = ?3 " +
"<if test='queryData != null'> " +
"AND a.some_column = #{queryData.someValue} " +
"</if>")
List<Map<String, String>> getCheckOutTimeAndBedId(String usage, String moveInStatusCheckOutDoing, String tenantId, @Param("queryData") QueryData queryData);
```
在SQL语句中使用了`<if>`标签,如果`queryData`不为空,则会拼接上`AND a.some_column = #{queryData.someValue}`这个条件,否则不会拼接。其中,`queryData.someValue`是您要拼接的具体条件。另外,这里使用了MyBatis的方式来实现动态SQL,需要引入MyBatis相关依赖和配置文件。
阅读全文