温馨提示×

mybatisplus返回string的方法是什么

小亿
547
2023-10-30 10:26:03
栏目: 编程语言
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

MyBatis Plus返回String的方法有多种,取决于你想要在什么情况下使用。

  1. 使用selectOne()方法:可以通过selectOne()方法返回单个String对象。例如:
String result = mapper.selectOne(queryWrapper).toString();
  1. 使用selectList()方法:可以通过selectList()方法返回一个包含多个String对象的List。例如:
List<String> resultList = mapper.selectList(queryWrapper).stream().map(Object::toString).collect(Collectors.toList());
  1. 使用selectMaps()方法:可以通过selectMaps()方法返回一个包含多个String对象的List<Map<String, Object>>。例如:
List<Map<String, Object>> resultMapList = mapper.selectMaps(queryWrapper);
List<String> resultList = resultMapList.stream().map(map -> map.get("columnName").toString()).collect(Collectors.toList());

这些只是一些常见的用法示例,根据你的具体需求可能会有其他更适合的方法。

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读:mybatisplus多表联查的方法是什么

0