BAEL-4783 rename module and fix indents

This commit is contained in:
Trixi Turny
2021-04-19 20:25:33 +01:00
parent c49ffcc3cd
commit af9cc0deb9
21 changed files with 792 additions and 0 deletions
@@ -0,0 +1,13 @@
package com.baeldung.cucumber_tags;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
@@ -0,0 +1,17 @@
package com.baeldung.cucumber_tags.controller;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HealthController {
@RequestMapping(value="/status", produces= MediaType.APPLICATION_JSON_VALUE)
public HttpStatus statusCheck() {
return ResponseEntity.ok().build().getStatusCode();
}
}
@@ -0,0 +1,36 @@
package com.baeldung.cucumber_tags.controller;
import com.baeldung.cucumber_tags.service.RandomNumberGeneratorService;
import lombok.Data;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
@Controller
public class UiController {
@GetMapping("/random-number-generator")
public String showForm(Model model) {
RandomNumberQuery randomNumberQuery = new RandomNumberQuery();
model.addAttribute("randomNumberQuery", randomNumberQuery);
return "random-number-generator";
}
@PostMapping(value = "/random-number-generator")
public String generateRandomNumber(@ModelAttribute("randomNumberQuery") final RandomNumberQuery randomNumberQuery) {
RandomNumberGeneratorService service = new RandomNumberGeneratorService();
randomNumberQuery.randomNumber = service.generateRandomNumber(randomNumberQuery.min, randomNumberQuery.max);
return "random-number-generator";
}
@Data
private static class RandomNumberQuery {
Integer min = null;
Integer max = null;
Integer randomNumber = null;
}
}
@@ -0,0 +1,10 @@
package com.baeldung.cucumber_tags.service;
import java.util.concurrent.ThreadLocalRandom;
public class RandomNumberGeneratorService {
public int generateRandomNumber(int min, int max) {
return ThreadLocalRandom.current().nextInt(min, max + 1);
}
}
@@ -0,0 +1,53 @@
<!DOCTYPE HTML>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Random Number Generator</title>
<link rel="stylesheet" th:href="@{webjars/bootstrap/css/bootstrap.min.css}"/>
</head>
<body>
<nav class="navbar navbar-light bg-light">
<div class="container">
<h1 class="navbar-brand mb-10 h1">Random Number Generator</h1>
</div>
</nav>
<div role="main" class="container">
<div>
<form id="random" name="random" action="#" th:action="@{/random-number-generator}"
th:object="${randomNumberQuery}" method="post">
<div class="row mt-10">
<label for="min" class="col-sm-1 control-label">Min:</label>
<div class="col-sm-3">
<input type="text" id="min" class="form-control" th:field="*{min}" placeholder="min" required
autofocus>
</div>
<label for="max" class="col-sm-1 control-label">Max:</label>
<div class="col-sm-3">
<input type="text" id="max" class="form-control" th:field="*{max}" placeholder="max" required
autofocus>
</div>
<div class="col-sm-3">
<button id="generate" type="submit" class="btn btn-primary">Generate</button>
</div>
</div>
</form>
<div class="row mt-10">
<p>Result: </p>
<p id="result" class="display-1 font-weight-bold" th:text="${randomNumberQuery.randomNumber}"></p>
</div>
<script type="text/javascript" th:src="@{webjars/bootstrap/js/bootstrap.min.js}"></script>
</div>
</div>
</body>
</html>