List<Map<String, Object>> mapCity = tbAllCityService.findCustom("select * from tb_All_City where PRO = 72 and name=#{p[0]}", new Object[]{tbUserInfo.getCity()}); json.fluentPut("cityInfo", tbAllCityService.findCustom("select * from tb_All_City where CITY = #{p[0]}", new Object[]{mapCity.get(0).get("SEQID")})); 改为list不要map并且取消findCustom
时间: 2024-04-11 15:26:31 浏览: 109
为了将查询的结果从Map转换为List,并且取消使用findCustom方法,你可以使用JdbcTemplate来执行SQL查询。具体操作如下:
首先,确保你已经引入了Spring的JdbcTemplate库。
然后,可以按照以下方式进行修改:
```java
List<Object> listCity = jdbcTemplate.queryForList("select * from tb_All_City where PRO = 72 and name=?", new Object[]{tbUserInfo.getCity()});
json.fluentPut("cityInfo", jdbcTemplate.queryForList("select * from tb_All_City where CITY = ?", new Object[]{listCity.get(0).get("SEQID")}));
```
这样,你将得到一个包含查询结果的List对象,并将其赋值给listCity变量。然后,将listCity中的第一个元素的"SEQID"值作为参数进行第二个查询,并将查询结果赋值给"cityInfo"键。注意,这里使用的是JdbcTemplate的queryForList方法,它会返回一个List<Map<String, Object>>对象,你可以根据需要进行类型转换。
相关问题
将 List<Map<String, Object>> mapCity = tbAllCityService.findCustom("select * from tb_All_City where PRO = 72 and name=#{p[0]}", new Object[]{tbUserInfo.getCity()}); json.fluentPut("cityInfo", tbAllCityService.findCustom("select * from tb_All_City where CITY = #{p[0]}", new Object[]{mapCity.get(0).get("SEQID")})); 改成和着代码一样的TbUserInfo parentUserInfo = new TbUserInfo(); parentUserInfo.setUsername(tbUserInfo.getParentId()); parentUserInfo.setPhone(DBCipherUtil.zwAddText(tbUserInfo.getPhone())); List<TbUserInfo> findListParentUserInfo = tbUserInfoService.findList(parentUserInfo); json.fluentPut("parentUserInfo", findListParentUserInfo.get(0));
根据你提供的代码示例,你想将以下代码改写成类似的形式:
```java
TbUserInfo parentUserInfo = new TbUserInfo();
parentUserInfo.setUsername(tbUserInfo.getParentId());
parentUserInfo.setPhone(DBCipherUtil.zwAddText(tbUserInfo.getPhone()));
List<TbUserInfo> findListParentUserInfo = tbUserInfoService.findList(parentUserInfo);
json.fluentPut("parentUserInfo", findListParentUserInfo.get(0));
```
你可以使用类似的方式来修改第一段代码:
```java
String cityName = tbUserInfo.getCity();
List<Map<String, Object>> mapCity = tbAllCityService.findCustom("select * from tb_All_City where PRO = 72 and name=#{p[0]}", new Object[]{cityName});
String seqId = (String) mapCity.get(0).get("SEQID");
TbAllCity cityInfo = tbAllCityService.findCustom("select * from tb_All_City where CITY = #{p[0]}", new Object[]{seqId});
json.fluentPut("cityInfo", cityInfo);
```
请注意,修改的代码是基于你提供的信息进行推测的,如果有任何错误,请根据实际情况进行调整。
阅读全文