Skip to content

Commit 2113974

Browse files
author
Grzegorz Piwowarek
committed
Refactor spring-controller
1 parent 0f6218e commit 2113974

17 files changed

Lines changed: 296 additions & 426 deletions

File tree

‎pom.xml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
<module>spring-apache-camel</module>
4343
<module>spring-batch</module>
4444
<module>spring-boot</module>
45+
<module>spring-controller</module>
4546
<module>spring-data-cassandra</module>
4647
<module>spring-data-elasticsearch</module>
4748
<module>spring-data-mongodb</module>

‎spring-batch/.classpath‎

Lines changed: 0 additions & 31 deletions
This file was deleted.

‎spring-batch/.project‎

Lines changed: 0 additions & 29 deletions
This file was deleted.
Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,56 @@
1-
<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/xsd/maven-4.0.0.xsd">
2-
<modelVersion>4.0.0</modelVersion>
3-
<groupId>test</groupId>
4-
<artifactId>test-mvc</artifactId>
5-
<version>0.0.1-SNAPSHOT</version>
6-
<packaging>war</packaging>
7-
8-
<dependencies>
9-
<dependency>
10-
<groupId>org.springframework</groupId>
11-
<artifactId>spring-webmvc</artifactId>
12-
<version>4.3.0.RELEASE</version>
13-
14-
</dependency>
15-
<dependency>
16-
<groupId>javax.servlet</groupId>
17-
<artifactId>javax.servlet-api</artifactId>
18-
<version>3.0.1</version>
19-
<scope>compile</scope>
20-
</dependency>
21-
<dependency>
22-
<groupId>com.fasterxml.jackson.core</groupId>
23-
<artifactId>jackson-databind</artifactId>
24-
<version>2.6.3</version>
25-
</dependency>
26-
<dependency>
27-
<groupId>com.fasterxml.jackson.core</groupId>
28-
<artifactId>jackson-annotations</artifactId>
29-
<version>2.6.3</version>
30-
</dependency>
31-
<dependency>
32-
<groupId>com.fasterxml.jackson.core</groupId>
33-
<artifactId>jackson-core</artifactId>
34-
<version>2.6.3</version>
35-
</dependency>
36-
<dependency>
37-
<groupId>org.springframework</groupId>
38-
<artifactId>spring-web</artifactId>
39-
<version>4.3.0.RELEASE</version>
40-
</dependency>
41-
42-
<dependency>
43-
<groupId>junit</groupId>
44-
<artifactId>junit</artifactId>
45-
<version>4.12</version>
46-
<scope>test</scope>
47-
</dependency>
48-
<dependency>
49-
<groupId>org.springframework</groupId>
50-
<artifactId>spring-test</artifactId>
51-
<version>4.1.7.RELEASE</version>
52-
</dependency>
53-
54-
</dependencies>
55-
1+
<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/xsd/maven-4.0.0.xsd">
2+
<modelVersion>4.0.0</modelVersion>
3+
<groupId>test</groupId>
4+
<artifactId>spring-controller</artifactId>
5+
<version>0.0.1-SNAPSHOT</version>
6+
<packaging>war</packaging>
7+
8+
<dependencies>
9+
<dependency>
10+
<groupId>org.springframework</groupId>
11+
<artifactId>spring-webmvc</artifactId>
12+
<version>4.3.0.RELEASE</version>
13+
14+
</dependency>
15+
<dependency>
16+
<groupId>javax.servlet</groupId>
17+
<artifactId>javax.servlet-api</artifactId>
18+
<version>3.0.1</version>
19+
<scope>compile</scope>
20+
</dependency>
21+
<dependency>
22+
<groupId>com.fasterxml.jackson.core</groupId>
23+
<artifactId>jackson-databind</artifactId>
24+
<version>2.6.3</version>
25+
</dependency>
26+
<dependency>
27+
<groupId>com.fasterxml.jackson.core</groupId>
28+
<artifactId>jackson-annotations</artifactId>
29+
<version>2.6.3</version>
30+
</dependency>
31+
<dependency>
32+
<groupId>com.fasterxml.jackson.core</groupId>
33+
<artifactId>jackson-core</artifactId>
34+
<version>2.6.3</version>
35+
</dependency>
36+
<dependency>
37+
<groupId>org.springframework</groupId>
38+
<artifactId>spring-web</artifactId>
39+
<version>4.3.0.RELEASE</version>
40+
</dependency>
41+
42+
<dependency>
43+
<groupId>junit</groupId>
44+
<artifactId>junit</artifactId>
45+
<version>4.12</version>
46+
<scope>test</scope>
47+
</dependency>
48+
<dependency>
49+
<groupId>org.springframework</groupId>
50+
<artifactId>spring-test</artifactId>
51+
<version>4.2.6.RELEASE</version>
52+
</dependency>
53+
54+
</dependencies>
55+
5656
</project>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.baledung.controller;
2+
3+
import com.baledung.student.Student;
4+
import org.springframework.web.bind.annotation.GetMapping;
5+
import org.springframework.web.bind.annotation.PathVariable;
6+
import org.springframework.web.bind.annotation.RestController;
7+
8+
@RestController
9+
public class RestAnnotatedController {
10+
11+
@GetMapping(value = "/annotated/student/{studentId}")
12+
public Student getData(@PathVariable Integer studentId) {
13+
Student student = new Student();
14+
student.setName("Peter");
15+
student.setId(studentId);
16+
17+
return student;
18+
}
19+
}

