Home > Blockchain >  Passing Hidden values upon clicking button Spring boot
Passing Hidden values upon clicking button Spring boot

Time:02-17

I have a list of patients displayed on the page using "<a href" tags. When a user clicks on one of the links I want it to redirect the user to another page called 'patientinfo' which displays all the information for that patient. I have hidden tags which have 'patientnumber' which will be used to get the information of that particular patient.

My question is how do I pass this hidden value into the controller upon clicking the "a href" link?

CodePudding user response:

As far as thymeleaf concerned, write your link as

<a th:href="@{/patientinfo/{id}(id = ${patientnumber})}">

which will generate the following html:

http://yourhost/patientinfo/1234 where 1234 is patient number.

Your controller would be similar to this:

    @GetMapping("/patientinfo/{id}")
    public String getPatientInfo(@PathVariable("id") int id, Model model) {
        // some service layer method calls
        return "patient_detail_view";
    }

CodePudding user response:

Change tag like this.

<a href="http://example.com/patientinfo/1234">

In your controller create like this.

@GetMapping(value = "/patientinfo/{patientId}")
public ResponseEntity<Object> getPatientInfo(@PathVariable Integer patientId)
{}
  • Related