pom.xml

 <properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<mapstruct.version>1.5.3.Final</mapstruct.version>
</properties> <dependencies>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>${mapstruct.version}</version>
</dependency> <dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${mapstruct.version}</version>
</dependency> <dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.24</version>
</dependency> <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
</dependency>
</dependencies>

entity

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Product {
private Integer id;
private String name;
private BigDecimal price;
}

vo

@Data
@NoArgsConstructor
@AllArgsConstructor
public class ProductVO {
private Integer productId;
private String productName;
private BigDecimal productPrice;
}

convert

package com.qbb.convert;

import com.qbb.entity.Product;
import com.qbb.vo.ProductVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers; /**
* @author QIUQIU&LL (个人博客:https://www.cnblogs.com/qbbit)
* @date 2022-11-14 20:42
* @tags 我爱的人在很远的地方, 我必须更加努力
*/
@Mapper
public interface ProductConvert {
ProductConvert convert = Mappers.getMapper(ProductConvert.class); @Mappings({
@Mapping(source = "id", target = "productId"),
@Mapping(source = "name", target = "productName"),
@Mapping(source = "price", target = "productPrice")
})
ProductVO toVO(Product product);
}

测试

@Test
public void test01(){
Product qiuqiu = new Product(1, "qiuqiu", new BigDecimal(9999));
ProductVO productVO = ProductConvert.convert.toVO(qiuqiu);
System.out.println("productVO = " + productVO);
}

解决办法

修改lombok的版本

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.10</version>
</dependency>

解决了

使用MapStruct出现了No property named "productId" exists in source parameter(s). Type "Product" has no properties.的更多相关文章

  1. There is no getter for property named 'useName' in 'class cn.itcast.mybatis.pojo.User'

    org.apache.ibatis.exceptions.PersistenceException: ### Error updating database.  Cause: org.apache.i ...

  2. mybatis There is no getter for property named 'xxxx

    mybatis There is no getter for property named 'xxxx 360反馈意见截图16230322799670.png http://blog.sina.com ...

  3. MyBatis查询传一个参数时报错:There is no getter for property named 'sleevetype' in 'class java.lang.Integer

    用MyBatis进行查询,传入参数只有一个时(非Map)如int,报错 There is no getter for property named 'sleevetype' in 'class jav ...

  4. There is no getter for property named 'purchaseApplyId' in 'class java.lang.Long'

    mapper.xml: <delete id="deleteByPurchaseAppyId" parameterType="Long"> < ...

  5. MyBatis3: There is no getter for property named 'code' in 'class java.lang.String'

    mybatis3  : mysql文如下,传入参数为string类型时‘preCode’,运行报错为:There is no getter for property named 'preCode' i ...

  6. mybatis There is no getter for property named 'xx' in 'class java.lang.String

    转载自://http://www.cnblogs.com/anee/p/3324140.html 用mybatis查询时,传入一个字符串传参数,且进行判断时,会报 There is no getter ...

  7. No object in the CompoundRoot has a publicly accessible property named

    No object in the CompoundRoot has a publicly accessible property named 'typeid' (no setter could be ...

  8. There is no getter for property named 'userSpAndSp' in 'class com.uauth.beans.UserSpAndSp'

    mybatis 报错There is no getter for property named 'userSpAndSp' in 'class com.uauth.beans.UserSpAndSp' ...

  9. There is no getter for property named 'userId' in 'class java.lang.String'

    [ERROR] 2017-01-18 04:37:06:231 cn.dataenergy.common.CenterHandlerExceptionResolver (CenterHandlerEx ...

  10. mybaits错误解决:There is no getter for property named 'parentId ' in class 'java.lang.String'

    在使用mybaitis传参数的时候,如果仅传入一个类型为String的参数,那么在 xml文件中应该使用_parameter来代替参数名. 比如mapper中如下方法,只有一个String值 publ ...

随机推荐

  1. What is TLS ?

    TLS intrduction TLS是一种保障数据传输安全的一种技术(方案),它在传输层工作. 想知道TLS和SSL的关系,先看看他们的历史: 人们遇到数据传输安全问题 1994 SSL 1.0 1 ...

  2. SqlServer修改表字段类型

    if not exists (select 1 from syscolumns where name='字段名' and id=OBJECT_ID('表名') and 条件) begin alter ...

  3. 企业级低代码平台,通用代码生成平台,Java开源项目(附源码)

    项目介绍 Jeecg-Boot 是一款基于代码生成器的智能开发平台!采用前后端分离架构:SpringBoot,Mybatis,Shiro,JWT,Vue&Ant Design.强大的代码生成器 ...

  4. sublime运行php文件

    sublime 运行 php 文件 使用 sublime 打开一个php文件 然后 Tools -> Build System -> New Build System 将以上打开的文件内容 ...

  5. 解密Linux中的通用块层:加速存储系统,提升系统性能

    通用块层 通用块层是Linux中的一个重要组件,用于管理不同块设备的统一接口,减少不同块设备的差异带来的影响.它位于文件系统和磁盘驱动之间,类似于Java中的适配器模式,让我们无需关注底层实现,只需提 ...

  6. JavaScript中的浅拷贝与深拷贝

    前言 JavaScript中的浅拷贝和深拷贝是非常重要的概念,它们在处理对象和数组时具有不同的作用.在编程中,经常需要复制数据以便进行各种操作,但必须注意拷贝的方式,以确保得到预期的结果. 浅拷贝是创 ...

  7. netstat命令输出详解

    netstat命令输出详解 1. 列出所有的TCP和UDP端口 2. 命令输出详解 Proto:协议名(tcp协议还是udp协议) recv-Q:网络接收队列,send-Q:网路发送队列 a. rec ...

  8. LocalDateTime、LocalDate、Date、String相互转化大全及其注意事项

    一.前言 大家在开发过程中必不可少的和日期打交道,对接别的系统时,时间日期格式不一致,每次都要转化! 每次写完就忘记了,小编专门来整理一篇来详细说一下他们四个的转换的方法,方便后面使用!! 二.Loc ...

  9. undefined reference to vtable for问题解决(QT)

    主要在运行时出现 原因是在自定义类使用信号与槽,在创建文件时,未继承QObject类并且没有添加Q_OBJECT: 解决: 在需要的类中,添加Q_OBJECT,继承QObject类. 然后使用QTCr ...

  10. Backgrounds

    有人私信要背景图,所以一起放出来了qwq 感觉这个博皮的动效选深色并且带点漂浮感的背景会比较好看(? 选图基本按这个标准选的,实际上比较亮的几张图已经被我手动拉低亮度了.(不过还是不太行/kk 备注里 ...