当前位置:网站首页>idea plugin autofill setter

idea plugin autofill setter

2022-08-11 09:25:00 Brother wind

The protagonist I want to talk about today is stillbeancopy
The conversion and filling of properties in our daily development is a laborious thing,于是就有了beancopy这玩意,Although the development efficiency has been improved,And the code looks much cleaner,但是,Then came a series of uncontrollable problems:

  • 1、类型转换问题
  • 2、性能问题
  • 3、measpace溢出问题
    And these questions are very obscure,The test may not detect it either,You may not find out until the problem occurs.This leads to an increased risk of possible production problems.
    血淋淋的教训:
    【BeanCopy血案1】
    【BeanCopy血案2】
    These are just two of the bloody cases I've encountered,Regarding the type conversion problem,In most cases, you may consciously avoid it,But the problem with generic erasure may not be so easy to spot.

再回到BeanCopyin terms of performance,不管你是用MapStruct ,Cacheless reflection,There are cached reflections,还是使用asm技术,Performance is still relatively straightforwardset来的差100倍不止,以下是测试结果
reflect time:1242
cglib time:331
directSet time:3
There should be exclamations here,天啦,Is it that much?Of course this is just a test result,For multiple executions,It will indeed be reduced to only a few times the difference.But this does not affect directlyset的高性能.
Then look at the test data,这么多属性,You asked me to do it one by one by handset,不可能,Something that can be solved with a single line of code,You have to write so much,I only have to do this all day,What should I do if I accidentally write a wrong line?
So the next step is to think about whether there is such a plugin,Can you help me autofill properties,恭喜你,思路是对的,接下来可以去idea插件中心搜索 GenAllSetter插件,After the installation is complete, you can directly generate and populate all attributes in one piece.
快捷键Alt+insert
Three generation methods

  • Generate All Setter
  • Generate with Default value
  • Generate with getter
    可以自己尝试下,Just know what to do.

测试数据:

