DoctorTableDataEntry

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 8

Pom.

xml:
<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
https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.hrs.dataentry</groupId>
<artifactId>Hospital_Reception_System_Data_Entry</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.2.20.RELEASE</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jasper</artifactId>
<version>9.0.12</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2
</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>5.3.1</version>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<version>8.0.32</version>
</dependency>

<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.0.13.Final</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.3</version>
</plugin>
</plugins>
</build>
</project>

Doctor_Details.java
package com.CRUD.beans;

public class Doctor_Details {


private int doctor_Id,age;
private String
gender,specialization,experience,language,mobile_No,email_ID,schedule;
public int getAge() {
return age;
}
public int getDoctor_Id() {
return doctor_Id;
}
public String getGender() {
return gender;
}
public String getSpecialization() {
return specialization;
}
public String getExperience() {
return experience;
}
public String getLanguage() {
return language;
}
public String getMobile_No() {
return mobile_No;
}
public String getEmail_ID() {
return email_ID;
}
public String getSchedule() {
return schedule;
}
public void setAge(int age) {
this.age = age;
}
public void setDoctor_Id(int doctor_Id) {
this.doctor_Id = doctor_Id;
}
public void setGender(String gender) {
this.gender = gender;
}
public void setSpecialization(String specialization) {
this.specialization = specialization;
}
public void setExperience(String experience) {
this.experience = experience;
}
public void setLanguage(String language) {
this.language = language;
}
public void setMobile_No(String mobile_No) {
this.mobile_No = mobile_No;
}
public void setEmail_ID(String email_ID) {
this.email_ID = email_ID;
}
public void setSchedule(String schedule) {
this.schedule = schedule;
}
}

Doctor_Details_Dao.java
package com.CRUD.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;

import com.CRUD.beans.Doctor_Details;

