Skip to content

Commit c33d944

Browse files
Ranga Rao KaranamRanga Rao Karanam
Ranga Rao Karanam
authored and
Ranga Rao Karanam
committed
first commit
0 parents  commit c33d944

Some content is hidden

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

43 files changed

+1728
-0
lines changed

Diff for: .gitignore

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Compiled class file
2+
*.class
3+
4+
# Log file
5+
*.log
6+
7+
# BlueJ files
8+
*.ctxt
9+
10+
# Mobile Tools for Java (J2ME)
11+
.mtj.tmp/
12+
13+
# Package Files #
14+
*.jar
15+
*.war
16+
*.ear
17+
*.zip
18+
*.tar.gz
19+
*.rar
20+
*.cmd
21+
*.classpath
22+
*.settings
23+
*.project
24+
*.mvn
25+
mvnw
26+
target
27+
*.DS_Store
28+
29+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
30+
hs_err_pid*
31+
bin

Diff for: README.md

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Spring Boot Code Examples
2+
All code examples for our website http://www.springboottutorial.com
3+
4+
For the best offers on our courses, Join our 15K Subscribers [here](http://eepurl.com/bOJulL).
5+
6+
## Installing Tools
7+
- Eclipse & Embedded Maven
8+
- PostMan
9+
10+
### Installing Eclipse & Embedded Maven
11+
- Installation Video : https://www.youtube.com/playlist?list=PLBBog2r6uMCSmMVTW_QmDLyASBvovyAO3
12+
- GIT Repository For Installation : https://github.com/in28minutes/getting-started-in-5-steps
13+
- PDF : https://github.com/in28minutes/SpringIn28Minutes/blob/master/InstallationGuide-JavaEclipseAndMaven_v2.pdf
14+
15+
## Running Examples
16+
- Download the zip or clone the Git repository.
17+
- Unzip the zip file (if you downloaded one)
18+
- Open Command Prompt and Change directory (cd) to folder containing pom.xml
19+
- Open Eclipse
20+
- File -> Import -> Existing Maven Project -> Navigate to the folder where you unzipped the zip
21+
- Select the right project
22+
- Choose the Spring Boot Application file (search for @SpringBootApplication)
23+
- Right Click on the file and Run as Java Application
24+
- You are all Set
25+
- For help : use our installation guide - https://www.youtube.com/playlist?list=PLBBog2r6uMCSmMVTW_QmDLyASBvovyAO3
26+
27+
### Useful Links
28+
- For the best offers on our courses, Join our 15K Subscribers [here](http://eepurl.com/bOJulL)
29+
- Facebook : https://www.facebook.com/in28Minutes​
30+
- Twitter : https://twitter.com/in28Minutes​
31+
- YouTube : https://www.youtube.com/rithustutorials​
32+
​ - Instagram : https://www.instagram.com/in28minutes/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.in28minutes.springboot</groupId>
7+
<artifactId>student-services</artifactId>
8+
<version>0.0.1-SNAPSHOT</version>
9+
<packaging>jar</packaging>
10+
11+
<name>student-services</name>
12+
<description>Demo project for Spring Boot</description>
13+
14+
<parent>
15+
<groupId>org.springframework.boot</groupId>
16+
<artifactId>spring-boot-starter-parent</artifactId>
17+
<version>1.4.4.RELEASE</version>
18+
<relativePath/> <!-- lookup parent from repository -->
19+
</parent>
20+
21+
<properties>
22+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
24+
<java.version>1.8</java.version>
25+
</properties>
26+
27+
<dependencies>
28+
<dependency>
29+
<groupId>org.springframework.boot</groupId>
30+
<artifactId>spring-boot-starter-actuator</artifactId>
31+
</dependency>
32+
<dependency>
33+
<groupId>org.springframework.boot</groupId>
34+
<artifactId>spring-boot-starter-web</artifactId>
35+
</dependency>
36+
37+
<dependency>
38+
<groupId>org.springframework.boot</groupId>
39+
<artifactId>spring-boot-devtools</artifactId>
40+
<scope>runtime</scope>
41+
</dependency>
42+
<dependency>
43+
<groupId>org.springframework.boot</groupId>
44+
<artifactId>spring-boot-starter-test</artifactId>
45+
<scope>test</scope>
46+
</dependency>
47+
</dependencies>
48+
49+
<build>
50+
<plugins>
51+
<plugin>
52+
<groupId>org.springframework.boot</groupId>
53+
<artifactId>spring-boot-maven-plugin</artifactId>
54+
</plugin>
55+
</plugins>
56+
</build>
57+
58+
59+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.in28minutes.springboot;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class StudentServicesApplication {
8+
9+
public static void main(String[] args) {
10+
SpringApplication.run(StudentServicesApplication.class, args);
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.in28minutes.springboot.controller;
2+
3+
import java.net.URI;
4+
import java.util.List;
5+
6+
import org.springframework.beans.factory.annotation.Autowired;
7+
import org.springframework.http.ResponseEntity;
8+
import org.springframework.web.bind.annotation.GetMapping;
9+
import org.springframework.web.bind.annotation.PathVariable;
10+
import org.springframework.web.bind.annotation.PostMapping;
11+
import org.springframework.web.bind.annotation.RequestBody;
12+
import org.springframework.web.bind.annotation.RestController;
13+
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
14+
15+
import com.in28minutes.springboot.model.Course;
16+
import com.in28minutes.springboot.service.StudentService;
17+
18+
@RestController
19+
public class StudentController {
20+
21+
@Autowired
22+
private StudentService studentService;
23+
24+
@GetMapping("/students/{studentId}/courses")
25+
public List<Course> retrieveCoursesForStudent(@PathVariable String studentId) {
26+
return studentService.retrieveCourses(studentId);
27+
}
28+
29+
@GetMapping("/students/{studentId}/courses/{courseId}")
30+
public Course retrieveDetailsForCourse(@PathVariable String studentId,
31+
@PathVariable String courseId) {
32+
return studentService.retrieveCourse(studentId, courseId);
33+
}
34+
35+
@PostMapping("/students/{studentId}/courses")
36+
public ResponseEntity<Void> registerStudentForCourse(
37+
@PathVariable String studentId, @RequestBody Course newCourse) {
38+
39+
Course course = studentService.addCourse(studentId, newCourse);
40+
41+
if (course == null)
42+
return ResponseEntity.noContent().build();
43+
44+
URI location = ServletUriComponentsBuilder.fromCurrentRequest().path(
45+
"/{id}").buildAndExpand(course.getId()).toUri();
46+
47+
return ResponseEntity.created(location).build();
48+
}
49+
50+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package com.in28minutes.springboot.model;
2+
3+
import java.util.List;
4+
5+
public class Course {
6+
private String id;
7+
private String name;
8+
private String description;
9+
private List<String> steps;
10+
11+
// Needed by Caused by: com.fasterxml.jackson.databind.JsonMappingException:
12+
// Can not construct instance of com.in28minutes.springboot.model.Course:
13+
// no suitable constructor found, can not deserialize from Object value
14+
// (missing default constructor or creator, or perhaps need to add/enable
15+
// type information?)
16+
public Course() {
17+
18+
}
19+
20+
public Course(String id, String name, String description, List<String> steps) {
21+
super();
22+
this.id = id;
23+
this.name = name;
24+
this.description = description;
25+
this.steps = steps;
26+
}
27+
28+
public String getId() {
29+
return id;
30+
}
31+
32+
public void setId(String id) {
33+
this.id = id;
34+
}
35+
36+
public String getDescription() {
37+
return description;
38+
}
39+
40+
public String getName() {
41+
return name;
42+
}
43+
44+
public List<String> getSteps() {
45+
return steps;
46+
}
47+
48+
@Override
49+
public String toString() {
50+
return String.format(
51+
"Course [id=%s, name=%s, description=%s, steps=%s]", id, name,
52+
description, steps);
53+
}
54+
55+
@Override
56+
public int hashCode() {
57+
final int prime = 31;
58+
int result = 1;
59+
result = prime * result + ((id == null) ? 0 : id.hashCode());
60+
return result;
61+
}
62+
63+
@Override
64+
public boolean equals(Object obj) {
65+
if (this == obj)
66+
return true;
67+
if (obj == null)
68+
return false;
69+
if (getClass() != obj.getClass())
70+
return false;
71+
Course other = (Course) obj;
72+
if (id == null) {
73+
if (other.id != null)
74+
return false;
75+
} else if (!id.equals(other.id))
76+
return false;
77+
return true;
78+
}
79+
80+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package com.in28minutes.springboot.model;
2+
3+
import java.util.List;
4+
5+
public class Student {
6+
private String id;
7+
private String name;
8+
private String description;
9+
private List<Course> courses;
10+
11+
public Student(String id, String name, String description,
12+
List<Course> courses) {
13+
super();
14+
this.id = id;
15+
this.name = name;
16+
this.description = description;
17+
this.courses = courses;
18+
}
19+
20+
public String getId() {
21+
return id;
22+
}
23+
24+
public void setId(String id) {
25+
this.id = id;
26+
}
27+
28+
public String getName() {
29+
return name;
30+
}
31+
32+
public void setName(String name) {
33+
this.name = name;
34+
}
35+
36+
public String getDescription() {
37+
return description;
38+
}
39+
40+
public void setDescription(String description) {
41+
this.description = description;
42+
}
43+
44+
public List<Course> getCourses() {
45+
return courses;
46+
}
47+
48+
public void setCourses(List<Course> courses) {
49+
this.courses = courses;
50+
}
51+
52+
@Override
53+
public String toString() {
54+
return String.format(
55+
"Student [id=%s, name=%s, description=%s, courses=%s]", id,
56+
name, description, courses);
57+
}
58+
}

0 commit comments

Comments
 (0)