SpringBoot 드롭다운 상자

프런트엔드 페이지:
<div class="layui-form-item">
                <label class="layui-form-label" ><span
                            class="x-red">*span>label>
                    <div class="layui-input-inline">

                        <select id="name" name="name" class="select"  size="1" >
                            <option th:each="sourceMateriaTypes:${sourceMateriaTypes}" th:value="${sourceMateriaTypes.name}"
                                    th:text="${sourceMateriaTypes.name}" th:selected="${sourceMateria.sourceId==sourceMateriaTypes.id}">option>
                        select>
                        div>
                        div>

백엔드 코드:
/**
    *       
    * @return
    */
    @GetMapping("editBefore/{id}")
    public String editBefore(Model model,@PathVariable("id")Long id){
        SourceMateria sourceMateria= sourceMateriaService.getById(id);
        //           
        String name=sourceMateriaTypeService.selectById(id).getName();
        sourceMateria.setName(name);

        List<SourceMateriaType> sourceMateriaTypes=sourceMateriaService.selectAllType();
        model.addAttribute("sourceMateriaTypes",sourceMateriaTypes);
        model.addAttribute("sourceMateria",sourceMateria);
        return prefix+"edit";
    }
    /**
    *   
    * @param sourceMateria
    * @return
    */
    @PostMapping("edit")
    @ResponseBody
    public AjaxResult edit(SourceMateria sourceMateria,
                           @RequestParam(required = false,value = "videoFile") MultipartFile videoFile,
                           @RequestParam(required = false,value = "imageFile") MultipartFile imageFile,
                           @RequestParam(required = false) String name,
                           @RequestParam(required = false) String title,
                           @RequestParam(required = false) String content,
                           @RequestParam(required = false) Integer traffic){
        sourceMateria.setTitle(title);
        sourceMateria.setContent(content);
        sourceMateria.setTraffic(traffic);
        //         id   sourceMateria      
        QueryWrapper<SourceMateriaType> queryWrapper = new QueryWrapper<SourceMateriaType>();
        SourceMateriaType sourceMateriaType = sourceMateriaTypeService.selectOne(queryWrapper.eq("name", name));
        sourceMateria.setSourceId(sourceMateriaType.getId());
        //    
        if (imageFile != null){
            String upload = null;
            upload = OssFileUtils.uploadSingleFile(imageFile);
            sourceMateria.setIcon(upload);
        }

        if (videoFile != null){
            String upload = null;
            upload = OssFileUtils.uploadSingleFile(imageFile);
            sourceMateria.setVideoUrl(upload);
        }
        return toAjax(sourceMateriaService.updateById(sourceMateria));
    }

좋은 웹페이지 즐겨찾기