使用MapStruct出现了No property named "productId" exists in source parameter(s). Type "Product" has no properties.
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.的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- There is no getter for property named 'purchaseApplyId' in 'class java.lang.Long'
mapper.xml: <delete id="deleteByPurchaseAppyId" parameterType="Long"> < ...
- 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 ...
- 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 ...
- 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 ...
- 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' ...
- 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 ...
- mybaits错误解决:There is no getter for property named 'parentId ' in class 'java.lang.String'
在使用mybaitis传参数的时候,如果仅传入一个类型为String的参数,那么在 xml文件中应该使用_parameter来代替参数名. 比如mapper中如下方法,只有一个String值 publ ...
随机推荐
- 《数据结构-C语言》顺序表
@ 目录 顺序表 结构定义 初始化 创建表 求表长 判断表是否为空 取值 查找 插入 删除 逆置 清空 销毁 遍历打印 测试 顺序表 结构定义 #include <stdio.h> #in ...
- 谈一谈电商api的未来
随着互联网的飞速发展,电商行业已经成为了现代消费的主流模式.在电商平台上,商品的交易.物流.支付等环节都需要使用API(Application Programming Interface)接口来实现信 ...
- crontab定时任务不执行的一些原因总结
参考博文地址: https://www.jb51.net/article/154290.htm声明:本文章是在以上地址博文基础上进行整理学习,如有侵权,请联系博主删除,感谢知识共享,一起进步,加油鸭 ...
- 入门篇-其之一-第一个Java程序
️注意: 本文中包含实际操作,需要安装JDK.如果需要安装JDK,请按照这篇文章的步骤进行安装:点我查看JDK安装教程 小白可以多看几遍这篇文章,多敲几次代码 前面我们已经安装了JDK,接下来就是写一 ...
- 【爬虫实战】用python爬豆瓣电影《热烈》短评
目录 一.爬虫对象-豆瓣电影短评 二.爬取结果 三.爬虫代码讲解 三.演示视频 四.获取完整源码 一.爬虫对象-豆瓣电影短评 您好!我是@马哥python说,一名10年程序猿. 今天分享一期爬虫案例, ...
- KRPANO资源分析工具下载四方环视全景图
提示:目前分析工具中的全景图下载功能将被极速全景图下载大师替代,相比分析工具,极速全景图下载大师支持更多的网站(包括各类KRPano全景网站,和百度街景) 详细可以查看如下的链接: 极速全景图下载大师 ...
- 使用C#发送邮件支持 Implicit SSL
安装Package: Install-Package AIM 使用下面的代码发送: class Mail { private static string mailAddress = "{yo ...
- window操作系统安装多个版本nodejs版本-控制工具nvm
参考: https://blog.csdn.net/m0_38134431/article/details/118388297 https://juejin.cn/post/7044890876631 ...
- Springboot简单功能示例-1 实现基本WEB服务
springboot-sample 介绍 springboot简单示例 跳转到发行版 查看发行版说明 软件架构(当前发行版使用) springboot 安装教程 git clone --branch ...
- http 500 错误
214 [Thu Sep 09 16:03:54.919334 2021] [:error] [pid 32045] [client 124.238.184.230:23796] script '/v ...