Spring Web MVC Hello World

 

Git Clone Link: https://gitlab.com/shaileshsonare/spring_helloworld.git

Step 1. Create new Project

Step 2. Name the Project and select location

 

Step 3. Select Server and Settings

 

Step 4. Select Framework to include in Project’s library and include JSTL (Java Server Pages Tag Library)

 

Step 5. Project Created Successfully

Step 6. Check Welcome file. This file will display on browser if we enter only Project name in url.

e.g. http://localhost:8080/ProjectName/

Step 7. This section will decide which url pattern will be consider as Spring Requests and which url is not a part of Spring Framework.

Here all *.htm (URL ending with .htm from browser) will be consider as Spring request.

 

Step 8. You can run normal jsp pages also from browser which will not be part of Spring framework.

 

Step 9. Create new jsp file as

Right Click on WebPages >> New >> Jsp File

 

Step 10. Run on Browser it will run as old traditional jsp project file.

 

Hibernate CRUD with MySQL Database – Java

 

To Update Record Using Hibernate Session:

Configuration cfg = new Configuration().configure("hibernate.cfg.xml"); 

StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder().applySettings(cfg.getProperties()); 

SessionFactory factory = cfg.buildSessionFactory(ssrb.build()); Session session = factory.openSession(); 

Transaction t = session.beginTransaction(); 

Users u = (Users) session.load(Users.class, 6); // load record having id 6 into u object

u.setLastName("Nitnavre"); // set column value which needs to update

System.out.println(session.save(u)); // fire update query using save function of hibernate

t.commit(); // commit the update changes to save state in database

System.out.println("Record updated successfully...");

 

Ref Link:

  1. https://www.journaldev.com/3481/hibernate-session-merge-vs-update-save-saveorupdate-persist-example

Creating Hibernate Session with Database

  1. model.dao.interfaces.EmployeeDAOInterface.java

 

package model.dao.interfaces;

import java.util.List;
import model.Employee;

/**
 *
 * @author Shailesh Sonare
 */
public interface EmployeeDAOInterface {
    public List getAllEmplyees();
}

 

2. model.dao.EmployeeDAO.java

 

package model.dao;

import java.util.Iterator;
import java.util.List;
import model.Employee;
import model.dao.interfaces.EmployeeDAOInterface;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;

/**
 *
 * @author Shailesh Sonare
 */
public class EmployeeDAO implements EmployeeDAOInterface {

    @Override
    public List getAllEmplyees() {
        Configuration cnf = new Configuration();
        cnf.configure("hibernate.cfg.xml");
        
        StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder().applySettings(cnf.getProperties());
        
        SessionFactory sf = cnf.buildSessionFactory(ssrb.build());
        Session session = sf.openSession();
        
        String hql = "FROM Employee where id = 2";
        
        List list = session.createQuery(hql).list();
        
        for(Iterator iterator = list.iterator(); iterator.hasNext();) {
            Employee e = (Employee)iterator.next();
            
            System.out.println(e.getName());
        }
        
        return list;
    }
    
}

 

Structure

  1. WAP to read Information about Student and Display it.
    (Information: Roll Number, Name, Age, Sex)
  2. WAP to read Information about an Employee and Display it.
    (Information: EmpNo, Name, Job, Sal)
  3. WAP to read Information about a Worker and Print Payment
    (Information: Name, Wages, WorkingDays)
  4. WAP to read information about 10 workers and print their Payment.
    Print Average Payment
    (Information: Name, Wages, WorkingDays)
  5. WAP to read co-ordinates of end point of a line and find its slope by using the structure
    struct Line{
    int x1, y1, x2, y2;
    }
  6. WAP to read information about student
    (Roll No. Name, Birth Date, Admission Date) by using following structure
    struct date {
    int D, M, Y;
    }
    struct Student {
    int RollNo;
    char name[20];
    struct date bdate;
    struct date admsndate;
    }

Arrays Programs (Multi Dimensional)

  1. WAP to read a matrix of size 3 X 5 and find their SUM
  2. WAP to read a matrix of size 3 X 5 and find sum of each ROW
  3. WAP to read a matrix of size 3 X 3 and check if it is NULL or NOT
  4. WAP to read a matrix of size 3 X 5 and count all EVEN and ODD numbers
  5. WAP to read matrix of size 3 X 3 and check if it is UNIT Matrix or NOT
  6. WAP to read 2 matrix of size 3 X 3 and find their Addition
  7. WAP to read 2 matrix of size 3 X 3 and find their Product
  8. WAP to read matrix of size 3 X 3 and find its Transpose
  9. WAP to read matrix of size 3 X 3 and find its Transpose without using second matrix
  10. WAP to read matrix of size 3 X 3 and find its Upper Triangular Matrix
  11. WAP to read matrix of size 3 X 3 and find its Lower Triangular Matrix
  12. WAP to read matrix of size 3 X 3 and check if sum of its diagonal is same or not
  13. WAP to read matrix of size 3 X 3 and check if sum of its middle row is same as sum of its middle column
  14. WAP to create TIC-TAC-TOE by showing number and take 9 inputs from 2 users.
    1 2 3
    4 5 6
    7 8 9

    X O X
    O X O
    O O X

    PLAYER 1 WIN
    O X O
    X O X
    O X O

    PLAYER 2 WIN

Arrays Programs (One Dimensional)

  1. WAP to read an array of 10 numbers and find their sum
  2. WAP to read temperature days of Week and find their Mean
  3. WAP to read an array of 10 numbers and find greatest of them
  4. WAP to read an array of 10 numbers and count all EVEN and ODD numbers
  5. WAP to rad an array of 10 numbers and find sum, mean, min, max
  6. WAP to read an array of 10 numbers and search a number in it
  7. WAP to read an array of 10 numbers and sort it in ascending order
  8. WAP to read an array of 10 numbers and sort it in descending order
  9. WAP to insert a number at given position in an array (optional)
  10. WAP to remove a number from given position from an array (optional)
  11. WAP to arrange all even numbers at top and all odd numbers at bottom of an array (optional)

FUNCTIONS

  1. WAF repeat to display a char specified no of times.
  2. WAF intrest to calculate simple intrest.
  3. WAF to return Volume of Sphere
  4. WAF to return mean of 3 numbers
  5. WAF to return greatest of 2 numbers
  6. WAF to return Factorial of given Number
  7. WAF to return Sum of Given Number.
  8. WAF to return Greatest of 3 numbers.
  9. WAF to print all numbers from 1 to given numbers
  10. WAF to repeat a given char given number of timest.
    e.g. repeat(‘#’, 25)
  11. Design a recursive function factorial to return factorial of given number.
  12. Design a recursive function intrest to return compound intrest.
  13. Design a recursive function SOD to return sum of digit of given number.
  14. WAF to return sum of number which is passed in a Array.
  15. WAF to return Mean of numbers which is passed in a Array.
  16. WAF to return Greatest number which is passed in a Array.