#3 -- Add term methods and model

This commit is contained in:
Anton Romanov 2023-09-11 19:23:27 +04:00
parent b88ed0211f
commit 8fbd17c63e
3 changed files with 94 additions and 0 deletions

View File

@ -6,6 +6,7 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import ru.ulstu.fc.rule.model.AddRuleForm;
import ru.ulstu.fc.rule.model.AddTermForm;
import ru.ulstu.fc.rule.service.RuleParseService;
import java.util.List;
@ -34,4 +35,16 @@ public class RuleController {
model.addAttribute("addRuleForm", addRuleForm);
return "listRules";
}
@GetMapping("addTerm")
public String addTerm(Model model) {
model.addAttribute("addTermForm", new AddTermForm());
return "addTerm";
}
@PostMapping("addTerm")
public String parse(@ModelAttribute AddTermForm addTermForm, Model model) {
model.addAttribute("addTermForm", addTermForm);
return "listTerms";
}
}

View File

@ -0,0 +1,40 @@
package ru.ulstu.fc.rule.model;
public class AddTermForm {
private String variable;
private String term;
private String min;
private String max;
public String getVariable() {
return variable;
}
public void setVariable(String variable) {
this.variable = variable;
}
public String getTerm() {
return term;
}
public void setTerm(String term) {
this.term = term;
}
public String getMin() {
return min;
}
public void setMin(String min) {
this.min = min;
}
public String getMax() {
return max;
}
public void setMax(String max) {
this.max = max;
}
}

View File

@ -0,0 +1,41 @@
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">
<html
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" xmlns:th="http://www.w3.org/1999/xhtml"
layout:decorate="~{default}">
<head>
<title>Простая обработка формы на Spring MVC</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<div class="container" layout:fragment="content">
<form action="/addTerm" th:object="${addTermForm}" method="post">
<div class="row">
<div class="col-md-2 col-sm-12">
<select id="select-variable" class="selectpicker m-2" data-live-search="true"
th:field="*{variable}"
data-width="90%">
<option th:each="var : ${variables}"
th:value="${var}"
th:utext="${var}">
</option>
</select>
</div>
<div class="col-md-2 col-sm-12">
<input class="form-control" type="text" th:field="*{term}">
</div>
<div class="col-md-2 col-sm-12">
<input class="form-control" type="text" th:field="*{min}">
</div>
<div class="col-md-2 col-sm-12">
<input class="form-control" type="text" th:field="*{max}">
</div>
</div>
<div class="row">
<div class="col-md-4 col-sm-12">
<input type="submit" class="btn btn-outline-success m-2" value="Создать term"/>
</div>
</div>
</form>
</div>
</html>