[TOC]
依赖:
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.3.1</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>dynamic-datasource-spring-boot-starter</artifactId>
<version>3.3.1</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
实体类:
@Data
@EqualsAndHashCode(callSuper = true)
public class TblSnManage extends Model<TblSnManage> {
@TableId(type = IdType.AUTO)
private Long id;
private Long modelId;
private String model;
private String sn;
private Integer isAllot;
private Date createdAt;
private Date updatedAt;
}
Controller:
@PostMapping("test")
public R<List<TblSnManage>> testController() {
List<Long> idList = new ArrayList<>();
idList.add(1L);
idList.add(2L);
idList.add(3L);
idList.add(4L);
idList.add(5L);
idList.add(6L);
idList.add(7L);
idList.add(8L);
idList.add(9L);
int allot = 1;
List<TblSnManage> snList = tblSnManageService.getSnList(idList, allot);
return R.ok(snList);
}
Service:
public interface TblSnManageService extends IService<TblSnManage> {
List<TblSnManage> getSnList(List<Long> id, int allots);
}
Impl:
@Service("TblSnManageServiceImpl")
public class TblSnManageServiceImpl extends ServiceImpl<TblSnManageMapper, TblSnManage> implements TblSnManageService {
@Autowired
private TblSnManageMapper tblSnManageMapper;
@Override
public List<TblSnManage> getSnList(List<Long> id, int allots) {
return tblSnManageMapper.getSnList(id, allots);
}
}
Mapper(Dao):
@Mapper
public interface TblSnManageMapper extends BaseMapper<TblSnManage> {
@Select({
"<script>",
"select * from tbl_sn_manage",
"where is_allot = #{allot} and id in ",
"<foreach collection='ids' item='value' open='(' separator=',' close=')'>",
"#{value}",
"</foreach>",
"</script>"
})
List<TblSnManage> getSnList(@Param("ids") List<Long> ids, @Param("allot") int allots);
}
返回值:
{
"code": 0,
"data": [
{
"id": 4,
"modelId": 1,
"model": "model4",
"sn": "model4",
"isAllot": 1
},
{
"id": 6,
"modelId": 1,
"model": "model6",
"sn": "model6",
"isAllot": 1
}
],
"msg": "执行成功"
}
注意事项:
1.@Select注解里必须有
