'How to access spring RequestMethod

Q1. Why it's not forwarding to form.html

<a class="btn btn-primary btn-sm" href="form.html" th:href="@{/(form)}">Create Topic</a>

@GetMapping(params = "form")
  public String createForm(@ModelAttribute Topic topic) {
  return "redirect:/messages/form";
}

it returns me the string, not the form.html

Q2. How can I access these methods?

@RequestMapping(method=RequestMethod.PUT, value="/topics/{id}")
public void updateTopic(@RequestBody Topic topic, @PathVariable String id) {
    topicService.updateTopic(id, topic);
}
@RequestMapping(method=RequestMethod.DELETE, value="/topics/{id}")
public void deleteTopic(@PathVariable String id) {
    topicService.deleteTopic(id);
}

<a href="topic.html" th:href="@{'/topics/' + ${topic.id}}">delete</a>
<a href="form.html" th:href="@{'/topics/' + ${topic.id}}"> modify</a>


Solution 1:[1]

More details required for your question 1

Can you add the details what error are you getting? And do you have a url /messages/form in your application's code here:-

@GetMapping(params = "form")
    public String createForm(@ModelAttribute Topic topic) {
    return "redirect:/messages/form";
}

Answer to your question 2:-

You cannot use anything other than HTTP GET in your hyperlinks for anchor tags

For performing tasks other than GET from the hyperlinks you can create AJAX request to your other NON GET methods.

So something like below:-

<a href="topic.html" th:href="@{'/topics/' + ${topic.id}}" onClick="functionDelete(this)">delete</a>
<a href="form.html" th:href="@{'/topics/' + ${topic.id}}" onClick="functionModify(this)"> modify</a>

<script>
    functionDelete(topic){
        // ajax call to delete method, the url of HTTP type DELETE
    }
    functionModify(topic){
        // ajax call to PUT method, the url of HTTP type PUT
    }
</script>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1