Construction of the Schneider Building Control System database backend server example project 2 (database query and writing), Schneider Control System
The example Project (Project Creation) of the database backend server of the Schneider building control system records how a Spring, Hibernate, and Rest project is created, this article briefly introduces how to use annotation programming in this framework.
1. Spring Annotation
Spring provides @ Service and @ Autowired annotations for automatic Bean creation in the project.
In our framework, we need to add the @ Service tag before the class name that needs to be called by other classes, and add @ Autowired to the member class that needs to be automatically created, in this way, Spring automatically assembles related class instances for us during the program running.
2. Rest comments
Rest means that we can use "/" to access our background services on the Web end in the form of resource list, rest annotations include @ Get, @ Post, and @ Put, which correspond to the doGet, doPost, and doPut methods in the Servlet respectively, and the annotation for configuring the Rest access Path @ Path
(Ps: In this project, the Rest is automatically created by the Spring framework when the program is running, so you also need to add the @ Service tag)
@ Path ("testRest") @ Servicepublic class TestRest {@ Autowiredprivate TestService testService; @ GET @ Path ("test") public String test () {DuplicateValueTypeModel model = testService. getId (1); return "rest (" + model. getDuplicateValueTypeId () + "," + model. getName () + ")";}}
The Rest access path of the code above is:
The project has not been fully organized yet. Only the database query is implemented, and the code will be improved later. The prototype of the code will be put here first.