Skip to content

Commit 99d9028

Browse files
vboyinavboyina
vboyina
authored and
vboyina
committed
SpringBoot CRUD COmmit
0 parents  commit 99d9028

File tree

112 files changed

+2071
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+2071
-0
lines changed
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
4+
org.eclipse.jdt.core.compiler.compliance=1.5
5+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
6+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
7+
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
8+
org.eclipse.jdt.core.compiler.source=1.5
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
activeProfiles=
2+
eclipse.preferences.version=1
3+
resolveWorkspaceProjects=true
4+
version=1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
2+
<wb-module deploy-name="springbootexample">
3+
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
4+
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
5+
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
6+
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
7+
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/test/java"/>
8+
<property name="context-root" value="springbootexample"/>
9+
<property name="java-output-path" value="/springbootexample/target/classes"/>
10+
</wb-module>
11+
</project-modules>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<faceted-project>
3+
<fixed facet="wst.jsdt.web"/>
4+
<installed facet="java" version="1.5"/>
5+
<installed facet="jst.web" version="2.3"/>
6+
<installed facet="wst.jsdt.web" version="1.0"/>
7+
</faceted-project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.eclipse.wst.jsdt.launching.baseBrowserLibrary
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Window
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
disabled=06target
2+
eclipse.preferences.version=1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Manifest-Version: 1.0
2+
Implementation-Title: springbootexample Maven Webapp
3+
Implementation-Version: 0.0.1-SNAPSHOT
4+
Built-By: vboyina
5+
Implementation-Vendor-Id: com.letstartcoding
6+
Build-Jdk: 1.8.0_161
7+
Implementation-URL: http://maven.apache.org
8+
Created-By: Maven Integration for Eclipse
9+
Implementation-Vendor: Pivotal Software, Inc.
10+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#Generated by Maven Integration for Eclipse
2+
#Tue Jan 30 11:28:31 SGT 2018
3+
version=0.0.1-SNAPSHOT
4+
groupId=com.letstartcoding
5+
m2e.projectName=springbootexample
6+
m2e.projectLocation=C\:\\GIt\\springbootexample
7+
artifactId=springbootexample
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.letstartcoding</groupId>
5+
<artifactId>springbootexample</artifactId>
6+
<packaging>war</packaging>
7+
<version>0.0.1-SNAPSHOT</version>
8+
<name>springbootexample Maven Webapp</name>
9+
<url>http://maven.apache.org</url>
10+
<parent>
11+
<groupId>org.springframework.boot</groupId>
12+
<artifactId>spring-boot-starter-parent</artifactId>
13+
<version>1.5.4.RELEASE</version>
14+
<relativePath/> <!-- lookup parent from repository -->
15+
</parent>
16+
<dependencies>
17+
<dependency>
18+
<groupId>junit</groupId>
19+
<artifactId>junit</artifactId>
20+
<version>3.8.1</version>
21+
<scope>test</scope>
22+
</dependency>
23+
24+
<dependency>
25+
<groupId>org.springframework.boot</groupId>
26+
<artifactId>spring-boot-starter-data-jpa</artifactId>
27+
</dependency>
28+
<dependency>
29+
<groupId>org.springframework.boot</groupId>
30+
<artifactId>spring-boot-starter-web</artifactId>
31+
</dependency>
32+
33+
<dependency>
34+
<groupId>org.apache.tomcat.embed</groupId>
35+
<artifactId>tomcat-embed-jasper</artifactId>
36+
<scope>provided</scope>
37+
</dependency>
38+
39+
<dependency>
40+
<groupId>org.springframework.boot</groupId>
41+
<artifactId>spring-boot-devtools</artifactId>
42+
<scope>runtime</scope>
43+
</dependency>
44+
45+
<dependency>
46+
<groupId>org.springframework.boot</groupId>
47+
<artifactId>spring-boot-starter-test</artifactId>
48+
<scope>test</scope>
49+
</dependency>
50+
51+
<!-- JSTL for JSP -->
52+
<dependency>
53+
<groupId>javax.servlet</groupId>
54+
<artifactId>jstl</artifactId>
55+
</dependency>
56+
57+
<dependency>
58+
<groupId>mysql</groupId>
59+
<artifactId>mysql-connector-java</artifactId>
60+
<scope>runtime</scope>
61+
</dependency>
62+
<dependency>
63+
<groupId>org.hibernate</groupId>
64+
<artifactId>hibernate-validator</artifactId>
65+
</dependency>
66+
67+
68+
69+
70+
</dependencies>
71+
<build>
72+
<finalName>springbootexample</finalName>
73+
</build>
74+
</project>

