广告
返回顶部
首页 > 资讯 > 后端开发 > Python >JPA如何将查询结果转换为DTO对象
  • 552
分享到

JPA如何将查询结果转换为DTO对象

JPA查询结果转换DTO对象JPA查询查询结果转DTO对象 2022-11-13 02:11:49 552人浏览 安东尼

Python 官方文档:入门教程 => 点击学习

摘要

目录前言例子Mysql数据库表联合查询的需求sql语句如何在JPA中映射为DTO对象例子涉及的部分源代码前言 JPA支持使用@Query自定义查询,查询的结果需要字节用DTO对象接收

前言

JPA支持使用@Query自定义查询,查询的结果需要字节用DTO对象接收,如果使用HQL的查询语句,可以将直接将DTO对象的构造方法传入hql中,直接转为DTO对象;而如果使用native sql查询的方式,只能将返回结果用Object[]对象接收,然后DTO设置对象的构造来接收Object[]里面的参数完成DTO对象的转换。

例子

mysql数据库

用户表

CREATE TABLE `pos_user` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `user_name` varchar(50) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
  `user_pwd` varchar(255) DEFAULT NULL,
  `user_type` int(11) DEFAULT NULL,
  `parent_id` bigint(20) DEFAULT NULL,
  `user_status` int(11) DEFAULT NULL,
  `distributor_id` bigint(20) DEFAULT NULL,
  `creator_identity_type` int(2) DEFAULT NULL,
  `creator_id` bigint(20) DEFAULT NULL,
  `create_date` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=22 DEFAULT CHARSET=utf8;

设备表

CREATE TABLE `pos_device` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `imei` varchar(120) NOT NULL,
  `Mac` varchar(120) NOT NULL,
  `unique_code` varchar(120) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
  `type` varchar(100) DEFAULT NULL,
  `system_version` varchar(100) DEFAULT NULL,
  `distributor_id` bigint(20) DEFAULT NULL,
  `creator_identity_type` int(2) DEFAULT NULL,
  `creator_id` bigint(20) DEFAULT NULL,
  `create_date` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=31 DEFAULT CHARSET=utf8;

用户和设备关联表

