简体   繁体   中英

How to refactor this REST API Spring Boot app?

I'm working on a simple financial transaction app in Spring Boot. And I want to know if I could improve it. There are 4 types of transactions and I have 4 different endpoints and 4 request classes. I want to know if I could use a design pattern or something with these 4 request classes. This is the code:

So I want to ask you if I could refactor this code, especially in the service, to use a design pattern, or how can I improve the implementation. I don't want to add a new functionality, just to refactor the code and improve it. Thank you!

Not sure if you are using java 8 if so you can create Functions to transform the incoming request objects to the models/entities you are using in the service layers. If you are using a prior version of java create transformer classes that would do the same. I would also probably have methods on the entities which would convert the Entities back into model objects.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM