To achieve three-tier architecture development based express. The figure below shows the development of the student management system
. Usually Ajax requests to the appropriate HTML. That is transmitted from the request to students.js sms.html Ajax
A: 1 is divided into: the presentation layer, mainly to accept a request sent by the user, and the data is returned, .2 providing access for the client application: business logic layer: mainly responsible for the operation of the data, i.e. some data layer the combined operation. 3: data access layer. When the operation of the main data
Two: establish a three-tier structure based on express, as a general directory. , Public (static html page at write), routes (inside stuendts.js accept requests static page, and return data),-Service (stuendtsService.js inside of routes inside stuendts.js data from the operation, and return result), dao (data layer)
NOTE: dao layer, the data processing layer, generally divided into three parts, a last see FIG.
dao layer, the data processing layer, generally divided into three parts. ① (db.js), directly connected to the database. ② establish dao folder inside subfolders see models, establish a database of the skeleton underneath, and the creation of the model based on the skeleton. (StudentsModel.js) ③ (studentsDao.js), direct data interface operation receiving studentsService.js folder service data transmitted, according to the transmitted data, the data inside the database search operation deletions reform and returns the result to the service folder.
Three detailed processes and implementation code.
1: static pages under public
// send Ajax
Ajax({
url:"./students/getStudents",
data:,
success(){
}
})
2: students.js routes folder // receiving information pages sent, and feedback
// index file
4: studentsDao.js//对数据库的数据进行操作
5:db.js//连接数据库