CREATE TABLE `pos_user_device_relation` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `device_id` bigint(20) DEFAULT NULL,
  `user_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8;

可以看到用户和设备关联表中有用户id和设备id

联合查询的需求

想列出pos_user_device_relation表中所有pos_user的distributor_id=1的所有用户和设备,要求返回的信息包括用户的username、type信息和设备的imei、mac等信息。

sql语句

SELECT
pdr.id,
pdr.device_id,
pd.imei,
pd.mac,
pd.unique_code,
pd.type,
pd.system_version,
pdr.user_id,
pu.user_name,
pu.user_type
FROM
pos_user_device_relation pdr, pos_user pu, pos_device pd
WHERE pdr.device_id = pd.id AND pdr.user_id = pu.id AND pdr.user_id in (select id from pos_user where distributor_id=1) limit 0,10

查询可以正常得到结果,结果行是这样的:

+----+-----------+---------------------+-------------------+--------------------------+----------+----------------+---------+---------------+-----------+
| id | device_id | imei                | mac               | unique_code              | type     | system_version | user_id | user_name     | user_type |
+----+-----------+---------------------+-------------------+--------------------------+----------+----------------+---------+---------------+-----------+

如何在JPA中映射为DTO对象

DTO对象字段定义如下:

private Long posUserDeviceId;
private Long deviceId;
private String deviceImei;
private String deviceMac;
private String deviceUniqueCode;
private String deviceType;
private String deviceSystemVersion;
private Long userId;
private String username;
private PosUserEntityConstants.UserType userType;

对象中的PosUserEntityConstants.UserType是一个自定义转换类型,通过继承AttributeConverter将Integer转换为UserType的枚举。

方法一:使用HQL的方法

Repository的查询代码如下:

@Query(
        value = "SELECT\n" +
                "new com.hengbao.ethiopiatelecomrecharge.dao.dto.PosUserDeviceRelationDto(\n" +
                "pdr.id,\n" +
                "pdr.deviceId,\n" +
                "pd.imei,\n" +
                "pd.mac,\n" +
                "pd.uniqueCode,\n" +
                "pd.type,\n" +
                "pd.systemVersion,\n" +
                "pdr.userId,\n" +
                "pu.userName,\n" +
                "pu.userType\n" +
                ") \n" +
                "FROM \n" +
                "PosUserDeviceRelationEntity pdr, PosUserEntity pu, PosDeviceEntity pd \n" +
                "WHERE pdr.deviceId = pd.id AND pdr.userId = pu.id AND pdr.userId in (select id from PosUserEntity where distributorId=?1)",
        countQuery = "SELECT count(*) FROM \n" +
                "PosUserDeviceRelationEntity pdr, PosUserEntity pu, PosDeviceEntity pd \n" +
                "WHERE pdr.deviceId = pd.id AND pdr.userId = pu.id AND pdr.userId in (select id from PosUserEntity where distributorId=?1)"
)
Page<PosUserDeviceRelationDto> findUserAndDeviceInfoByDistributorId(Long distributorId, Pageable pageable);

可以看到HQL的方法将PosUserDeviceRelationDto的构造器直接传入到HQL语句中,省去了我们自行转换的麻烦。那么PosUserDeviceRelationDto中也要重写一个相应的构造器:

由于项目中使用了lombok,所有最终dto的代码只是在类上面加上了一些注解,@AllArgsConstructor的注解会自动生成一个全参数的构造器,构造器的顺序和字段定义顺序一致,类代码如下:

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@ToString
public class PosUserDeviceRelationDto implements Serializable {
    
    private static final long serialVersionUID = 1L; 
    private Long posUserDeviceId; 
    private Long deviceId;
    private String deviceImei;
    private String deviceMac;
    private String deviceUniqueCode;
    private String deviceType;
    private String deviceSystemVersion; 
    private Long userId;
    private String username;
    private PosUserEntityConstants.UserType userType;
}

方法二:使用native query的方式查询并转换为dto

Repository的查询代码如下:

@Query(
        value = "SELECT\n" +
                "pdr.id,\n" +
                "pdr.device_id,\n" +
                "pd.imei,\n" +
                "pd.mac,\n" +
                "pd.unique_code,\n" +
                "pd.type,\n" +
                "pd.system_version,\n" +
                "pdr.user_id,\n" +
                "pu.user_name,\n" +
                "pu.user_type\n" +
                "FROM\n" +
                "pos_user_device_relation pdr, pos_user pu, pos_device pd\n" +
                "WHERE pdr.device_id = pd.id AND pdr.user_id = pu.id AND pdr.user_id in (select id from pos_user where distributor_id=?1)",
        countQuery = "SELECT count(*) FROM\n" +
                "pos_user_device_relation pdr, pos_user pu, pos_device pd\n" +
                "WHERE pdr.device_id = pd.id AND pdr.user_id = pu.id AND pdr.user_id in (select id from pos_user where distributor_id=?1)",
        nativeQuery = true
)
Page<Object[]> findUserAndDeviceInfoByDistributorId2(Long distributorId, Pageable pageable);

可以看到这样只能用Object[]来接收结果集,而不能直接将返回参数定义为PosUserDeviceRelationDto对象,否则会报no converter的异常。

那如何将Object[]的结果集转换为PosUserDeviceRelationDto对象呢?

首先先看一下Object[]每个对象的类型:BigInteger BigInteger String String String String String BigInteger String Integer

这是可以发现虽然mysql数据库定义的是bigint(20)类型,但是结果集是BigInteger,不能直接用Long接收,所以专门定义一个dto的构造器如下:

public PosUserDeviceRelationDto(BigInteger posUserDeviceId,
                                BigInteger deviceId,
                                String deviceImei,
                                String deviceMac,
                                String deviceUniqueCode,
                                String deviceType,
                                String deviceSystemVersion,
                                BigInteger userId,
                                String username,
                                Integer userType) {
    this.posUserDeviceId = posUserDeviceId == null ? null : posUserDeviceId.longValue();
    this.deviceId = deviceId == null ? null : deviceId.longValue();
    this.deviceImei = deviceImei;
    this.deviceMac = deviceMac;
    this.deviceUniqueCode = deviceUniqueCode;
    this.deviceType = deviceType;
    this.deviceSystemVersion = deviceSystemVersion;
    this.userId = userId == null ? null : userId.longValue();
    this.username = username;
    // UserTypeConverter是继承自javax.persistence.AttributeConverter的类型转换器
    this.userType = new PosUserEntityConstants.UserTypeConverter().convertToEntityAttribute(userType);
}

然后直接调用构造即可:

Page<Object[]> userAndDeviceInfoByDistributorId2 = posUserDeviceRelationRepository.findUserAndDeviceInfoByDistributorId2(1L, PageRequest.of(0, 10));
for (Object[] objects : userAndDeviceInfoByDistributorId2.getContent()) {
    // 转换成dto的方法一:将objects中的所有参数强转为对应类型,传递到dto的构造器中;dto对象定义好对应的构造器
    PosUserDeviceRelationDto dto1 = new PosUserDeviceRelationDto(
            (BigInteger) objects[0],
            (BigInteger) objects[1],
            (String    ) objects[2],
            (String    ) objects[3],
            (String    ) objects[4],
            (String    ) objects[5],
            (String    ) objects[6],
            (BigInteger) objects[7],
            (String    ) objects[8],
            (Integer   ) objects[9]);
    System.out.println(dto1);

网上还能搜到另外一种解决方法,就是通过反射的方法简化dto的转化步骤(https://www.jb51.net/article/238470.htm),但是这个存在bug,如果返回的objects数组中有一个值为null,那么getClass()方法获取类的类型就会报错,所以改为将每个参数的类型直接传入进去,可以这样使用反射其实省不了多少工夫了:

Page<Object[]> userAndDeviceInfoByDistributorId2 = posUserDeviceRelationRepository.findUserAndDeviceInfoByDistributorId2(1L, PageRequest.of(0, 10));
for (Object[] objects : userAndDeviceInfoByDistributorId2.getContent()) {
    // 转换成dto的方法二:反射的方法直接调用构造
    PosUserDeviceRelationDto dto2 = caseDto(objects, new Class[]{BigInteger.class,
                    BigInteger.class,
                    String.class,
                    String.class,
                    String.class,
                    String.class,
                    String.class,
                    BigInteger.class,
                    String.class,
                    Integer.class},
            PosUserDeviceRelationDto.class);
    System.out.println(dto2);
}

private <T> T caseDto(Object[] objectArray, Class[] objectClassArray, Class<T> dtoClass) throws Exception {
    Constructor<T> constructor = dtoClass.getConstructor(objectClassArray);
    return constructor.newInstance(objectArray);
}

例子涉及的部分源代码

Repository

@Query(
        value = "SELECT\n" +
                "new com.hengbao.ethiopiatelecomrecharge.dao.dto.PosUserDeviceRelationDto(\n" +
                "pdr.id,\n" +
                "pdr.deviceId,\n" +
                "pd.imei,\n" +
                "pd.mac,\n" +
                "pd.uniqueCode,\n" +
                "pd.type,\n" +
                "pd.systemVersion,\n" +
                "pdr.userId,\n" +
                "pu.userName,\n" +
                "pu.userType\n" +
                ") \n" +
                "FROM \n" +
                "PosUserDeviceRelationEntity pdr, PosUserEntity pu, PosDeviceEntity pd \n" +
                "WHERE pdr.deviceId = pd.id AND pdr.userId = pu.id AND pdr.userId in (select id from PosUserEntity where distributorId=?1)",
        countQuery = "SELECT count(*) FROM \n" +
                "PosUserDeviceRelationEntity pdr, PosUserEntity pu, PosDeviceEntity pd \n" +
                "WHERE pdr.deviceId = pd.id AND pdr.userId = pu.id AND pdr.userId in (select id from PosUserEntity where distributorId=?1)"
)
Page<PosUserDeviceRelationDto> findUserAndDeviceInfoByDistributorId(Long distributorId, Pageable pageable);
@Query(
        value = "SELECT\n" +
                "pdr.id,\n" +
                "pdr.device_id,\n" +
                "pd.imei,\n" +
                "pd.mac,\n" +
                "pd.unique_code,\n" +
                "pd.type,\n" +
                "pd.system_version,\n" +
                "pdr.user_id,\n" +
                "pu.user_name,\n" +
                "pu.user_type\n" +
                "FROM\n" +
                "pos_user_device_relation pdr, pos_user pu, pos_device pd\n" +
                "WHERE pdr.device_id = pd.id AND pdr.user_id = pu.id AND pdr.user_id in (select id from pos_user where distributor_id=?1)",
        countQuery = "SELECT count(*) FROM\n" +
                "pos_user_device_relation pdr, pos_user pu, pos_device pd\n" +
                "WHERE pdr.device_id = pd.id AND pdr.user_id = pu.id AND pdr.user_id in (select id from pos_user where distributor_id=?1)",
        nativeQuery = true
)
Page<Object[]> findUserAndDeviceInfoByDistributorId2(Long distributorId, Pageable pageable);

DTO类

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@ToString
public class PosUserDeviceRelationDto implements Serializable {
    
    private static final long serialVersionUID = 1L; 
    private Long posUserDeviceId; 
    private Long deviceId;
    private String deviceImei;
    private String deviceMac;
    private String deviceUniqueCode;
    private String deviceType;
    private String deviceSystemVersion; 
    private Long userId;
    private String username;
    private PosUserEntityConstants.UserType userType; 
    public PosUserDeviceRelationDto(BigInteger posUserDeviceId,
                                    BigInteger deviceId,
                                    String deviceImei,
                                    String deviceMac,
                                    String deviceUniqueCode,
                                    String deviceType,
                                    String deviceSystemVersion,
                                    BigInteger userId,
                                    String username,
                                    Integer userType) {
        this.posUserDeviceId = posUserDeviceId == null ? null : posUserDeviceId.longValue();
        this.deviceId = deviceId == null ? null : deviceId.longValue();
        this.deviceImei = deviceImei;
        this.deviceMac = deviceMac;
        this.deviceUniqueCode = deviceUniqueCode;
        this.deviceType = deviceType;
        this.deviceSystemVersion = deviceSystemVersion;
        this.userId = userId == null ? null : userId.longValue();
        this.username = username;
        // UserTypeConverter是继承自javax.persistence.AttributeConverter的类型转换器
        this.userType = new PosUserEntityConstants.UserTypeConverter().convertToEntityAttribute(userType);
    }
}

test测试类:

@Test
public void testFindUserAndDeviceInfoByDistributorId() throws Exception {
    System.out.println("-----------------hql query-----------------");
    Page<PosUserDeviceRelationDto> userAndDeviceInfoByDistributorId = posUserDeviceRelationRepository.findUserAndDeviceInfoByDistributorId(1L, PageRequest.of(0, 10)); 
    System.out.println("count=" + userAndDeviceInfoByDistributorId.getTotalElements());
    if(userAndDeviceInfoByDistributorId.getContent() != null) {
        for (PosUserDeviceRelationDto dto : userAndDeviceInfoByDistributorId.getContent()) {
            System.out.println(dto);
        }
    }
 
    System.out.println("-----------------native sql query-----------------");
    Page<Object[]> userAndDeviceInfoByDistributorId2 = posUserDeviceRelationRepository.findUserAndDeviceInfoByDistributorId2(1L, PageRequest.of(0, 10));
    System.out.println("count=" + userAndDeviceInfoByDistributorId2.getTotalElements());
    if(userAndDeviceInfoByDistributorId2.getContent() != null) {
        for (Object[] objects : userAndDeviceInfoByDistributorId2.getContent()) {
            for (Object obj : objects) {
                System.out.print(obj + "(" + (obj == null ? null : obj.getClass().getSimpleName()) + ") ");
            }
            System.out.println();  
        }
 
        // 转换为dto 方法一
        System.out.println("-----转换dto的第一种方法-----");
        for (Object[] objects : userAndDeviceInfoByDistributorId2.getContent()) {
            // 转换成dto的方法一:将objects中的所有参数强转为对应类型,传递到dto的构造器中;dto对象定义好对应的构造器
            PosUserDeviceRelationDto dto1 = new PosUserDeviceRelationDto(
                    (BigInteger) objects[0],
                    (BigInteger) objects[1],
                    (String    ) objects[2],
                    (String    ) objects[3],
                    (String    ) objects[4],
                    (String    ) objects[5],
                    (String    ) objects[6],
                    (BigInteger) objects[7],
                    (String    ) objects[8],
                    (Integer   ) objects[9]);
            System.out.println(dto1);
        }
 
        // 转换为dto 方法二
        System.out.println("-----转换dto的第二种方法-----");
        for (Object[] objects : userAndDeviceInfoByDistributorId2.getContent()) {
            // 转换成dto的方法二:反射的方法直接调用构造
            PosUserDeviceRelationDto dto2 = caseDto(objects, new Class[]{BigInteger.class,
                            BigInteger.class,
                            String.class,
                            String.class,
                            String.class,
                            String.class,
                            String.class,
                            BigInteger.class,
                            String.class,
                            Integer.class},
                    PosUserDeviceRelationDto.class);
            System.out.println(dto2);
        }
    }
}
 

private <T> T caseDto(Object[] objectArray, Class[] objectClassArray, Class<T> dtoClass) throws Exception {
    Constructor<T> constructor = dtoClass.getConstructor(objectClassArray);
    return constructor.newInstance(objectArray);
}

以上为个人经验,希望能给大家一个参考,也希望大家多多支持编程网。

--结束END--

本文标题: JPA如何将查询结果转换为DTO对象

本文链接: https://www.lsjlt.com/news/140142.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • JPA如何将查询结果转换为DTO对象
    目录前言例子mysql数据库表联合查询的需求sql语句如何在JPA中映射为DTO对象例子涉及的部分源代码前言 JPA支持使用@Query自定义查询,查询的结果需要字节用DTO对象接收...
    99+
    2022-11-13
    JPA查询结果 转换DTO对象 JPA查询 查询结果转DTO对象
  • JPA如何查询原生SQL转换VO对象方式
    小编给大家分享一下JPA如何查询原生SQL转换VO对象方式,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!JPA查询原生SQL转换VO对象 List<...
    99+
    2023-06-25
  • SqlServer中怎么将查询结果转换为XML和JSON
    这篇文章将为大家详细讲解有关SqlServer中怎么将查询结果转换为XML和JSON,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。1.查询结果转XMLDEC...
    99+
    2022-10-18
    sqlserver
  • SQL Server中怎么将查询结果转换为Json格式
    这篇文章主要讲解了“SQL Server中怎么将查询结果转换为Json格式”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“SQL Server中怎么将查询结果...
    99+
    2022-10-18
    sql server json
  • java如何将map转换为对象
    要将Map转换为对象,可以使用反射来实现。首先,创建一个空对象,然后遍历Map的键值对,通过反射设置对象的属性值。假设有一个Pers...
    99+
    2023-08-24
    java map
  • Mysql将查询结果集转换为JSON数据的实例代码
    Mysql将查询结果集转换为JSON数据 前言学生表学生成绩表查询单个学生各科成绩(转换为对象JSON串并用逗号拼接)将单个学生各科成绩转换为数组JSON串将数组串作为value并设...
    99+
    2022-11-12
    mysql结果集转换json数据 mysql查询结果集
  • nodejs如何将buffer转换为JSON对象
    本篇内容主要讲解“nodejs如何将buffer转换为JSON对象”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“nodejs如何将buffer转换为JSON对象...
    99+
    2022-10-19
    nodejs buffer json
  • Javascript如何将数组转换为对象
    这篇文章主要为大家展示了“Javascript如何将数组转换为对象”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“Javascript如何将数组转换为对象”这篇文章吧。将数组转换为对象如果要将数组...
    99+
    2023-06-17
  • JavaScript如何将arguments对象转换为数组
    小编给大家分享一下JavaScript如何将arguments对象转换为数组,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!将 arguments 对象转换为数组a...
    99+
    2023-06-27
  • 如何将json字符串转换为java对象
    如何将json字符串转换为java对象?针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。Java的特点有哪些Java的特点有哪些1.Java语言作为静态面向对象编程语言的代表,...
    99+
    2023-06-14
  • Java中如何将对象转换为二维码?
    二维码是一种常见的矩阵条形码,它可以存储大量信息并且易于扫描。在Java中,我们可以使用第三方库来将对象转换为二维码。 本文将介绍如何使用Zxing库来将对象转换为二维码,并提供相应的代码示例。 引入Zxing库 首先,我们需要在项目...
    99+
    2023-08-29
    二维码 对象 path
  • 如何将javascript对象转换为json字符串
    这篇文章将为大家详细讲解有关如何将javascript对象转换为json字符串,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。在javascript中,可以使用内置方法“JSON.stringify()”来...
    99+
    2023-06-14
  • php如何将数组转换为对象数组
    这篇文章主要介绍了php如何将数组转换为对象数组的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇php如何将数组转换为对象数组文章都会有所收获,下面我们一起来看看吧。方法一:强制类型转换$arr =&n...
    99+
    2023-07-06
  • php如何将数组转换为MySQL查询语句
    PHP是一种流行的服务器端编程语言,用于构建Web应用程序和动态网站。在PHP编程中,数组是一种重要的数据类型,用于存储和处理数据集。通常,我们可以使用PHP数组中的键值对来表示数据库表格中的行数据。但是,有时候我们需要将这些数组转化为My...
    99+
    2023-05-14
    php mysql
  • 在Java项目中如何将对象转换为String
    在Java项目中如何将对象转换为String?很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。Java中对象转换为String的常用方法:  方法一:String&...
    99+
    2023-05-31
    java string ava
  • OleDbDataReader查询出的结果如何转换成DataTable啊
    要将OleDbDataReader查询结果转换为DataTable,可以按照以下步骤进行操作:1. 创建一个空的DataTable对...
    99+
    2023-08-08
    OleDbDataReader
  • JavaScript如何将对象转换为字符串进行比较
    这篇文章主要介绍了JavaScript如何将对象转换为字符串进行比较,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。将对象转换为字符串进行比较...
    99+
    2022-10-19
    javascript
  • SpringBoot返回对象时,如何将Long类型转换为String
    目录SpringBoot返回对象将Long类型转换为String1.自定义ObjectMapper2.把MappingJackson2HttpMessageConverter3.定义...
    99+
    2022-11-13
    SpringBoot返回对象 Long类型转为String SpringBoot Long转String
  • PHP中如何将一个对象转换为一个数组
    在PHP中,将一个对象转换为数组是一个经常性的操作,因为数组是一个更方便地存储和处理数据的数据结构。本文将介绍PHP中如何将一个对象转换为一个数组。PHP中将一个对象转换为数组的方法非常简单,可以通过将对象强制转换为数组来实现。可以使用(a...
    99+
    2023-05-14
  • php如何将json字符串转换为数组和对象
    本篇内容介绍了“php如何将json字符串转换为数组和对象”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!Json字符串的格式在我们学习Jso...
    99+
    2023-07-05
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作