Diff for: springbootexample/pom.xml

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.letstartcoding</groupId>
5+
<artifactId>springbootexample</artifactId>
6+
<packaging>war</packaging>
7+
<version>0.0.1-SNAPSHOT</version>
8+
<name>springbootexample Maven Webapp</name>
9+
<url>http://maven.apache.org</url>
10+
<parent>
11+
<groupId>org.springframework.boot</groupId>
12+
<artifactId>spring-boot-starter-parent</artifactId>
13+
<version>1.5.4.RELEASE</version>
14+
<relativePath/> <!-- lookup parent from repository -->
15+
</parent>
16+
<dependencies>
17+
<dependency>
18+
<groupId>junit</groupId>
19+
<artifactId>junit</artifactId>
20+
<version>3.8.1</version>
21+
<scope>test</scope>
22+
</dependency>
23+
24+
<dependency>
25+
<groupId>org.springframework.boot</groupId>
26+
<artifactId>spring-boot-starter-data-jpa</artifactId>
27+
</dependency>
28+
<dependency>
29+
<groupId>org.springframework.boot</groupId>
30+
<artifactId>spring-boot-starter-web</artifactId>
31+
</dependency>
32+
33+
<dependency>
34+
<groupId>org.apache.tomcat.embed</groupId>
35+
<artifactId>tomcat-embed-jasper</artifactId>
36+
<scope>provided</scope>
37+
</dependency>
38+
39+
<dependency>
40+
<groupId>org.springframework.boot</groupId>
41+
<artifactId>spring-boot-devtools</artifactId>
42+
<scope>runtime</scope>
43+
</dependency>
44+
45+
<dependency>
46+
<groupId>org.springframework.boot</groupId>
47+
<artifactId>spring-boot-starter-test</artifactId>
48+
<scope>test</scope>
49+
</dependency>
50+
51+
<!-- JSTL for JSP -->
52+
<dependency>
53+
<groupId>javax.servlet</groupId>
54+
<artifactId>jstl</artifactId>
55+
</dependency>
56+
57+
<dependency>
58+
<groupId>mysql</groupId>
59+
<artifactId>mysql-connector-java</artifactId>
60+
<scope>runtime</scope>
61+
</dependency>
62+
<dependency>
63+
<groupId>org.hibernate</groupId>
64+
<artifactId>hibernate-validator</artifactId>
65+
</dependency>
66+
67+
68+
69+
70+
</dependencies>
71+
<build>
72+
<finalName>springbootexample</finalName>
73+
</build>
74+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.letstartcoding.springbootexample;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
6+
7+
8+
@SpringBootApplication
9+
@EnableJpaAuditing
10+
public class SudentEnrollmentApplication {
11+
12+
public static void main(String[] args) {
13+
14+
SpringApplication.run(SudentEnrollmentApplication.class, args);
15+
16+
}
17+
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
package com.letstartcoding.springbootexample.controller;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
import javax.validation.Valid;
7+
8+
import org.springframework.beans.factory.annotation.Autowired;
9+
import org.springframework.stereotype.Controller;
10+
import org.springframework.ui.ModelMap;
11+
import org.springframework.validation.BindingResult;
12+
import org.springframework.web.bind.annotation.ModelAttribute;
13+
import org.springframework.web.bind.annotation.PathVariable;
14+
import org.springframework.web.bind.annotation.RequestMapping;
15+
import org.springframework.web.bind.annotation.RequestMethod;
16+
import org.springframework.web.servlet.ModelAndView;
17+
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
18+
19+
import com.letstartcoding.springbootexample.model.Student;
20+
import com.letstartcoding.springbootexample.service.StudentService;
21+
22+
@Controller
23+
24+
public class StudentEnrollmentController {
25+
26+
@Autowired
27+
private StudentService studentService;
28+
29+
@RequestMapping(value ="/enroll",method = RequestMethod.GET)
30+
public String newRegistration(ModelMap model) {
31+
Student student = new Student();
32+
model.addAttribute("student", student);
33+
return "enroll";
34+
}
35+
36+
@RequestMapping(value ="/save",method = RequestMethod.POST)
37+
public String saveRegistration(@Valid Student student,
38+
BindingResult result, ModelMap model,RedirectAttributes redirectAttributes) {
39+
40+
if (result.hasErrors()) {
41+
return "enroll";//will redirect to viewemp request mapping
42+
}
43+
studentService.save(student);
44+
//redirectAttributes.addFlashAttribute("message", "Student " + student.getFirstName()+" "+student.getLastName() + " saved");
45+
return "redirect:/viewstudents/1";//will redirect to viewemp request mapping
46+
}
47+
48+
@RequestMapping("/viewstudents")
49+
public ModelAndView viewstudents(){
50+
List<Student> list=studentService.getAllStudents();
51+
return new ModelAndView("viewstudents","list",list);
52+
}
53+
54+
/* It opens the student list for the given page id */
55+
@RequestMapping(value="/viewstudents/{pageid}")
56+
public ModelAndView edit(@PathVariable int pageid){
57+
int total=2;
58+
if(pageid==1){}
59+
else{
60+
pageid=(pageid-1)*total+1;
61+
}
62+
List<Student> list=studentService.getStudentsByPage(pageid,total);
63+
64+
return new ModelAndView("viewstudents","list",list);
65+
}
66+
67+
/* It opens the record for the given id in editstudent page */
68+
@RequestMapping(value="/editstudent/{id}")
69+
public String edit(@PathVariable int id,ModelMap model){
70+
Student student=studentService.getStudentById(id);
71+
model.addAttribute("student", student);
72+
return "editstudent";
73+
74+
75+
}
76+
77+
/* It updates record for the given id in editstudent page and redirects to /viewstudents */
78+
@RequestMapping(value="/editsave",method = RequestMethod.POST)
79+
public ModelAndView editsave(@ModelAttribute("student") Student emp){
80+
System.out.println("id is"+emp.getId());
81+
studentService.update(emp);
82+
return new ModelAndView("redirect:/viewstudents/1");
83+
}
84+
85+
/* It deletes record for the given id and redirects to /viewstudents */
86+
@RequestMapping(value="/deletestudent/{id}",method = RequestMethod.GET)
87+
public ModelAndView delete(@PathVariable int id){
88+
studentService.delete(id);
89+
return new ModelAndView("redirect:/viewstudents/1");
90+
}
91+
92+
/* It deletes record for the given id and redirects to /viewstudents */
93+
@RequestMapping(value="/delete",method = RequestMethod.GET)
94+
public ModelAndView delete(){
95+
studentService.delete();
96+
return new ModelAndView("redirect:/enroll");
97+
}
98+
99+
@ModelAttribute("sections")
100+
public List<String> initializeSections() {
101+
102+
List<String> sections = new ArrayList<String>();
103+
sections.add("Graduate");
104+
sections.add("Post Graduate");
105+
sections.add("Research");
106+
return sections;
107+
}
108+
109+
/*
110+
* Method used to populate the country list in view. Note that here you can
111+
* call external systems to provide real data.
112+
*/
113+
@ModelAttribute("countries")
114+
public List<String> initializeCountries() {
115+
116+
List<String> countries = new ArrayList<String>();
117+
countries.add("INDIA");
118+
countries.add("USA");
119+
countries.add("CANADA");
120+
countries.add("FRANCE");
121+
countries.add("GERMANY");
122+
countries.add("ITALY");
123+
countries.add("OTHER");
124+
return countries;
125+
}
126+
127+
/*
128+
* Method used to populate the subjects list in view. Note that here you can
129+
* call external systems to provide real data.
130+
*/
131+
@ModelAttribute("subjects")
132+
public List<String> initializeSubjects() {
133+
134+
List<String> subjects = new ArrayList<String>();
135+
subjects.add("Physics");
136+
subjects.add("Chemistry");
137+
subjects.add("Life Science");
138+
subjects.add("Political Science");
139+
subjects.add("Computer Science");
140+
subjects.add("Mathmatics");
141+
return subjects;
142+
}
143+
144+
/*
145+
* Method used to populate the Section list in view. Note that here you can
146+
* call external systems to provide real data.
147+
*/
148+
@ModelAttribute("pageCount")
149+
public List<String> initializePageCount() {
150+
int total=2;
151+
List<String> pageCount = new ArrayList<String>();
152+
int count=studentService.count();
153+
int result=((count/total)+ (count%total));
154+
for(int k=0;k<result;k++) {
155+
pageCount.add(new Integer(k).toString());
156+
}
157+
158+
return pageCount;
159+
}
160+
161+
}

0 commit comments

Comments
 (0)