SpringBoot 移动复制功能的实现

本文详细介绍了如何在SpringBoot应用中实现新闻条目的复制和移动功能。涉及HTML页面效果展示、数据库表结构、Ajax请求、DAO与Service层、Controller层以及Vue方法。关键步骤包括:通过Ajax获取分类列表、使用接口继承实现DAO和Service层方法、控制器中处理移动和复制逻辑,特别是复制时的数据克隆、图片文件复制及重新命名。
摘要由CSDN通过智能技术生成

这个功能要求的是我们选中的条数然后去进行一个复制或者移动到别的一个分类去。

可能是多条一起操作,也可能是一条去操作。

我们选择的数据,移动到比它大的一个分类里面

我们先实现一下效果吧,这个效果主要是在html的一个页面的效果。

先附上显示截图吧,我们复制和移动到的分类这个是从数据库中查出来的。

先附上表结构吧,没有表结构可能理解的不是很清晰

1、新闻表 news 外键c_id

 

2、新闻类型表 category 主键cid

接下来应该考虑的是移动和复制的分类列表是怎么出来的

我是ajax请求后台传值然后返回json数据去循环数据

这个没什么好说的很好理解

先附上dao层的代码 CategoryDao

package com.msfh.news.dao;

import com.msfh.news.eneity.Category;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;

public interface CategoryDao extends PagingAndSortingRepository<Category, Integer>, JpaSpecificationExecutor<Category> {

}

这里可以看得出来dao层里并没有代码,主要是我们继承的接口

 

service层 CategoryService

package com.msfh.news.service;

import com.msfh.news.dao.CategoryDao;
import com.msfh.news.eneity.Category;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CategoryService {
    @Autowired
    private CategoryDao categoryDao;

    /**
     * 查询categroy这个表的所有数据
     * @return categroy这个表的所有数据
     */
    public Iterable<Category> findAll(){
        return categoryDao.findAll();
    }
}

controller层

CategoryController

package com.msfh.news.controller;

import com.msfh.news.eneity.Category;
import com.msfh.news.service.CategoryService;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    /**
     * ajax请求查询categroy表的所有数据
     * @return
     */
    @RequestMapping("findAll")
    @ResponseBody
    public Iterable<Category> findAll(){
        return categoryService.findAll();
    }
}

html Categoryhtml

    <table class="table table-hover text-center">
      <tr>
        <th width="100" style="text-align:left; padding-left:20px;">ID</th>
        <th>内容</th>
        <th>名称</th>
        <th>分类名称</th>
        <th>作者</th>
        <th>缩略图</th>
        <th width="10%">更新时间</th>
        <th width="310">操作</th>
      </tr>


        <tr v-for="ns,key in newss">
          <td style="text-align:left; padding-left:20px;">
            <input type="checkbox" name="nid"  :value="ns.nid" v-model="nids" />
                              排序: <input type="text" style="width: 33px;" v-model="ns.u_id" @blur="sort(ns.nid,ns.u_id)" />
          </td>
          <td>{
  {n
  • 8
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值