Skip to content

Instantly share code, notes, and snippets.

@GerritRiesch94
Last active March 28, 2023 13:28
Show Gist options
  • Save GerritRiesch94/265f1581d8ba60684223a55afd10ae25 to your computer and use it in GitHub Desktop.
Save GerritRiesch94/265f1581d8ba60684223a55afd10ae25 to your computer and use it in GitHub Desktop.
App Controller Spring Boot Example
package com.example.example.api;
import com.example.example.service.AppService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/api/data")
public class AppController {
private final AppService appService;
public AppController(AppService appService) {
this.appService = appService;
}
@GetMapping("/{id}")
public ResponseEntity<List<String>> getData(@PathVariable String id, @RequestParam Integer skip, @RequestParam Integer top) {
// should represent a database service, api call, etc.
var data = this.appService.searchForIdAndPaginate(id, skip, top);
if (!data.isEmpty()) {
return ResponseEntity.ok(data);
} else {
return ResponseEntity.noContent().build();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment