Move spring-controller to spring-all
This commit is contained in:
+19
@@ -0,0 +1,19 @@
|
||||
package org.baeldung.controller.controller;
|
||||
|
||||
import org.baeldung.controller.student.Student;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
public class RestAnnotatedController {
|
||||
|
||||
@GetMapping(value = "/annotated/student/{studentId}")
|
||||
public Student getData(@PathVariable Integer studentId) {
|
||||
Student student = new Student();
|
||||
student.setName("Peter");
|
||||
student.setId(studentId);
|
||||
|
||||
return student;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package org.baeldung.controller.controller;
|
||||
|
||||
import org.baeldung.controller.student.Student;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
@Controller
|
||||
public class RestController{
|
||||
|
||||
@GetMapping(value="/student/{studentId}")
|
||||
public @ResponseBody Student getTestData(@PathVariable Integer studentId) {
|
||||
Student student = new Student();
|
||||
student.setName("Peter");
|
||||
student.setId(studentId);
|
||||
|
||||
return student;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
|
||||
/**
|
||||
* @author Prashant Dutta
|
||||
*/
|
||||
package org.baeldung.controller.controller;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
@Controller
|
||||
@RequestMapping(value = "/test")
|
||||
public class TestController {
|
||||
|
||||
@GetMapping
|
||||
public ModelAndView getTestData() {
|
||||
ModelAndView mv = new ModelAndView();
|
||||
mv.setViewName("welcome");
|
||||
mv.getModel().put("data", "Welcome home man");
|
||||
|
||||
return mv;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package org.baeldung.controller.student;
|
||||
|
||||
public class Student {
|
||||
private String name;
|
||||
|
||||
private int id;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode(){
|
||||
return this.id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj){
|
||||
return this.name.equals(((Student)obj).getName());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user