Thymeleaf在前台下拉列表獲取后台傳的值


                                                                                                                     Thymeleaf在前台下拉列表獲取后台傳的值

后台添加代碼:

/**
     * 新增機構
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        List<Scholar>  scholars = scholarService.selectScholarListName();  mmap.put("scholars",scholars); return "module/institution/add";
    }
    

后台修改代碼:

 

/**
     * 修改機構
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        Institution institution = institutionService.selectInstitutionById(id);
        List<Scholar> scholars = scholarService.selectScholarListName(); mmap.put("scholars",scholars);
        mmap.put("institution", institution);
        return  "module/institution/edit";
    }

 

 

 

前台代碼添加:

<div class="form-group">    
                <label class="col-sm-3 control-label">主要研究人員:</label>
                <div class="col-sm-8" >
                    <!--<input id="majorResearcher" name="majorResearcher" class="form-control" type="hidden">-->
                        <!--<select name="title"  id="title" class="form-control m-b">
                            <option th:each="scholars : ${scholars.title}" th:text="${scholars.title}" th:value="${scholars.title}" ></option>
                        </select>-->
                    <select class="form-control" name="majorResearcher">
                        <option value="">  --  主要研究人員 --  </option>
                        <option th:each="scholars:${scholars}" th:value="${scholars.title}" th:text="${scholars.title}"></option>
                    </select>

                </div>
            </div>

 

前台代碼回顯:

<div class="form-group">    
                <label class="col-sm-3 control-label">主要研究人員:</label>
                <div class="col-sm-8">
                   <!-- <input id="majorResearcher" name="majorResearcher" th:field="*{majorResearcher}" class="form-control" type="text" >-->
                    <select class="form-control" name="majorResearcher">
                        <option  value="">  --  主要研究人員 --  </option>
                        <option th:each="scholars:${scholars}" th:value="${scholars.title}" th:text="${scholars.title}" th:field="*{majorResearcher}"></option>
                    </select>
                </div>
            </div>

前台頁面添加效果:

前台頁面回顯效果:


前台頁面的效果:


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM