前言
最近在工作中需要使用到mybatis,需要实现某个功能。但是发现需要编写一个sql,但是mybatis的映射文件入参是List集合和Map<String,Integer>,需要循环List,然后通过List循环出来的值为Key获取Map中的值作为sql的入参,遇到了一些问题。但是经过不懈的努力,最后终于解决了这个问题。顺便分享一下自己的经验。
-
项目结构
-
pom文件配置
server:
port: 8379
spring:
datasource:
username: root
url: jdbc:mysql://localhost:3306/shop?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=UTC
driver-class-name: com.mysql.jdbc.Driver
mybatis:
mapper-locations: classpath:mapping/*Mapper.xml
type-aliases-package: com.example.bean
#showSql
logging:
level:
com:
example:
dao : debug
3 其他的业务代码
package com.example.bean;
import lombok.Data;
@Data
public class SysUser {
private Integer id;
private String username;
private String image;
}
package com.example.controller;
import com.example.bean.SysUser;
import com.example.service.SysUserService;
import org.springframework.beans.factory