public static void main(String[] args) {
    
  
        reflect();
        cglib();
        directSet();
  
    }
    
    public static void reflect() {
    
        long start = System.currentTimeMillis();
        Product product=new Product();
        ProductVO productVO = new ProductVO();
        BeanUtils.copyProperties(product,productVO);
        long end = System.currentTimeMillis();
        System.out.println("reflect time:"+(end-start));
    }
    
    public static void cglib(){
    
        long start = System.currentTimeMillis();
        Product product = new Product();
        ProductVO productVO = new ProductVO();
        BeanCopier beanCopier = BeanCopier.create(Product.class, ProductVO.class, false);
        beanCopier.copy(product,productVO,null);
        long end = System.currentTimeMillis();
        System.out.println("cglib time:"+(end-start));
    }
    
    public static void directSet(){
    
        long start = System.currentTimeMillis();
        ProductVO productVO = new ProductVO();
        Product product = new Product();
        product.setField1(productVO.getField1());
        product.setField2(productVO.getField2());
        product.setField3(productVO.getField3());
        product.setField4(productVO.getField4());
        product.setField5(productVO.getField5());
        product.setField6(productVO.getField6());
        product.setField7(productVO.getField7());
        product.setField8(productVO.getField8());
        product.setField9(productVO.getField9());
        product.setField10(productVO.getField10());
        product.setField11(productVO.getField11());
        product.setField12(productVO.getField12());
        product.setField13(productVO.getField13());
        product.setField14(productVO.getField14());
        product.setField15(productVO.getField15());
        product.setField16(productVO.getField16());
        product.setField17(productVO.getField17());
        product.setField18(productVO.getField18());
        product.setField19(productVO.getField19());
        product.setField20(productVO.getField20());
        product.setField21(productVO.getField21());
        product.setField22(productVO.getField22());
        product.setField23(productVO.getField23());
        product.setField24(productVO.getField24());
        product.setField25(productVO.getField25());
        product.setField26(productVO.getField26());
        product.setField27(productVO.getField27());
        product.setField28(productVO.getField28());
        product.setField29(productVO.getField29());
        product.setField30(productVO.getField30());
        product.setField31(productVO.getField31());
        product.setField32(productVO.getField32());
        product.setField33(productVO.getField33());
        product.setField34(productVO.getField34());
        product.setField35(productVO.getField35());
        product.setField36(productVO.getField36());
        product.setField37(productVO.getField37());
        product.setField38(productVO.getField38());
        product.setField39(productVO.getField39());
        product.setField40(productVO.getField40());
        product.setField41(productVO.getField41());
        product.setField42(productVO.getField42());
        product.setField43(productVO.getField43());
        product.setField44(productVO.getField44());
        product.setField45(productVO.getField45());
        product.setField46(productVO.getField46());
        product.setField47(productVO.getField47());
        product.setField48(productVO.getField48());
        product.setField49(productVO.getField49());
        product.setField50(productVO.getField50());
        product.setField51(productVO.getField51());
        product.setField52(productVO.getField52());
        product.setField53(productVO.getField53());
        product.setField54(productVO.getField54());
        product.setField55(productVO.getField55());
        product.setField56(productVO.getField56());
        product.setField57(productVO.getField57());
        product.setField58(productVO.getField58());
        product.setField59(productVO.getField59());
        product.setField60(productVO.getField60());
        product.setField61(productVO.getField61());
        product.setField62(productVO.getField62());
        product.setField63(productVO.getField63());
        product.setField64(productVO.getField64());
        product.setField65(productVO.getField65());
        product.setField66(productVO.getField66());
        product.setField67(productVO.getField67());
        product.setField68(productVO.getField68());
        product.setField69(productVO.getField69());
        product.setField70(productVO.getField70());
        product.setField71(productVO.getField71());
        product.setField72(productVO.getField72());
        product.setField73(productVO.getField73());
        product.setField74(productVO.getField74());
        product.setField75(productVO.getField75());
        product.setField76(productVO.getField76());
        product.setField77(productVO.getField77());
        product.setField78(productVO.getField78());
        product.setField79(productVO.getField79());
        product.setField80(productVO.getField80());
        product.setField81(productVO.getField81());
        product.setField82(productVO.getField82());
        product.setField83(productVO.getField83());
        product.setField84(productVO.getField84());
        product.setField85(productVO.getField85());
        product.setField86(productVO.getField86());
        product.setField87(productVO.getField87());
        product.setField88(productVO.getField88());
        product.setField89(productVO.getField89());
        product.setField90(productVO.getField90());
        product.setField91(productVO.getField91());
        product.setField92(productVO.getField92());
        product.setField93(productVO.getField93());
        product.setField94(productVO.getField94());
        product.setField95(productVO.getField95());
        product.setField96(productVO.getField96());
        product.setField97(productVO.getField97());
        product.setField98(productVO.getField98());
        product.setField99(productVO.getField99());
        product.setField100(productVO.getField100());
        product.setField101(productVO.getField101());
        product.setField102(productVO.getField102());
        product.setField103(productVO.getField103());
        product.setField104(productVO.getField104());
        product.setField105(productVO.getField105());
        product.setField106(productVO.getField106());
        product.setField107(productVO.getField107());
        product.setField108(productVO.getField108());
        product.setField109(productVO.getField109());
        product.setField110(productVO.getField110());
        product.setField111(productVO.getField111());
        product.setField112(productVO.getField112());
        product.setField113(productVO.getField113());
        product.setField114(productVO.getField114());
        product.setField115(productVO.getField115());
        product.setField116(productVO.getField116());
        product.setField117(productVO.getField117());
        product.setField118(productVO.getField118());
        product.setField119(productVO.getField119());
        product.setField120(productVO.getField120());
        product.setField121(productVO.getField121());
        product.setField122(productVO.getField122());
        product.setField123(productVO.getField123());
        product.setField124(productVO.getField124());
        product.setField125(productVO.getField125());
        product.setField126(productVO.getField126());
        product.setField127(productVO.getField127());
        product.setField128(productVO.getField128());
        product.setField129(productVO.getField129());
        product.setField130(productVO.getField130());
        product.setField131(productVO.getField131());
        product.setField132(productVO.getField132());
        product.setField133(productVO.getField133());
        product.setField134(productVO.getField134());
        product.setField135(productVO.getField135());
        product.setField136(productVO.getField136());
        product.setField137(productVO.getField137());
        product.setField138(productVO.getField138());
        product.setField139(productVO.getField139());
        product.setField140(productVO.getField140());
        product.setField141(productVO.getField141());
        product.setField142(productVO.getField142());
        product.setField143(productVO.getField143());
        product.setField144(productVO.getField144());
        product.setField145(productVO.getField145());
        product.setField146(productVO.getField146());
        product.setField147(productVO.getField147());
        product.setField148(productVO.getField148());
        product.setField149(productVO.getField149());
        product.setField150(productVO.getField150());
        product.setField151(productVO.getField151());
        product.setField152(productVO.getField152());
        product.setField153(productVO.getField153());
        product.setField154(productVO.getField154());
        product.setField155(productVO.getField155());
        product.setField156(productVO.getField156());
        product.setField157(productVO.getField157());
        product.setField158(productVO.getField158());
        product.setField159(productVO.getField159());
        product.setField160(productVO.getField160());
        product.setField161(productVO.getField161());
        product.setField162(productVO.getField162());
        product.setField163(productVO.getField163());
        product.setField164(productVO.getField164());
        product.setField165(productVO.getField165());
        product.setField166(productVO.getField166());
        product.setField167(productVO.getField167());
        product.setField168(productVO.getField168());
        product.setField169(productVO.getField169());
        product.setField170(productVO.getField170());
        product.setField171(productVO.getField171());
        product.setField172(productVO.getField172());
        product.setField173(productVO.getField173());
        product.setField174(productVO.getField174());
        product.setField175(productVO.getField175());
        product.setField176(productVO.getField176());
        product.setField177(productVO.getField177());
        product.setField178(productVO.getField178());
        product.setField179(productVO.getField179());
        product.setField180(productVO.getField180());
        product.setField181(productVO.getField181());
        product.setField182(productVO.getField182());
        product.setField183(productVO.getField183());
        product.setField184(productVO.getField184());
        product.setField185(productVO.getField185());
        product.setField186(productVO.getField186());
        product.setField187(productVO.getField187());
        product.setField188(productVO.getField188());
        product.setField189(productVO.getField189());
        product.setField190(productVO.getField190());
        product.setField191(productVO.getField191());
        product.setField192(productVO.getField192());
        product.setField193(productVO.getField193());
        product.setField194(productVO.getField194());
        product.setField195(productVO.getField195());
        product.setField196(productVO.getField196());
        product.setField197(productVO.getField197());
        product.setField198(productVO.getField198());
        product.setField199(productVO.getField199());
        product.setField200(productVO.getField200());
        product.setField201(productVO.getField201());
        product.setField202(productVO.getField202());
        product.setField203(productVO.getField203());
        product.setField204(productVO.getField204());
        product.setField205(productVO.getField205());
        product.setField206(productVO.getField206());
        product.setField207(productVO.getField207());
        product.setField208(productVO.getField208());
        product.setField209(productVO.getField209());
        product.setField210(productVO.getField210());
        product.setField211(productVO.getField211());
        product.setField212(productVO.getField212());
        product.setField213(productVO.getField213());
        product.setField214(productVO.getField214());
        product.setField215(productVO.getField215());
        product.setField216(productVO.getField216());
        product.setField217(productVO.getField217());
        product.setField218(productVO.getField218());
        product.setField219(productVO.getField219());
        product.setField220(productVO.getField220());
        product.setField221(productVO.getField221());
        product.setField222(productVO.getField222());
        product.setField223(productVO.getField223());
        product.setField224(productVO.getField224());
        product.setField225(productVO.getField225());
        product.setField226(productVO.getField226());
        product.setField227(productVO.getField227());
        product.setField228(productVO.getField228());
        product.setField229(productVO.getField229());
        product.setField230(productVO.getField230());
        product.setField231(productVO.getField231());
        product.setField232(productVO.getField232());
        product.setField233(productVO.getField233());
        product.setField234(productVO.getField234());
        product.setField235(productVO.getField235());
        product.setField236(productVO.getField236());
        product.setField237(productVO.getField237());
        product.setField238(productVO.getField238());
        product.setField239(productVO.getField239());
        product.setField240(productVO.getField240());
        product.setField241(productVO.getField241());
        product.setField242(productVO.getField242());
        product.setField243(productVO.getField243());
        product.setField244(productVO.getField244());
        product.setField245(productVO.getField245());
        product.setField246(productVO.getField246());
        product.setField247(productVO.getField247());
        product.setField248(productVO.getField248());
        product.setField249(productVO.getField249());
        product.setField250(productVO.getField250());
        product.setField251(productVO.getField251());
        product.setField252(productVO.getField252());
        product.setField253(productVO.getField253());
        product.setField254(productVO.getField254());
        product.setField255(productVO.getField255());
        product.setField256(productVO.getField256());
        product.setField257(productVO.getField257());
        product.setField258(productVO.getField258());
        product.setField259(productVO.getField259());
        product.setField260(productVO.getField260());
        product.setField261(productVO.getField261());
        product.setField262(productVO.getField262());
        product.setField263(productVO.getField263());
        product.setField264(productVO.getField264());
        product.setField265(productVO.getField265());
        product.setField266(productVO.getField266());
        product.setField267(productVO.getField267());
        product.setField268(productVO.getField268());
        product.setField269(productVO.getField269());
        product.setField270(productVO.getField270());
        product.setField271(productVO.getField271());
        product.setField272(productVO.getField272());
        product.setField273(productVO.getField273());
        product.setField274(productVO.getField274());
        product.setField275(productVO.getField275());
        product.setField276(productVO.getField276());
        product.setField277(productVO.getField277());
        product.setField278(productVO.getField278());
        product.setField279(productVO.getField279());
        product.setField280(productVO.getField280());
        product.setField281(productVO.getField281());
        product.setField282(productVO.getField282());
        product.setField283(productVO.getField283());
        product.setField284(productVO.getField284());
        product.setField285(productVO.getField285());
        product.setField286(productVO.getField286());
        product.setField287(productVO.getField287());
        product.setField288(productVO.getField288());
        product.setField289(productVO.getField289());
        product.setField290(productVO.getField290());
        product.setField291(productVO.getField291());
        product.setField292(productVO.getField292());
        product.setField293(productVO.getField293());
        product.setField294(productVO.getField294());
        product.setField295(productVO.getField295());
        product.setField296(productVO.getField296());
        product.setField297(productVO.getField297());
        product.setField298(productVO.getField298());
        product.setField299(productVO.getField299());
        product.setField300(productVO.getField300());
        product.setField301(productVO.getField301());
        product.setField302(productVO.getField302());
        product.setField303(productVO.getField303());
        product.setField304(productVO.getField304());
        product.setField305(productVO.getField305());
        product.setField306(productVO.getField306());
        product.setField307(productVO.getField307());
        product.setField308(productVO.getField308());
        product.setField309(productVO.getField309());
        product.setField310(productVO.getField310());
        product.setField311(productVO.getField311());
        product.setField312(productVO.getField312());
        product.setField313(productVO.getField313());
        product.setField314(productVO.getField314());
        product.setField315(productVO.getField315());
        product.setField316(productVO.getField316());
        product.setField317(productVO.getField317());
        product.setField318(productVO.getField318());
        product.setField319(productVO.getField319());
        product.setField320(productVO.getField320());
        product.setField321(productVO.getField321());
        product.setField322(productVO.getField322());
        product.setField323(productVO.getField323());
        product.setField324(productVO.getField324());
        product.setField325(productVO.getField325());
        product.setField326(productVO.getField326());
        product.setField327(productVO.getField327());
        product.setField328(productVO.getField328());
        product.setField329(productVO.getField329());
        product.setField330(productVO.getField330());
        product.setField331(productVO.getField331());
        product.setField332(productVO.getField332());
        product.setField333(productVO.getField333());
        product.setField334(productVO.getField334());
        product.setField335(productVO.getField335());
        product.setField336(productVO.getField336());
        product.setField337(productVO.getField337());
        product.setField338(productVO.getField338());
        product.setField339(productVO.getField339());
        product.setField340(productVO.getField340());
        product.setField341(productVO.getField341());
        product.setField342(productVO.getField342());
        product.setField343(productVO.getField343());
        product.setField344(productVO.getField344());
        product.setField345(productVO.getField345());
        product.setField346(productVO.getField346());
        product.setField347(productVO.getField347());
        product.setField348(productVO.getField348());
        product.setField349(productVO.getField349());
        product.setField350(productVO.getField350());
        product.setField351(productVO.getField351());
        product.setField352(productVO.getField352());
        product.setField353(productVO.getField353());
        product.setField354(productVO.getField354());
        product.setField355(productVO.getField355());
        product.setField356(productVO.getField356());
        product.setField357(productVO.getField357());
        product.setField358(productVO.getField358());
        product.setField359(productVO.getField359());
        product.setField360(productVO.getField360());
        product.setField361(productVO.getField361());
        product.setField362(productVO.getField362());
        product.setField363(productVO.getField363());
        product.setField364(productVO.getField364());
        product.setField365(productVO.getField365());
        product.setField366(productVO.getField366());
        product.setField367(productVO.getField367());
        product.setField368(productVO.getField368());
        product.setField369(productVO.getField369());
        product.setField370(productVO.getField370());
        product.setField371(productVO.getField371());
        product.setField372(productVO.getField372());
        product.setField373(productVO.getField373());
        product.setField374(productVO.getField374());
        product.setField375(productVO.getField375());
        product.setField376(productVO.getField376());
        product.setField377(productVO.getField377());
        product.setField378(productVO.getField378());
        product.setField379(productVO.getField379());
        product.setField380(productVO.getField380());
        product.setField381(productVO.getField381());
        product.setField382(productVO.getField382());
        product.setField383(productVO.getField383());
        product.setField384(productVO.getField384());
        product.setField385(productVO.getField385());
        product.setField386(productVO.getField386());
        product.setField387(productVO.getField387());
        product.setField388(productVO.getField388());
        product.setField389(productVO.getField389());
        product.setField390(productVO.getField390());
        product.setField391(productVO.getField391());
        product.setField392(productVO.getField392());
        product.setField393(productVO.getField393());
        product.setField394(productVO.getField394());
        product.setField395(productVO.getField395());
        product.setField396(productVO.getField396());
        product.setField397(productVO.getField397());
        product.setField398(productVO.getField398());
        product.setField399(productVO.getField399());
        product.setField400(productVO.getField400());
        product.setField401(productVO.getField401());
        product.setField402(productVO.getField402());
        product.setField403(productVO.getField403());
        product.setField404(productVO.getField404());
        product.setField405(productVO.getField405());
        product.setField406(productVO.getField406());
        product.setField407(productVO.getField407());
        product.setField408(productVO.getField408());
        product.setField409(productVO.getField409());
        product.setField410(productVO.getField410());
        product.setField411(productVO.getField411());
        product.setField412(productVO.getField412());
        product.setField413(productVO.getField413());
        product.setField414(productVO.getField414());
        product.setField415(productVO.getField415());
        product.setField416(productVO.getField416());
        product.setField417(productVO.getField417());
        product.setField418(productVO.getField418());
        product.setField419(productVO.getField419());
        product.setField420(productVO.getField420());
        product.setField421(productVO.getField421());
        product.setField422(productVO.getField422());
        product.setField423(productVO.getField423());
        product.setField424(productVO.getField424());
        product.setField425(productVO.getField425());
        product.setField426(productVO.getField426());
        product.setField427(productVO.getField427());
        product.setField428(productVO.getField428());
        product.setField429(productVO.getField429());
        product.setField430(productVO.getField430());
        product.setField431(productVO.getField431());
        product.setField432(productVO.getField432());
        product.setField433(productVO.getField433());
        product.setField434(productVO.getField434());
        product.setField435(productVO.getField435());
        product.setField436(productVO.getField436());
        product.setField437(productVO.getField437());
        product.setField438(productVO.getField438());
        product.setField439(productVO.getField439());
        product.setField440(productVO.getField440());
        product.setField441(productVO.getField441());
        product.setField442(productVO.getField442());
        product.setField443(productVO.getField443());
        product.setField444(productVO.getField444());
        product.setField445(productVO.getField445());
        product.setField446(productVO.getField446());
        product.setField447(productVO.getField447());
        product.setField448(productVO.getField448());
        product.setField449(productVO.getField449());
        product.setField450(productVO.getField450());
        product.setField451(productVO.getField451());
        product.setField452(productVO.getField452());
        product.setField453(productVO.getField453());
        product.setField454(productVO.getField454());
        product.setField455(productVO.getField455());
        product.setField456(productVO.getField456());
        product.setField457(productVO.getField457());
        product.setField458(productVO.getField458());
        product.setField459(productVO.getField459());
        product.setField460(productVO.getField460());
        product.setField461(productVO.getField461());
        product.setField462(productVO.getField462());
        product.setField463(productVO.getField463());
        product.setField464(productVO.getField464());
        product.setField465(productVO.getField465());
        product.setField466(productVO.getField466());
        product.setField467(productVO.getField467());
        product.setField468(productVO.getField468());
        product.setField469(productVO.getField469());
        product.setField470(productVO.getField470());
        product.setField471(productVO.getField471());
        product.setField472(productVO.getField472());
        product.setField473(productVO.getField473());
        product.setField474(productVO.getField474());
        product.setField475(productVO.getField475());
        product.setField476(productVO.getField476());
        product.setField477(productVO.getField477());
        product.setField478(productVO.getField478());
        product.setField479(productVO.getField479());
        product.setField480(productVO.getField480());
        product.setField481(productVO.getField481());
        product.setField482(productVO.getField482());
        product.setField483(productVO.getField483());
        product.setField484(productVO.getField484());
        product.setField485(productVO.getField485());
        product.setField486(productVO.getField486());
        product.setField487(productVO.getField487());
        product.setField488(productVO.getField488());
        product.setField489(productVO.getField489());
        product.setField490(productVO.getField490());
        product.setField491(productVO.getField491());
        product.setField492(productVO.getField492());
        product.setField493(productVO.getField493());
        product.setField494(productVO.getField494());
        product.setField495(productVO.getField495());
        product.setField496(productVO.getField496());
        product.setField497(productVO.getField497());
        product.setField498(productVO.getField498());
        product.setField499(productVO.getField499());
        product.setField500(productVO.getField500());
        product.setField501(productVO.getField501());
        product.setField502(productVO.getField502());
        product.setField503(productVO.getField503());
        product.setField504(productVO.getField504());
        product.setField505(productVO.getField505());
        product.setField506(productVO.getField506());
        product.setField507(productVO.getField507());
        product.setField508(productVO.getField508());
        product.setField509(productVO.getField509());
        product.setField510(productVO.getField510());
        product.setField511(productVO.getField511());
        product.setField512(productVO.getField512());
        product.setField513(productVO.getField513());
        product.setField514(productVO.getField514());
        product.setField515(productVO.getField515());
        product.setField516(productVO.getField516());
        
        long end = System.currentTimeMillis();
        System.out.println("directSet time:"+(end-start));
    }
原网站

版权声明
本文为[Brother wind]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/223/202208110907224171.html