mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-29 18:23:23 +00:00
deps: Refactor dependencies (#3224)
* remove spring dep move junit, logging, mockito under dep mgmt * upgrade anti-corruption-layer deps * async method invocation * balking, bloc * bridge to bytecode * caching * callback - cqrs * component - health check * hexagonal - metadata mapping * rest of the patterns * remove checkstyle, take spotless into use
This commit is contained in:
@@ -30,10 +30,11 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
* Page Controller pattern is utilized when we want to simplify relationship in a dynamic website.
|
||||
* It is an approach of one front page leading to one logical file that handles HTTP requests and actions.
|
||||
* In this example, we build a website with signup page handling an input form with Signup Controller, Signup View, and Signup Model
|
||||
* and after signup, it is redirected to a user page handling with User Controller, User View, and User Model.
|
||||
*/
|
||||
* It is an approach of one front page leading to one logical file that handles HTTP requests and
|
||||
* actions. In this example, we build a website with signup page handling an input form with Signup
|
||||
* Controller, Signup View, and Signup Model and after signup, it is redirected to a user page
|
||||
* handling with User Controller, User View, and User Model.
|
||||
*/
|
||||
@Slf4j
|
||||
@SpringBootApplication
|
||||
public class App {
|
||||
|
||||
@@ -31,31 +31,23 @@ import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
||||
|
||||
/**
|
||||
* Signup Controller.
|
||||
*/
|
||||
/** Signup Controller. */
|
||||
@Slf4j
|
||||
@Controller
|
||||
@Component
|
||||
public class SignupController {
|
||||
SignupView view = new SignupView();
|
||||
/**
|
||||
* Signup Controller can handle http request and decide which model and view use.
|
||||
*/
|
||||
SignupController() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle http GET request.
|
||||
*/
|
||||
/** Signup Controller can handle http request and decide which model and view use. */
|
||||
SignupController() {}
|
||||
|
||||
/** Handle http GET request. */
|
||||
@GetMapping("/signup")
|
||||
public String getSignup() {
|
||||
return view.display();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle http POST request and access model and view.
|
||||
*/
|
||||
/** Handle http POST request and access model and view. */
|
||||
@PostMapping("/signup")
|
||||
public String create(SignupModel form, RedirectAttributes redirectAttributes) {
|
||||
LOGGER.info(form.getName());
|
||||
|
||||
@@ -28,9 +28,7 @@ import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* ignup model.
|
||||
*/
|
||||
/** ignup model. */
|
||||
@Component
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@@ -38,5 +36,4 @@ public class SignupModel {
|
||||
private String name;
|
||||
private String email;
|
||||
private String password;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,9 +27,7 @@ package com.iluwatar.page.controller;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* Signup View.
|
||||
*/
|
||||
/** Signup View. */
|
||||
@Slf4j
|
||||
@NoArgsConstructor
|
||||
public class SignupView {
|
||||
@@ -39,11 +37,10 @@ public class SignupView {
|
||||
return "/signup";
|
||||
}
|
||||
|
||||
/**
|
||||
* redirect to user page.
|
||||
*/
|
||||
/** redirect to user page. */
|
||||
public String redirect(SignupModel form) {
|
||||
LOGGER.info("Redirect to user page with " + "name " + form.getName() + " email " + form.getEmail());
|
||||
LOGGER.info(
|
||||
"Redirect to user page with " + "name " + form.getName() + " email " + form.getEmail());
|
||||
return "redirect:/user";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,22 +30,18 @@ import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
/**
|
||||
* User Controller.
|
||||
*/
|
||||
/** User Controller. */
|
||||
@Slf4j
|
||||
@Controller
|
||||
@NoArgsConstructor
|
||||
public class UserController {
|
||||
private final UserView view = new UserView();
|
||||
|
||||
/**
|
||||
* Handle http GET request and access view and model.
|
||||
*/
|
||||
/** Handle http GET request and access view and model. */
|
||||
@GetMapping("/user")
|
||||
public String getUserPath(SignupModel form, Model model) {
|
||||
model.addAttribute("name", form.getName());
|
||||
model.addAttribute("email", form.getEmail());
|
||||
return view.display(form);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,13 +27,10 @@ package com.iluwatar.page.controller;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* User model.
|
||||
*/
|
||||
/** User model. */
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class UserModel {
|
||||
private String name;
|
||||
private String email;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,13 +26,12 @@ package com.iluwatar.page.controller;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* User view class generating html file.
|
||||
*/
|
||||
/** User view class generating html file. */
|
||||
@Slf4j
|
||||
public class UserView {
|
||||
/**
|
||||
* displaying command to generate html.
|
||||
*
|
||||
* @param user model content.
|
||||
*/
|
||||
public String display(SignupModel user) {
|
||||
|
||||
Reference in New Issue
Block a user