Author: Kelvin Hui

Example 2: MVC App No ratings yet.

Like other famous development languages, such as .NET and Java, node.js does have development framework like MVC. This example will show you how to buildup a small MVC web application using express framework. Please note that this example is based on express version 4.13.4 . Let’s create the folders: example under {your_node.js_installed_path}\nodejs\ demo2 under {your_node.js_installed_path}\nodejs\examples\

Example 1: Simple Web Page with MySQL connection No ratings yet.

This example will show you how to connect to MySQL database and response output to webpage. Please download the schema.sql here, and run it with MySQL client. /* create database */ CREATE DATABASE itblogs DEFAULT CHARACTER SET utf8;   USE itblogs;   CREATE TABLE COMPANY( id BIGINT NOT NULL AUTO_INCREMENT, name VARCHAR(50) NOT NULL, background 

Installation of Node.js (Windows) No ratings yet.

Before working on the examples, let’s setup the environment first: Install MySQL (using 5.7 for our example), you can download from http://dev.mysql.com/downloads/mysql/ Download and install Node.js version 4.X from https://nodejs.org/en/ Run “cmd”, and using it to install necessary modules Install Express framework by “npm install express” Install ejs template engine by “npm install ejs” Install logger Morgan by “npm install morgan”

DAO Layer & Service Manager Layer No ratings yet.

All DAO classes will extend the GenericDao.java, which includes some common database actions, such as saveOrUpdate() and findByID(). Besides, it is also using to auto-wired the sessionFactory: package com.itblogs.dao; import java.util.List; import java.io.Serializable; import java.lang.reflect.ParameterizedType; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.criterion.Order; import org.hibernate.Criteria; import org.springframework.beans.factory.annotation.Autowired; /**  * @author      Kelvin Hui  * @see              it-blogs.com  *

MODEL : Create Hibernate ORM Models No ratings yet.

We will create five model classes mapping to our database tables, please download here: Java Class Files Table Name Address.java ADDRESS Customer.java CUSTOMER Orders.java ORDERS Product.java PRODUCT Shop.java SHOP Nil   We don’t need to create a model class for this table. But, we will use @ManyToMany annotation in Orders.java to state this join table