Sails is a node. JS middleware architecture that helps us build Web applications easily, URL: http://www.sailsjs.org/, which is developed primarily on the basis of the express framework, expands the new functional components, Let's take a look at the installation method
One installation sails
Npm-g Install sails
Second, establish a sails project
New TestProject
Three startup projects
CD Testprojectsails Lift
The structure of the four projects, based on the MVC concept
We can see that it is made up of Model,view,controller, which is very similar to. NET MVC, except that the model in. NET MVC refers primarily to viewmodel, whereas in sails the model is mostly data models, That is, the entity in. NET, which is an abstraction of data tables, sails provides many kinds of data persistence, such as local files, Mysql,mongodb,redis, etc., for SQL Server We can also find third-party components.
Five to render the view through the Controller's action
In. NET MVC, we all know that views are rendered using the Render method of the action, which is also the case with sails, which can use native render, or use the encapsulated view method, and use the object returned by your action directly on the view.
Controller/action's Content
module.exports={ index:function (req, res) { return res.view ("Test/index ", {title:" uncle ", Engtitle:"Lind"}) ; // return Res.view ("view_name", data) // The view_name parameter is empty to indicate the current action }};
View-ejs's Content
<p> objects returned from Action-title:<%=title%></p><p> object returned from action-engtitle:<%=engtitle%></p >
The result of the call is as follows
If you enter the index page, you can write the controller name directly
If the other action wants to take a route such as/test, it needs to be configured in Config/route.js, such as adding a route to/user for the add action, which is set as
NULL }},' Get/test ': {view: ' Test/index ', locals:{layout:null}}
Well, to such a simple MVC of the demo is done, the next section we will refer to model, the data persistence mechanism, for the curd operation of the data table, please look forward to ...
node. js and sails~ project structure and MVC implementation