This tutorial provides the typical steps in migrating a Spring Web MVC Controller to avoid dependency on Spring. It also enables simpler code that can take advantage of all the OfficeFloor features.
The Spring Web MVC Controller to be migrated is taken from the previous tutorial:
@RestController @RequestMapping("/rest") public class SpringRestController { @Autowired private SpringDependency dependency; @GetMapping public ResponseModel get() { return new ResponseModel("GET " + this.dependency.getMessage()); } @GetMapping("/path/{param}") public ResponseModel path(@PathVariable String param) { return new ResponseModel(param); } @PostMapping("/update") public ResponseModel post(@RequestBody RequestModel request) { return new ResponseModel(request.getInput()); } }
To migrate a Spring Web MVC Controller:
The resulting migrated code is as follows:
public class MigratedRestController { public void get(SpringDependency dependency, ObjectResponse<ResponseModel> response) { response.send(new ResponseModel("GET " + dependency.getMessage())); } public void path(@HttpPathParameter("param") String param, ObjectResponse<ResponseModel> response) { response.send(new ResponseModel(param)); } public void post(RequestModel request, ObjectResponse<ResponseModel> response) { response.send(new ResponseModel(request.getInput())); } }
The Spring web page is again taken from the previous tutorial:
@Controller public class SpringController { @GetMapping("/html") public String html(@RequestParam String name, Model model) { model.addAttribute("name", name); return "simple"; } }
<html><body><p th:text="'Hello ' + ${name}" /></body></html>
To migrate the web page, can either:
The rewritten WoOF logic object and template are as follows:
public class MigratedController { @Value public static class Model { private String name; } public Model getTemplate(@HttpQueryParameter("name") String name) { return new Model(name); } }
<html><body><p >Hello ${name}</p></body></html>
The next tutorial covers migrating Spring Web Flux to WoOF.