mardi 16 octobre 2018

there are lots of @Service methods to check if an id has some result

if (!WebUtils.isEmpty(appAppService.getByAppid(id))) {
        LOGGER.info(":bind app info");
        errorNum++;
    }
    if (!WebUtils.isEmpty(appDownloadCensusService.getByAppid(id))) {
        LOGGER.info(":bind bi info");
        errorNum++;
    }
    if (!WebUtils.isEmpty(appManuCensusService.getByAppid(id))) {
        LOGGER.info(":bind download info");
        errorNum++;
    }
    if (!WebUtils.isEmpty(appOrderService.getByAppid(id))) {
        LOGGER.info(":bind order info");
        errorNum++;
    }
    if (!WebUtils.isEmpty(appShareService.getByAppid(id))) {
        LOGGER.info(":bind share info");
        errorNum++;
    }
    ......

these xxxService are @Autowired properties, and the "...." presents other similar if statements.How can I avoid this by refactoring code?I tried to use reflection to get the xxxService,but I found that the xxxService class could be created,but properties in them,e.g. xxxxDao,SessionFactory(I was using Hibernate),these cannot be created by reflection,how can I do this?Or if there any other way to solve the if check issue?

What I really want is how to refactor the code to make it look more pretty:how can I avoid so many if statements?





Aucun commentaire:

Enregistrer un commentaire