3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Spring】クリックされた選択肢によって表示先のJSPを変える方法

Posted at
all.jsp
<!-- 予めfindAll()などで作成したallDomainsなどをaddAttributeしておく -->
<c:forEach var = "domain" items = ${allDomains}>
  <!-- allDomains(ArrayList)の中身の数だけ選択肢を表示 -->
  <a href = "/class/method/${domain.id}"><c:out value = "${domain.name}"/>
  <!-- href属性の中に${domain.id}を設定することで変数を渡すことができる -->
<c:forEach />
Controller.java
@Controller
@RequestMapping("/class") 
    public class Controller{
@Autowired
Service service;

@RequestMapping("/method/{domainId}") //jspで選択したdomainのidを引数に受け渡し
public String findOne(@PathVariable("domainId") Integer id, Model model){
    Domain domain = service.findOne(id);
    model.addAttribute("domain", domain);
    return "detail";
detail.jsp
<!-- ControllerでaddAttributeしたdomainの情報が表示される -->
<c:out value = "${domain.id}">
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?