Skip to content

Instantly share code, notes, and snippets.

@pethaniakshay
Last active April 27, 2019 08:45
Show Gist options
  • Save pethaniakshay/e3a1b779626b271a6b0d0837219dd378 to your computer and use it in GitHub Desktop.
Save pethaniakshay/e3a1b779626b271a6b0d0837219dd378 to your computer and use it in GitHub Desktop.
package com.codepuran.dto;
import java.util.List;
public class ResponseMessageDto {
private Integer port;
private List<Student> students;
public Integer getPort() {
return port;
}
public void setPort(Integer port) {
this.port = port;
}
public List<Student> getStudents() {
return students;
}
public void setStudents(List<Student> students) {
this.students = students;
}
public ResponseMessageDto(Integer port, List<Student> students) {
super();
this.port = port;
this.students = students;
}
}
package com.codepuran.dto;
public class Student {
private Long id;
private String name;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Student(Long id, String name) {
super();
this.id = id;
this.name = name;
}
}
package com.codepuran.controller;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import com.codepuran.dto.ResponseMessageDto;
import com.codepuran.dto.Student;
@RestController
public class UserController {
@GetMapping("/students")
public ResponseEntity<?> getAllStudent(HttpServletRequest request) {
request.getLocalPort();
List<Student> students = new ArrayList<>();
students.add(new Student(1l, "Akshay"));
students.add(new Student(2l, "Karan"));
students.add(new Student(3l, "Hasmukh"));
students.add(new Student(4l, "Keyur"));
students.add(new Student(5l, "Prashant"));
return ResponseEntity.ok(new ResponseMessageDto(request.getLocalPort(), students));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment