ciphermagic / java-learn Goto Github PK
View Code? Open in Web Editor NEW学习 Java 过程中的一些记录,代码为主
Home Page: http://www.ciphermagic.cn
学习 Java 过程中的一些记录,代码为主
Home Page: http://www.ciphermagic.cn
public interface AbstractOrderHandler {
String handle(OrderDTO dto);
String type();
}
@Component
public class LitbHandler implements AbstractHandler {
@Override
public String handle(OrderDTO dto) {
return OrderType.litb.toString();
}
@Override
public String type() {
return OrderType.litb.toString();
}
}
@Service
public class OrderServiceImpl implements OrderService {
@Resource
public ApplicationContext applicationContext;
@Override
public String handle(OrderDTO dto) {
String orderType = String.valueOf(dto.getType());
// Spring 有个 Map Cache 根据 class 来缓存 bean Name, 此处无需担忧性能
Map<String, AbstractOrderHandler> beans = applicationContext.getBeansOfType(AbstractOrderHandler.class);
beans.values().stream()
.filter(x -> x.type().equals(orderType))
.findFirst()
.orElseThrow(() -> new RuntimeException("not found handler for type: " + orderType))
.handle(dto);
return null;
}
}
后来发现用 注解 有点脱了裤子放屁的感觉。
绕来绕去的,除了增加阅读复杂度
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.