<select id="getdatatypeconfig" parameterType="java.util.HashMap" resultType="java.util.HashMap"> SELECT [datatypeconfig_colname] ,[datatypeconfig_strtype] ,[datatypeconfig_strlen] ,[datatypeconfig_strdecimal] ,[datatypeconfig_order] ,[datatypeconfig_remark] ,b.datavalue_colvalue AS datavalue FROM [JxBivAppUserDB].[dbo].[jxbivtob_settlement_datatypeconfig] a LEFT JOIN [JxBivAppUserDB].[dbo].[jxbivtob_settlement_datavalue] b ON a.datatype_id=b.datatype_id AND a.datatypeconfig_id=b.datatypeconfig_id WHERE b.datafile_id=(SELECT TOP (1) [datafile_id] FROM [JxBivAppUserDB].[dbo].[jxbivtob_settlement_datafile] WHERE datatype_id=9 ORDER BY datafile_id DESC) AND b.datatype_id=(SELECT TOP (1) datatype_id FROM [JxBivAppUserDB].[dbo].[jxbivtob_settlement_datafile] WHERE datatype_id=9 ORDER BY datafile_id DESC) </select> <insert id="insert_fundsettlementdays" parameterType="java.util.HashMap"> INSERT INTO [JxBivAppUserDB].[dbo].[jxbivtob_settlement_fundsettlementdays] (${columnNames}) VALUES (${columnValues}) </insert>public Map<String,Object> insert_fundsettlementdays(HttpServletRequest request, HttpServletResponse response){ response.setCharacterEncoding("UTF-8"); Map<String,Object> map =new HashMap<>(); List<HashMap> datatypeList=userDao.selectList("basessm.mapper.fundsettlementdays.getdatatypeconfig"); if (datatypeList == null || datatypeList.isEmpty()) { // 处理查询结果为空的情况 map.put("info", "No data available"); return map; } HashMap hashMap =new HashMap(); userDao.insert("basessm.mapper.fundsettlementdays.insert_fundsettlementdays",hashMap); map.put("info", "success"); return map; }根据我的SQL语句和方法来完成需求
时间: 2024-04-15 14:29:23 浏览: 127
根据你提供的代码和 SQL 语句,我做了一些修改和补充,以满足你的需求。请注意以下代码中的修改:
```xml
<!-- 在 mapper 文件中定义查询方法 -->
<select id="getDataTypeConfig" parameterType="java.lang.Integer" resultType="java.util.HashMap">
SELECT a.[datatypeconfig_colname] AS colName,
b.datavalue_colvalue AS colValue
FROM [JxBivAppUserDB].[dbo].[jxbivtob_settlement_datatypeconfig] a
LEFT JOIN [JxBivAppUserDB].[dbo].[jxbivtob_settlement_datavalue] b ON a.datatypeconfig_id = b.datatypeconfig_id
WHERE b.datafile_id = (SELECT TOP 1 [datafile_id] FROM [JxBivAppUserDB].[dbo].[jxbivtob_settlement_datafile] WHERE datatype_id = #{datatypeId} ORDER BY datafile_id DESC)
AND b.datatype_id = (SELECT TOP 1 datatype_id FROM [JxBivAppUserDB].[dbo].[jxbivtob_settlement_datafile] WHERE datatype_id = #{datatypeId} ORDER BY datafile_id DESC)
ORDER BY a.datatypeconfig_order ASC
</select>
<!-- 在 mapper 文件中定义插入方法 -->
<insert id="insert_fundsettlementdays" parameterType="java.util.Map">
INSERT INTO [JxBivAppUserDB].[dbo].[jxbivtob_settlement_fundsettlementdays] (${columnNames}) VALUES (${columnValues})
</insert>
```
在你的业务逻辑类中,可以按照以下方式调用上述方法:
```java
@Autowired
private DataInsertionMapper dataInsertionMapper;
public Map<String, Object> insertFundSettlementDays(HttpServletRequest request, HttpServletResponse response) {
response.setCharacterEncoding("UTF-8");
Map<String, Object> map = new HashMap<>();
// 调用查询方法获取数据
List<HashMap> datatypeList = dataInsertionMapper.getDataTypeConfig(9);
if (datatypeList == null || datatypeList.isEmpty()) {
// 处理查询结果为空的情况
map.put("info", "No data available");
return map;
}
// 构建插入的列名和对应的值
StringBuilder columnNames = new StringBuilder();
StringBuilder columnValues = new StringBuilder();
for (HashMap<String, Object> datatype : datatypeList) {
String colName = (String) datatype.get("colName");
String colValue = (String) datatype.get("colValue");
columnNames.append(colName).append(",");
columnValues.append("'").append(colValue).append("',");
}
columnNames.deleteCharAt(columnNames.length() - 1);
columnValues.deleteCharAt(columnValues.length() - 1);
// 构建参数并调用插入方法
Map<String, Object> paramMap = new HashMap<>();
paramMap.put("columnNames", columnNames.toString());
paramMap.put("columnValues", columnValues.toString());
dataInsertionMapper.insertFundSettlementDays(paramMap);
map.put("info", "success");
return map;
}
```
请根据你的具体需求进行进一步调整和修改。同时,确保在配置文件中正确设置数据源和相关配置信息。
阅读全文