发布时间:2023-12-11 16:00
public interface UserMapper { List
@Service public class MapTest implements CommandLineRunner { @Autowired private UserMapper mapper; @Override public void run(String... args) throws Exception { List
import org.apache.ibatis.annotations.MapKey; public interface UserMapper { // 指定的key必须是唯一的,否则重复的重复map的key会覆盖,如果查询的字段中没有唯一值,可以通过rowno来指定 @MapKey(\"rowno\") Map> selectTestData2(); }
@Service public class MapTest implements CommandLineRunner { @Autowired private UserMapper mapper; @Override public void run(String... args) throws Exception { Map> mapData1 = mapper.selectTestData2(); System.out.println(mapData1); } }
import org.apache.ibatis.annotations.MapKey; public interface UserMapper { // 指定的key名称必须是User实体类中的属性 @MapKey(\"id\") MapselectTestData3(); }
@Service public class MapTest implements CommandLineRunner { @Autowired private UserMapper mapper; @Override public void run(String... args) throws Exception { MapmapData2 = mapper.selectTestData3(); Set > entries = mapData2.entrySet(); for (Map.Entry entry : entries) { User user = entry.getValue(); System.out.println(user); } } }
以上就是Mybatis返回Map数据方式示例的详细内容,更多关于Mybatis返回Map数据的资料请关注脚本之家其它相关文章!