java – A way to create a plant motif for an application in the spring

I created this code

@A service
Public class TestService {

@Autowired
private Test1Repository test1Repository;

@Autowired
private test2Repository test2Repository;

@Autowired
private Test1Mapper test1Mapper;

@Autowired
test2Mapper private test2Mapper;

public vacuum test (map body){
if ("test1" .equals (body.get ("type")))) {
Test1 test1 = test1Mapper.mapToTest1 (body);
// the logic here
test1Repository.save (test1);
} else if ("test2" .equals (body.get ("type")))) {
Test2 test2 = test2Mapper.mapToTest2 (body);
// the logic here
test2Repository.save (test2);
}
}

}

I think it's not so good to create an if statement for each type of query because in the future, I'll need to add others. I'm trying to use enum

TestType.valueOf ((String) body.get ("type")). SaveInDB ();

But in the enumeration, I can not inject repositories or mappers. I am looking for a way to solve this problem but I can not find it. Does anyone have a source with an explanation to solve the problem with if statements can explain how to solve it?

Thank you in advance.