spring_controller/src/main/java/com/baledung/controller/RestController.java renamed to spring-controller/src/main/java/com/baledung/controller/RestController.java

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,21 @@
1-
package com.baledung.controller;
2-
3-
import org.springframework.stereotype.Controller;
4-
import org.springframework.web.bind.annotation.PathVariable;
5-
import org.springframework.web.bind.annotation.RequestMapping;
6-
import org.springframework.web.bind.annotation.RequestMethod;
7-
import org.springframework.web.bind.annotation.ResponseBody;
8-
9-
import com.baledung.student.Student;
10-
11-
@Controller
12-
public class RestController{
13-
14-
/**
15-
* Get a student based on the id of the student
16-
* specified in path variable {studentId}
17-
* @param studentId
18-
* @return
19-
*/
20-
@RequestMapping(value="/student/{studentId}",method=RequestMethod.GET)
21-
public @ResponseBody Student getTestData(@PathVariable Integer studentId)
22-
{
23-
Student student = new Student();
24-
student.setName("Peter");
25-
student.setId(studentId);
26-
27-
return student;
28-
29-
}
30-
}
1+
package com.baledung.controller;
2+
3+
import com.baledung.student.Student;
4+
import org.springframework.stereotype.Controller;
5+
import org.springframework.web.bind.annotation.GetMapping;
6+
import org.springframework.web.bind.annotation.PathVariable;
7+
import org.springframework.web.bind.annotation.ResponseBody;
8+
9+
@Controller
10+
public class RestController{
11+
12+
@GetMapping(value="/student/{studentId}")
13+
public @ResponseBody Student getTestData(@PathVariable Integer studentId) {
14+
Student student = new Student();
15+
student.setName("Peter");
16+
student.setId(studentId);
17+
18+
return student;
19+
20+
}
21+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
/**
3+
* @author Prashant Dutta
4+
*/
5+
package com.baledung.controller;
6+
7+
import org.springframework.stereotype.Controller;
8+
import org.springframework.web.bind.annotation.GetMapping;
9+
import org.springframework.web.bind.annotation.RequestMapping;
10+
import org.springframework.web.servlet.ModelAndView;
11+
12+
@Controller
13+
@RequestMapping(value = "/test")
14+
public class TestController {
15+
16+
@GetMapping
17+
public ModelAndView getTestData() {
18+
ModelAndView mv = new ModelAndView();
19+
mv.setViewName("welcome");
20+
mv.getModel().put("data", "Welcome home man");
21+
22+
return mv;
23+
}
24+
}

spring_controller/src/main/java/com/baledung/student/Student.java renamed to spring-controller/src/main/java/com/baledung/student/Student.java

Lines changed: 32 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,33 @@
1-
/**
2-
*
3-
*/
4-
package com.baledung.student;
5-
6-
public class Student
7-
{
8-
private String name;
9-
10-
private int id;
11-
12-
//----------------------------- getters and setters--------------------------------------------------------
13-
public String getName() {
14-
return name;
15-
}
16-
17-
public void setName(String name) {
18-
this.name = name;
19-
}
20-
21-
public int getId() {
22-
return id;
23-
}
24-
25-
public void setId(int id) {
26-
this.id = id;
27-
}
28-
29-
@Override
30-
public int hashCode(){
31-
return this.id;
32-
}
33-
34-
@Override
35-
public boolean equals(Object obj){
36-
return this.name.equals(((Student)obj).getName());
37-
}
38-
39-
1+
package com.baledung.student;
2+
3+
public class Student {
4+
private String name;
5+
6+
private int id;
7+
8+
public String getName() {
9+
return name;
10+
}
11+
12+
public void setName(String name) {
13+
this.name = name;
14+
}
15+
16+
public int getId() {
17+
return id;
18+
}
19+
20+
public void setId(int id) {
21+
this.id = id;
22+
}
23+
24+
@Override
25+
public int hashCode(){
26+
return this.id;
27+
}
28+
29+
@Override
30+
public boolean equals(Object obj){
31+
return this.name.equals(((Student)obj).getName());
32+
}
4033
}

0 commit comments

Comments
 (0)