1. 根据列表批量修改
| void secretKeySequence(@Param("list")List<IndustrialShareDto> list); |
| <update id="secretKeySequence"> |
| update cloud_industrial_set |
| set `index` = |
| case |
| <foreach collection="list" item="item"> |
| when id = |
| </foreach> |
| end |
| where id in( |
| <foreach collection="list" item="item" separator=","> |
| |
| </foreach> |
| ) |
| </update> |
2. 小于号的处理
| select username from t where id <![CDATA[ <= ]]> #{id} |
3. 大小写重复列的问题
出现在 3.0.5 版本独有的问题,当返回值是 resultType = java.util.Map
时,会有两个列
| <select id="findDataShowSet" resultType="java.util.Map"> |
| select sqltext,customid |
| from datashowset |
| where showname = #{showName} |
| order by id |
| offset 0 rows fetch next 1 rows only |
| </select> |

查找原因:FastResultSetHandler.loadMappedAndUnmappedColumnNames()
| protected void loadMappedAndUnmappedColumnNames(ResultSet rs, ResultMap resultMap, List<String> mappedColumnNames, List<String> unmappedColumnNames) throws SQLException { |
| mappedColumnNames.clear(); |
| unmappedColumnNames.clear(); |
| final ResultSetMetaData rsmd = rs.getMetaData(); |
| final int columnCount = rsmd.getColumnCount(); |
| final Set<String> mappedColumns = resultMap.getMappedColumns(); |
| for (int i = 1; i <= columnCount; i++) { |
| final String columnName = configuration.isUseColumnLabel() ? rsmd.getColumnLabel(i) : rsmd.getColumnName(i); |
| |
| final String upperColumnName = columnName.toUpperCase(Locale.ENGLISH); |
| |
| if (mappedColumns.contains(upperColumnName)) { |
| mappedColumnNames.add(upperColumnName); |
| mappedColumnNames.add(columnName); |
| } else { |
| unmappedColumnNames.add(upperColumnName); |
| unmappedColumnNames.add(columnName); |
| } |
| } |
| } |
要么换版本,要么手动去掉
| Set<String> upperKeys = new HashSet<>(); |
| dataList.forEach(map -> { |
| upperKeys.addAll(map.keySet()); |
| }); |
| dataList.forEach( |
| map -> { |
| for(String key : upperKeys){ |
| map.remove(key.toUpperCase(Locale.ENGLISH)); |
| } |
| } |
| ); |
4. 递归自连接
- 实体类
| @Data |
| @JsonInclude(JsonInclude.Include.NON_EMPTY) |
| public class Sect { |
| private Integer id; |
| @NotEmpty |
| private String name; |
| private String desc; |
| @NotEmpty |
| private Integer parentId; |
| |
| |
| private List<Sect> sectList; |
| } |
- Mapper 接口
| List<Sect> list(@Param("parentId") Integer parentId); |
正常的查询
- Mapper.xml
| <resultMap id="sectList" type="com.demo.dto.Sect"> |
| <id property="id" column="id"></id> |
| <result column="name" property="name"></result> |
| <result column="desc" property="desc"></result> |
| //select 属性,引用下一个自己,column 属性,将上一个查询的 id 作为参数继续查询 |
| <collection property="sectList" select="list" column="id"></collection> |
| </resultMap> |
| |
| <select id="list" resultMap="sectList"> |
| select * from sect where parent_id = |
| </select> |
- 调用 mapper
| @RequestMapping("/list") |
| public List<Sect> list(){ |
| return sectMapper.list(-1); |
| } |
| |
这里参数传顶级的 id
本文作者:Hi.PrimaryC
本文链接:https://www.cnblogs.com/cnff/p/18043546
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步