1+ package com .example .springmvcdocker ;
2+
3+ import org .springframework .stereotype .Controller ;
4+ import org .springframework .ui .Model ;
5+ import org .springframework .web .bind .annotation .GetMapping ;
6+ import org .springframework .web .bind .annotation .PostMapping ;
7+ import org .springframework .web .bind .annotation .RequestParam ;
8+ import org .springframework .web .bind .annotation .RequestMapping ;
9+
10+ @ Controller
11+ public class FormController {
12+
13+ @ GetMapping ("/" )
14+ public String showForm () {
15+ return "index" ;
16+ }
17+
18+ @ PostMapping ("/process" )
19+ public String processForm (
20+ @ RequestParam ("a" ) int a ,
21+ @ RequestParam ("b" ) int b ,
22+ @ RequestParam ("c" ) int c )
23+ {
24+ int value = TriangleClassification .classify (a , b , c );
25+ String triangleType = getTriangleType (value );
26+ return "redirect:/" + triangleType .toLowerCase ().replace (" " , "-" );
27+ }
28+
29+ @ RequestMapping ("/not-a-triangle" )
30+ public String notATriangle (Model model ) {
31+ model .addAttribute ("output" , "The input does not form a triangle." );
32+ return "notTriangle" ;
33+ }
34+
35+ @ RequestMapping ("/scalene-triangle" )
36+ public String scaleneTriangle (Model model ) {
37+ model .addAttribute ("output" , "This is a Scalene triangle." );
38+ return "scalene" ;
39+ }
40+
41+ @ RequestMapping ("/isosceles-triangle" )
42+ public String isoscelesTriangle (Model model ) {
43+ model .addAttribute ("output" , "This is an Isosceles triangle." );
44+ return "isosceles" ;
45+ }
46+
47+ @ RequestMapping ("/equilateral-triangle" )
48+ public String equilateralTriangle (Model model ) {
49+ model .addAttribute ("output" , "This is an Equilateral triangle." );
50+ return "equilateral" ;
51+ }
52+
53+ public static String getTriangleType (int value ) {
54+ switch (value ) {
55+ case 0 : return "Not a triangle" ;
56+ case 1 : return "Scalene triangle" ;
57+ case 2 : return "Isosceles triangle" ;
58+ case 3 : return "Equilateral triangle" ;
59+ default : return "Invalid input" ;
60+ }
61+ }
62+ }
0 commit comments