【转载】Spring最佳后台框架

https://www.quora.com/What-is-the-best-backend-arquitecture-using-spring-framework

The most modern architecture is one based on Spring as a backend, with a Javascript framework on the frontend. A good alternative is Spring as a full stack framework, using Thymeleaf for server generated JSP pages, see Tutorial: Thymeleaf + Spring, but nowadays people expect web pages to be dynamic and fast responsing, and this is harder to do with server generated UI.

In this case, Spring will act as a RESTful service (Understanding : REST) and the JS framework will request and use it to generate Web pages. Actually, the most used frameworks are:

You’ll surely find a ton of other alternatives as valid as these. My personal suggestion is to start with AngularJS 2, avoid the 1.x branch which suffered from various issues.

ReactJS is probably most performant and has more hype, but it requires to be assembled with other libraries to start working, while Angular is an all-in-one tool.

DDD is a design approach where entities “drive” the overall architecture. So, you have a OO model and, around it, a layer of services which manage them.

Casually it’s what Spring does by default :)

If a storage is needed, you have to choice between SQL or noSQL. Then you have to choice between direct SQL access or an ORM framework. ORM, usually by Hibernate, simplifies table <-> entity mapping, but it’s another framework to learn…

This is a guide about using SQL with Spring Accessing Relational Data using JDBC with Spring and this is about using an ORM Accessing Data with JPA

Having your DB mapped to OO entities, you now need to throw them to the JS framework. The right way is to serialize your output as Json, so the (simplified) path is:

DB -> (by SQL/ORM repository)-> Object -> (by Services) -> HTTP Resource -> (by Controller) -> Json

Going from your DB-loaded entities (or some representation of them) to Json is very easy, by using RestControllers, usually you simply return the entity, and Spring will do the serialization, using FasterXML/jackson.

This is a guide about REST controllers: Spring MVC 4 RESTFul Web Services CRUD Example+RestTemplate - WebSystique

As I usually write, there is a lot of work to do, compared to PHP/Ruby/Python couterparts. This is justified by a better organization of your code, and the advantages become more clear on size growing. For little or simple problems all this work has objectively no justification.

原文地址:https://www.cnblogs.com/pengyusong/p/6184349.html