power_settings_new

how to add form to spring boot application?

by
asked
0 votes
44 views
I am working on a spring boot application. How do I add form to my view?

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.

1 Answer

answered by (171 points)
0 votes
Just follow instruction as below.

 

E.g. This is your form from jsp page.

 

<form method="post" action="/">
    <div>
        First name:
        <input type="text" name="firstName" th:field="*{firstName}"/>
    </div>
    <div>
        Last name:
        <input type="text" name="lastName" th:field="*{lastName}"/>
    </div>
    <div>
        SS Number:
        <input type="text" name="SSNumber" th:field="*{SSNumber}"/>
    </div>
    <div>
        <input type="submit"/>
    </div>
</form>

 

Your controller:

@RequestMapping(value = "/", method = RequestMethod.POST)
    public String eligibilityPost(
            @ModelAttribute("form") @Valid EligibilityModelsImpl form,
            BindingResult result, Model model) {
        eligibilityService.addEligibleUser(form);
        model.addAttribute("eligibilityModels", eligibilityService.getEligibilityList());
        return "eligibility";
    }

 

Let us know if you need more details.
add
...