public class Doctor_Details_Dao {


JdbcTemplate template;

public void setTemplate(JdbcTemplate template) {


this.template=template;
}
public int save(Doctor_Details d) {
String sql="insert into doctor(Doctor_Id,Age,Gender,Specialization,"
+ "Experience,Language,Mobile_No,Email_ID,Schedule)
values('"
+ d.getDoctor_Id()+"',"+d.getAge()+",'"+d.getGender()+"','"
+ d.getSpecialization()+"','"+d.getExperience()+"','"
+ d.getLanguage()+"','"+d.getMobile_No()+ "','"
+ d.getEmail_ID()+"','"+d.getSchedule()+"')";
return template.update(sql);
}
public int update(Doctor_Details d) {
String sql="update doctor set Age="+d.getAge()+",Specialization='"
+ d.getSpecialization()+"',Experience='"+d.getExperience()
+ "',Language='"+d.getLanguage()
+"',Mobile_No='"+d.getMobile_No()
+ "',Email_ID='"+d.getEmail_ID()
+"',Schedule='"+d.getSchedule()
+ "'"+ "where Doctor_Id="+d.getDoctor_Id()+"";
return template.update(sql);
}
public int delete(int id) {
String sql="delete from doctor where Doctor_Id="+id+"";
return template.update(sql);
}
public Doctor_Details getDoctor_DetailsById(int id) {
String sql="select * from doctor where Doctor_Id=?";
return template.queryForObject(sql, new Object[] {id}, new
BeanPropertyRowMapper<Doctor_Details>(Doctor_Details.class));
}
public List<Doctor_Details> getEmployees(){
return template.query("select * from doctor", new
RowMapper<Doctor_Details>() {
public Doctor_Details mapRow(ResultSet rs, int row) throws
SQLException{
Doctor_Details d=new Doctor_Details();
d.setDoctor_Id(rs.getInt(1));
d.setAge(rs.getInt(2));
d.setGender(rs.getString(3));
d.setSpecialization(rs.getString(4));
d.setExperience(rs.getString(5));
d.setLanguage(rs.getString(6));
d.setMobile_No(rs.getString(7));
d.setEmail_ID(rs.getString(8));
d.setSchedule(rs.getString(9));
return d;
}
});
}
}

Doctor_Details_Controller.java
package com.CRUD.controllers;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.CRUD.beans.Doctor_Details;
import com.CRUD.dao.Doctor_Details_Dao;

@Controller
public class Doctor_Details_Controller {
@Autowired
Doctor_Details_Dao dao;
@RequestMapping("/adddoctordetailsform")
public String showform(Model m) {
m.addAttribute("command", new Doctor_Details());
return "adddoctordetailsform";
}
@RequestMapping(value="/save",method=RequestMethod.POST)
public String save(@ModelAttribute("doctor_details") Doctor_Details
doctor_Details) {
dao.save(doctor_Details);
return "redirect:/viewdoctordetailsform";
}
@RequestMapping("/viewdoctordetailsform")
public String viewdoctordetailsform(Model m) {
List<Doctor_Details> list=dao.getEmployees();
m.addAttribute("list", list);
return "viewdoctordetailsform";
}
@RequestMapping(value="/editdoctordetails/{doctor_Id}")
public String edit(@PathVariable int doctor_Id, Model m) {
Doctor_Details doctor_Details=dao.getDoctor_DetailsById(doctor_Id);
m.addAttribute("command", doctor_Details);
return "editdoctordetailsform";
}
@RequestMapping(value="/editsave",method=RequestMethod.POST)
public String editSave(@ModelAttribute("doctor_details")Doctor_Details
doctor_Details) {
dao.update(doctor_Details);
return "redirect:/viewdoctordetailsform";
}

@RequestMapping(value="deletedoctordetails/{doctor_Id}",method=RequestMethod.GET)
public String delete(@PathVariable int doctor_Id) {
dao.delete(doctor_Id);
return "redirect:/viewdoctordetailsform";
}
}

web.xml:
<?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"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>SpringMVC</display-name>
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>

spring-servlet.xml:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="com.CRUD.controllers"/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
<bean id="ds" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.cj.jdbc.Driver"/>
<property name="url"
value="jdbc:mysql://localhost:3306/hospital_reception_system"/>
<property name="username" value="root"/>
<property name="password" value="as12@#as"/>
</bean>
<bean id="jt" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="ds"/>
</bean>
<bean id="dao" class="com.CRUD.dao.Doctor_Details_Dao">
<property name="template" ref="jt"/>
</bean>
</beans>

index.jsp:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>AAA Hospital Reception System</title>
</head>
<body bgcolor="miranda">
<h2>Welcome to Our Hospital's Portal</h2>
<a href="adddoctordetailsform">Add Doctor Details</a>
<a href="viewdoctordetailsform">View Doctor Employees</a>
</body>
</html>

editdoctordetailsform:
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<h1>Edit Doctor_Details</h1>
<form:form method="POST" action="/Hospital_Reception_System_Data_Entry/editsave">
<table>
<tr>
<td></td>
<td><form:hidden path="Doctor_Id"/></td>
</tr>
<tr>
<td>Age: </td>
<td><form:input path="Age"/></td>
</tr>
<tr>
<td>Gender: </td>
<td><form:input path="Gender"/></td>
</tr>
<tr>
<td>Specialization: </td>
<td><form:input path="Specialization"/></td>
</tr>
<tr>
<td>Experience: </td>
<td><form:input path="Experience"/></td>
</tr>
<tr>
<td>Language: </td>
<td><form:input path="Language"/></td>
</tr>
<tr>
<td>Mobile_No: </td>
<td><form:input path="Mobile_No"/></td>
</tr>
<tr>
<td>Email_ID: </td>
<td><form:input path="Email_ID"/></td>
</tr>
<tr>
<td>Schedule: </td>
<td><form:input path="Schedule"/></td>
</tr>
</table>
</form:form>

adddoctordetailsform:
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<h1>Add New Doctor_Details</h1>


<form:form method="POST" action="save">
<table>
<tr>
<td>Doctor_Id: </td>
<td><form:input path="Doctor_Id"/></td>
</tr>
<tr>
<td>Age: </td>
<td><form:input path="Age"/></td>
</tr>
<tr>
<td>Gender: </td>
<td><form:input path="Gender"/></td>
</tr>
<tr>
<td>Specialization: </td>
<td><form:input path="Specialization"/></td>
</tr>
<tr>
<td>Experience: </td>
<td><form:input path="Experience"/></td>
</tr>
<tr>
<td>Language: </td>
<td><form:input path="Language"/></td>
</tr>
<tr>
<td>Mobile_No: </td>
<td><form:input path="Mobile_No"/></td>
</tr>
<tr>
<td>Email_ID: </td>
<td><form:input path="Email_ID"/></td>
</tr>
<tr>
<td>Schedule: </td>
<td><form:input path="Schedule"/></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Save"/></td>
</tr>
</table>
</form:form>

viewdoctordetailsform:
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<h1>Employees List</h1>
<table border="2" width="70%" cellpadding="2">
<tr><th>Doctor_Id</th><th>Age</th><th>Gender</th><th>Experience</th><th>Language</
th><th>Mobile_No</th><th>Email_ID</th><th>Schedule</th><th>Edit</th></tr>
<c:forEach var="doctor_details" items="${list}">
<tr>
<td>${doctor_details.doctor_Id}</td>
<td>${doctor_details.age}</td>
<td>${doctor_details.gender}</td>
<td>${doctor_details.specialization}</td>
<td>${doctor_details.experience}</td>
<td>${doctor_details.language}</td>
<td>${doctor_details.mobile_No}</td>
<td>${doctor_details.email_ID}</td>
<td>${doctor_details.schedule}</td>
<td><a href="editdoctordetails/${doctor_details.doctor_Id}">Edit</a></td>
<td><a href="deletedoctordetails/${doctor_details.doctor_Id}">Delete</a></td>
</c:forEach>
</table>

You might also like