In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Editor to share with you the example analysis of strange events in MapStruct conversion into javaBean, I believe most people do not know much about it, so share this article for your reference, I hope you will gain a lot after reading this article, let's go to know it together!
MapStruct was used in the project, and I was particularly curious about its ability to convert JavaBean, because before, I used to use Vo to manually convert set, but when I came into contact with MapStruct, I felt that the previous way of using Vo was a bit low.
So I wanted to take a look and wrote a demo. So this weird time begins.
My code is as follows:
This is the pom file.
These are my two javaBean.
You can see the gray serialization interface because I ran it again and the converted JavaBean property was empty. I thought it was caused by serialization, so I removed it.
But it turns out that this is not the reason at all.
This is my mapper conversion class.
And my startup execution class.
The result of the correct operation should be like this
Now the result of my run is
This made me quite confused, so I checked a lot of bosses' blogs and said that adding "maven-compiler-plugin" configuration to pom would solve the problem, so I configured it.
As follows:
The gray one is to see that some bosses talk about such a configuration. Before, my maven-compiler-plugin was version 3.8, but it just made it the way it is now, but it still doesn't seem to be of any use.
After running, the property is empty, and I try maven-clean and maven-instell, and in a lot of my attempts, I suddenly find that after changing the method name of that transformation after install, the conversion can be successful, and the property has a value.
I looked at the execution process through debug. There was no set method generated in the implementation class of mapper before I did not change the method name, but after I changed it, I generated the set method, which is the direct reason why the property is null.
I have tried a lot of methods, read a lot of materials and did not understand why there is such a problem, distressed "ah!"
I changed this method after packing.
As long as you change this construction method, it can be realized.
The above is all the contents of the article "sample Analysis of strange events occurred when MapStruct converts javaBean". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.