Our example will demonstrate three different table relationships: One-to-One One-to-Many Many-to-Many You can download the schema.sql here, and run it with MySQL client. /* create database */ CREATE DATABASE itblogs DEFAULT CHARACTER SET utf8; USE itblogs; /* One-to-One relationship */ /* SHOP – ADDRESS */ CREATE TABLE ADDRESS( id BIGINT NOT NULL AUTO_INCREMENT,
Let’s try running the app by right-click the project: Choose “Always use this server when running this project. You can change to other web server, such as JBoss or other if you want to. Simply click finish to run it. Done, it is running!!! Please rate this Useful?
Before running the app, you need to setup the web.xml, dispatcher-servlet.xml and other property files properly. Let’s update the web.xml file by right-click src/main/webapp/WEB-INF/web.xml => Open With Text Editor and then update with below settings: <?xml version=”1.0″ encoding=”UTF-8″?> <web-app xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xmlns=”http://java.sun.com/xml/ns/javaee” xmlns:web=”http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd” xsi:schemaLocation=”http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd” id=”WebApp_ID” version=”2.5″> <display-name>SpringMVCExample</display-name> <welcome-file-list> <welcome-file>index.html</welcome-file>
Starting from Spring 3.1, you can run the app without web.xml and dispatch-servlet.xml. Simply storing all your settings in Spring configuration and servlet initizer, it helps to simplify the web configuration with Spring. Let’s create a Spring configuration file called AppConfiguration.java under src/main/java/com/itblogs/config/ as: package com.itblogs.config; import org.springframework.context.MessageSource; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import
Now, we will create two property files to src/main/resources/ , right-click to create a new file called log4j.properties with below settings. After running the app, you can find the log file (SpringMVCExample.log) under C:\logs\ folder. # logger option for File and stdout log4j.rootLogger=INFO, File, stdout # Logging levels : ALL, DEBUG, INFO, WARN, ERROR, FATAL,
Under the project, you can find pom.xml file. Right-click this file, and Open With Text Editor: Adding below dependencies: <project xmlns=”http://maven.apache.org/POM/4.0.0″ xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=”http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd”> <modelVersion>4.0.0</modelVersion> <groupId>com.itblog</groupId> <artifactId>SpringMVCExample</artifactId> <packaging>war</packaging> <version>0.0.1-SNAPSHOT</version> <name>SpringMVCExample Maven Webapp</name> <url>http://maven.apache.org</url> <properties> <spring.version>4.2.0.RELEASE</spring.version> <hibernate.version>4.3.11.Final</hibernate.version> <javax.validator.version>1.1.0.Final</javax.validator.version> <hibernate.validator.version>5.2.2.Final</hibernate.validator.version> <mysql.connector.version>5.1.31</mysql.connector.version>
Let’s try to create a new Maven Project using Eclipse. Right-click on “Navigator” or “Project Explorer” => select “New” => choose “Maven Project” Click “Next” Select “maven-archetype-webapp”: Click “Next”, and fill in the below values: Click “Finish”, the project SpringMVCExample has been created: Please rate this Useful?
Background and Pre-request Developers always talk about Spring and Hibernate. In fact, they are two different frameworks. But, working closely together very well, and forming MVC (Model-View-Controller) framework. Spring is one of the most famous Java application framework, constructing Controllers and Views (JSP). Hibernate is an ORM (object-relational mapping) framework, constructing Models. This blog
You may find the below (CRUD ) actions from this web UI: HTTP Method Actions GET Get / List record(s) POST Create record PUT Update record DELETE Delete record R – Read the list of customers [GET Method] Let’s go to Customer List page, you can find the list of customers here. The UI