vue+springBoot实现单击树节点,右侧表单数据展示本级和本级以下数据

vue实现单击树节点,右侧表单数据展示本级和本级以下数据

实现结果

单击树节点展示本级和本级以下数据

Vue

html部分

当单击树节点,执行handleNodeClick方法

<el-aside
                width="200px"
                style="height: 100vh; border-radius: 5px;border: 1px solid #ddd; background:white"
            >
                <el-row type="flex">
                    <el-col :span="20" :offset="3">
                        <el-header style="margin: 20px 0px 20px 0px">
                            <el-row>
                                <h1 style="font-size:15px;text-align:center;line-height:50px">题目类别</h1>
                            </el-row>
                            <div class="horizon">
                                <hr />
                            </div>
                        </el-header>
                        <el-card>
                            <el-tree
                                :data="treeData"
                                :props="defaultProps"
                                node-key="id"
                                @node-contextmenu="rightClick"
                                @node-click="handleNodeClick"
                            ></el-tree>
                        </el-card>
                        <div v-show="menuVisible">
                            <el-card>
                            <ul id="menu" class="menu" :model="treeItem">
                                <li class="menu__item" @click="TreeAdd(treeItem)">添加</li>
                                <li class="menu__item" @click="handleEdit(1,treeItem)">修改</li>
                                <li class="menu__item" @click="handleDelete(1,treeItem)">删除</li>
                            </ul>
                            </el-card>
                        </div>
                    </el-col>
                </el-row>
            </el-aside>

Js部分

通过queryData方法从后台查询出数据

handleNodeClick(data) {
            this.getIds(data);
            for (var i = 0; i < this.searchIds.length; i++) {
                this.vo.id = this.searchIds[i];
                this.ls.push(this.vo);
                this.CommonRequest.body.vo = this.ls;
                this.queryData();
                this.resetSearch();
            }
        },
//从后台查询数据
        queryData() {
            this.vo.pageIndex = this.page.pageIndex;
            this.vo.pageSize = this.page.pageSize; // vo传给request
            this.CommonRequest.body.vo = this.vo;
            queryCategory(this.CommonRequest.body.vo).then(response => {
                this.tableData = [];
                this.page.total = response.body.total;
                this.tableData = response.body.list;
                this.getTreeData();
            });
        },

SpringBoot

Controller部分

根据前台传过来的vo,判断是执行哪个查询,可能是根据搜索框得查询,可能是点击树节点得查询

	@ApiLog
    @PostMapping("/queryCategory")
    @CrossOrigin
    public CommonResponse<CommonPage<CategoryTableVO>> doQuery(@RequestBody CommonRequest<CategoryTableVO> request){
        CategoryDTO categoryDTO= new CategoryDTO();
        Map<String, CategoryTableVO> body = request.getBody();
        CategoryTableVO queryVO=body.get("vo");
        List<CategoryTableVO> resultList=new ArrayList<>();
        Page<Object> page = null;
        /*
        * 判断前台传过来的查询条件
        * */
        /*
        * 根据名字查询
        * */
        if(!queryVO.getName().equals("")){
            categoryDTO.setName(queryVO.getName());
             page = PageHelper.startPage(queryVO.getPageIndex(), queryVO.getPageSize());
            List<CategoryDTO> categoryDTOList=categoryService.query(categoryDTO);
            PojoUtil.copyList(categoryDTOList,resultList,CategoryTableVO.class);
        }
        /*
        * 点击树节点查询
        * */
        if(!queryVO.getId().equals("")){
            categoryDTO.setId(Long.valueOf(queryVO.getId()));
            page = PageHelper.startPage(queryVO.getPageIndex(), queryVO.getPageSize());
            List<CategoryDTO> treeList=categoryService.queryTreeData(categoryDTO);
            PojoUtil.copyList(treeList,resultList,CategoryTableVO.class);
        }
        /*
        * 只点击查询按钮
        * */
        if(queryVO.getName().equals("")&&queryVO.getId().equals("")){
            page = PageHelper.startPage(queryVO.getPageIndex(), queryVO.getPageSize());
            List<CategoryDTO> categoryDTOList=categoryService.query(categoryDTO);
            PojoUtil.copyList(categoryDTOList,resultList,CategoryTableVO.class);
        }
        return buildResponseWithPage(page,resultList);
    }

