Hello Readers,
I am going to share one of my interview question which is CRUD application ask in practical round so here I am sharing the complete code here.
hope you will enjoy it !
INCLUDED ALL .XML FILES
Project Name : meavenCrudSpring
File 1 : pom.xml (location : meavenCrudSpring\)
CODE :
<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.spring</groupId>
<artifactId>meavenCrudSpring</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>meavenCrudSpring Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.7</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.2.4.RELEASE</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.30</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>5.2.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.4.2.Final</version>
</dependency>
</dependencies>
<build>
<finalName>meavenCrudSpring</finalName>
</build>
</project>
File 2 : web.xml (location : meavenCrudSpring\src\main\webapp\WEB-INF\)
CODE :
File 3 : spring-servlet.xml (location : meavenCrudSpring\src\main\webapp\WEB-INF\)
CODE :
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<tx:annotation-driven />
<context:component-scan base-package="meavenCrudSpring" />
<mvc:annotation-driven />
<mvc:resources location="/WEB-INF/resources/" mapping="/resources/**" />
<!-- view resolver configuration -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" name="viewResolver">
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>
<!-- mysql database configuration -->
<bean class="org.springframework.jdbc.datasource.DriverManagerDataSource" name="ds">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/jdbcspringtutorial" />
<property name="username" value="root" />
<property name="password" value="" />
</bean>
<bean class="org.springframework.orm.hibernate5.LocalSessionFactoryBean" name="factory">
<!-- data Source -->
<property name="dataSource" ref="ds"/>
<!-- hibernate property -->
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL57Dialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
<!-- annotated classes -->
<property name="annotatedClasses">
<list>
<value>meavenCrudSpring.Model.Product</value>
</list>
</property>
</bean>
<bean class="org.springframework.orm.hibernate5.HibernateTemplate" name="hibernateTemplate">
<property name="sessionFactory" ref="factory"/>
</bean>
<bean class="org.springframework.orm.hibernate5.HibernateTransactionManager" name="transactionManager">
<property name="sessionFactory" ref="factory" />
</bean>
</beans>
File 4 : jdbcspring(location : in database (here PhpMySql))
Table Name : product
Database Name : jdbcspringtutorial
CODE :
-- phpMyAdmin SQL Dump
-- version 5.0.2
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1
-- Generation Time: Jul 23, 2021 at 06:48 AM
-- Server version: 10.4.11-MariaDB
-- PHP Version: 7.4.6
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
--
-- Database: `jdbcspringtutorial`
--
-- --------------------------------------------------------
--
-- Table structure for table `hibernate_sequence`
--
CREATE TABLE `hibernate_sequence` (
`next_val` bigint(20) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Dumping data for table `hibernate_sequence`
--
INSERT INTO `hibernate_sequence` (`next_val`) VALUES
(13);
-- --------------------------------------------------------
--
-- Table structure for table `product`
--
CREATE TABLE `product` (
`id` int(11) NOT NULL,
`description` varchar(255) DEFAULT NULL,
`name` varchar(255) DEFAULT NULL,
`price` bigint(20) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Dumping data for table `product`
--
INSERT INTO `product` (`id`, `description`, `name`, `price`) VALUES
(10, 'Awesome Phone yoo', 'Oppo Reno 2', 20000),
(11, 'La Javab Phone', 'Apple XR', 100000),
(12, 'Bidu bole to hiladala yo', 'Tamsung S21+ Altra Max Pro A1', 100001);
-- --------------------------------------------------------
--
-- Table structure for table `student_details`
--
CREATE TABLE `student_details` (
`student_id` int(11) NOT NULL,
`student_city` varchar(255) DEFAULT NULL,
`student_name` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Dumping data for table `student_details`
--
INSERT INTO `student_details` (`student_id`, `student_city`, `student_name`) VALUES
(8, 'Kashmir', 'Jignesh'),
(10, 'Rajkot', 'Rushabh'),
(11, 'Vadaj', 'Vatshal'),
(12, 'ahmedabad', 'google');
-- --------------------------------------------------------
--
-- Table structure for table `tblstudent`
--
CREATE TABLE `tblstudent` (
`sid` int(2) NOT NULL,
`sname` varchar(100) NOT NULL,
`scity` varchar(200) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Dumping data for table `tblstudent`
--
INSERT INTO `tblstudent` (`sid`, `sname`, `scity`) VALUES
(1, 'siddharth', 'pune'),
(2, 'uttam', 'chand'),
(3, 'Jatin', 'Thailand'),
(4, 'Jamnaben', 'Jammu'),
(5, 'Arjun', 'mumbai'),
(6, 'Arjunbhai', 'puna'),
(7, 'yogesh', 'japan');
-- --------------------------------------------------------
--
-- Table structure for table `user`
--
CREATE TABLE `user` (
`id` int(11) NOT NULL,
`userEmail` varchar(255) DEFAULT NULL,
`userName` varchar(255) DEFAULT NULL,
`userPassword` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Dumping data for table `user`
--
INSERT INTO `user` (`id`, `userEmail`, `userName`, `userPassword`) VALUES
(1, 'auguust1708@gmail.com', 'Siddharth', '1290'),
(2, 'patelyash270200@gmail.com', 'Siddharth Panchal', 'Siddddddd'),
(3, 'panchalsiddharth5134@gmail.com', 'Siddharth Panchal', '9090');
--
-- Indexes for dumped tables
--
--
-- Indexes for table `product`
--
ALTER TABLE `product`
ADD PRIMARY KEY (`id`);
--
-- Indexes for table `student_details`
--
ALTER TABLE `student_details`
ADD PRIMARY KEY (`student_id`);
--
-- Indexes for table `tblstudent`
--
ALTER TABLE `tblstudent`
ADD PRIMARY KEY (`sid`);
--
-- Indexes for table `user`
--
ALTER TABLE `user`
ADD PRIMARY KEY (`id`);
COMMIT;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
0 comments:
Post a Comment