xml文件

<select id="queryTreeData" resultType="com.boss.bes.basedata.pojo.entity.Category">
        SELECT * from t_category where id=#{id}
        UNION ALL
        SELECT a.* FROM t_category a JOIN t_category b on a.parent_id=b.id
            where a.parent_id=#{id}
    </select>
  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
下面是一个简单的示例,展示如何使用VueSpring Boot实现回显MySQL文件和表单数据。 1. 配置MySQL数据库连接 在Spring Boot的application.properties文件中配置MySQL数据库连接信息,例如: ``` spring.datasource.url=jdbc:mysql://localhost:3306/db_name spring.datasource.username=username spring.datasource.password=password spring.datasource.driver-class-name=com.mysql.jdbc.Driver ``` 2. 创建MySQL表 在MySQL数据库中创建一个表,用于存储文件和表单数据,例如: ``` CREATE TABLE `file_data` ( `id` int(11) NOT NULL AUTO_INCREMENT, `file_name` varchar(255) DEFAULT NULL, `file_data` longblob, `form_data` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; ``` 3. 编写Spring Boot后端代码 创建一个Spring Boot的RestController,用于处理HTTP请求并从MySQL数据库中检索文件和表单数据。下面是一个简单的示例: ``` @RestController @RequestMapping("/api") public class FileDataController { @Autowired private FileDataRepository fileDataRepository; @GetMapping("/file-data") public List<FileData> getFileData() { return fileDataRepository.findAll(); } @PostMapping("/file-data") public void saveFileData(@RequestBody FileData fileData) { fileDataRepository.save(fileData); } } ``` 4. 编写Vue前端代码 使用Vue和Element UI创建一个简单的表单,用于上传文件和提交表单数据。下面是一个简单的示例: ``` <template> <el-form :model="form" ref="form" label-width="100px"> <el-form-item label="Upload File"> <el-upload class="upload-demo" :action="uploadUrl" :on-success="handleFileUploadSuccess" :before-upload="beforeFileUpload" :show-file-list="false"> <el-button slot="trigger" size="small" type="primary">Select File</el-button> </el-upload> </el-form-item> <el-form-item label="Form Data"> <el-input v-model="form.formData"></el-input> </el-form-item> <el-form-item> <el-button type="primary" @click="submitForm('form')">Submit</el-button> </el-form-item> </el-form> </template> <script> import axios from 'axios' export default { data() { return { form: { formData: '', file: null }, uploadUrl: '/api/file-data' } }, methods: { beforeFileUpload(file) { this.form.file = file return true }, handleFileUploadSuccess(response) { console.log(response) }, submitForm(formName) { this.$refs[formName].validate((valid) => { if (valid) { let formData = new FormData() formData.append('formData', this.form.formData) formData.append('file', this.form.file) axios.post(this.uploadUrl, formData, { headers: { 'Content-Type': 'multipart/form-data' } }).then(response => { console.log(response) }).catch(error => { console.log(error) }) } else { console.log('error submit!!') return false } }) } } } </script> ``` 5. 创建FileData实体类和Repository 创建一个FileData实体类,用于映射MySQL表中的数据。创建一个FileDataRepository,用于从MySQL数据库中检索数据。下面是一个简单的示例: ``` @Entity @Table(name = "file_data") public class FileData { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @Column(name = "file_name") private String fileName; @Lob @Column(name = "file_data") private byte[] fileData; @Column(name = "form_data") private String formData; // getters and setters } @Repository public interface FileDataRepository extends JpaRepository<FileData, Long> { } ``` 以上就是一个简单的示例,展示了如何使用VueSpring Boot实现回显MySQL文件和表单数据的代码。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值