SpringMVC实现文件上传和下载功能

2023-11-07

一、文件上传功能

目录结构

设立流程

  • 设计数据表,将项目id和上传文件路径的对应关系存到数据库中。
    结构包括:主键、项目id(外键)、文件目录、重命名后的文件名、原文件名。
  • 逆向工程生成dao、po、mapper,xml
  • 在project的edit.jsp中增加一段html的文件上传标记。
  • 编写service和controller实现上传功能。
  • 编辑页面显示文件,根据projectid找到对应的文件对象的,将原文件名显示在页面上。

1.数据库表结构

create table tb_files(
	fid int primary key not null auto_increment,
	projectid int,
	path varchar(255),
	filename varchar(255),
	origname varchar(255)
)

2.dao包

通过逆向工程生成 TbFilesMapper接口

public interface TbFilesMapper {
    int countByExample(TbFilesExample example);

    int deleteByExample(TbFilesExample example);

    int deleteByPrimaryKey(Integer fid);

    int insert(TbFiles record);

    int insertSelective(TbFiles record);

    List<TbFiles> selectByExample(TbFilesExample example);

    TbFiles selectByPrimaryKey(Integer fid);

    int updateByExampleSelective(@Param("record") TbFiles record, @Param("example") TbFilesExample example);

    int updateByExample(@Param("record") TbFiles record, @Param("example") TbFilesExample example);

    int updateByPrimaryKeySelective(TbFiles record);

    int updateByPrimaryKey(TbFiles record);
}

3.po包

TbFiles.java

public class TbFiles {
    private Integer fid;

    private Integer projectid;

    private String path;

    private String filename;

    private String origname;

    public Integer getFid() {
        return fid;
    }

    public void setFid(Integer fid) {
        this.fid = fid;
    }

    public Integer getProjectid() {
        return projectid;
    }

    public void setProjectid(Integer projectid) {
        this.projectid = projectid;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path == null ? null : path.trim();
    }

    public String getFilename() {
        return filename;
    }

    public void setFilename(String filename) {
        this.filename = filename == null ? null : filename.trim();
    }

    public String getOrigname() {
        return origname;
    }

    public void setOrigname(String origname) {
        this.origname = origname == null ? null : origname.trim();
    }
}

4.service包

FileService接口

public interface FileService {
    public List<TbFiles> query(int projectid);
}

FileServiceImpl.java

@Service//将该类注册到IOC容器中生成对应的Bean
public class FileServiceImpl implements FileService{
    @Autowired
    private TbFilesMapper filesMapper;
    @Override
    public List<TbFiles> query(int projectid) {
        TbFilesExample example=new TbFilesExample();
        TbFilesExample.Criteria criteria=example.createCriteria();
        criteria.andProjectidEqualTo(projectid);
        return filesMapper.selectByExample(example);
    }
}

ProjectService接口

public interface ProjectService {
    public void update(MultipartFile[] files,TbProject project,String realPath);
    public TbProject queryById(int id);
}

ProjectServiceImpl.java

@Service
public class ProjectServiceImpl implements ProjectService{
    @Autowired
    private TbProjectMapper projectMapper;
    @Autowired
    private TbFilesMapper filesMapper;

    @Override
    public void update(MultipartFile[] files,TbProject project,String realPath) {
        int count=0;
        for(MultipartFile f:files){
            //重命名
            //截取后缀名
            String hzm="";
            int index=f.getOriginalFilename().lastIndexOf(".");
            if(index!=-1){
                hzm=f.getOriginalFilename().substring(index);
            }
            //生成一个不重复的名字
            String name=String.valueOf(new Date().getTime())+(++count);//用当前时间的毫秒值作为名字,为了使名字不重复,count为计数器
            //上传文件存储在部署路径的upload文件夹中,文件名是重命名的文件名
            File dirFile=new File(realPath,"upload");//将部署的路径传进来
            if(!dirFile.exists())//如果不存在就建立文件夹
                dirFile.mkdir();
            File saveFile=new File(dirFile,name+hzm);//dirFile为父文件夹,要存的文件名name+hzm
            try {
                f.transferTo(saveFile);
            } catch (IOException e) {
                e.printStackTrace();
            }
            //向数据库存储关系
            TbFiles tbFiles=new TbFiles();
            tbFiles.setProjectid(project.getProjectid());
            tbFiles.setFilename(name+hzm);
            tbFiles.setOrigname(f.getOriginalFilename());//源文件名
            tbFiles.setPath(dirFile.getPath());//存储的路径
            filesMapper.insert(tbFiles);
        }
        projectMapper.updateByPrimaryKeySelective(project);
    }
}

5.controller包

ProjectController.java

@Controller
@RequestMapping("/project")
public class ProjectController {
    @Autowired
    private ProjectService projectService;//注入
    @Autowired
    private FileService fileService;

    @RequestMapping("/edit")
    public String edit(int id,Map map){
        //查询项目经理的集合,查客户的集合,传到add.jsp页面
        TbProject project=projectService.queryById(id);
        List<TbFiles> files=fileService.query(id);
        List<TbEmp> managers=empService.query(3);
        List<TbCompany> companies=companyService.query();
        map.put("managers",managers);
        map.put("companies",companies);
        map.put("project",project);
        map.put("files",files);
        return "/project/edit";

    }
    @RequestMapping("/update")
    public String update(MultipartFile[] file, TbProject project, HttpServletRequest request){
        projectService.update(file,project,request.getServletContext().getRealPath(""));//得到部署的路径传进去
        return "redirect:/project/query";//重定向跳转
    }
   
}

6.resources包

通过逆向工程生成的 TbFilesMapper.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.hyxy.dao.TbFilesMapper" >
  <resultMap id="BaseResultMap" type="com.hyxy.po.TbFiles" >
    <id column="fid" property="fid" jdbcType="INTEGER" />
    <result column="projectid" property="projectid" jdbcType="INTEGER" />
    <result column="path" property="path" jdbcType="VARCHAR" />
    <result column="filename" property="filename" jdbcType="VARCHAR" />
    <result column="origname" property="origname" jdbcType="VARCHAR" />
  </resultMap>
 
  <update id="updateByPrimaryKeySelective" parameterType="com.hyxy.po.TbFiles" >
    update tb_files
    <set >
      <if test="projectid != null" >
        projectid = #{projectid,jdbcType=INTEGER},
      </if>
      <if test="path != null" >
        path = #{path,jdbcType=VARCHAR},
      </if>
      <if test="filename != null" >
        filename = #{filename,jdbcType=VARCHAR},
      </if>
      <if test="origname != null" >
        origname = #{origname,jdbcType=VARCHAR},
      </if>
    </set>
    where fid = #{fid,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.hyxy.po.TbFiles" >
    update tb_files
    set projectid = #{projectid,jdbcType=INTEGER},
      path = #{path,jdbcType=VARCHAR},
      filename = #{filename,jdbcType=VARCHAR},
      origname = #{origname,jdbcType=VARCHAR}
    where fid = #{fid,jdbcType=INTEGER}
  </update>
</mapper>

7.webapp

edit.jsp

<%--
Created by IntelliJ IDEA.
User: 86159
Date: 2022/7/5
Time: 8:54
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>项目管理系统</title>
    <link rel="stylesheet" rev="stylesheet"
          href="${pageContext.request.contextPath}/css/style.css" type="text/css" media="all" />
    <style type="text/css">
        <!--
        .atten {font-size:12px;font-weight:normal;color:#F00;}
        -->
    </style>
    <script src="${pageContext.request.contextPath}/js/jquery-1.9.1.min.js"></script>
    <script>
        $(function(){
            $("#saveBtn").click(function(){
                saveForm.submit();
            });
            $("#addFile").click(function(){
                $("#filetd").append("<input type='file' name='file'/><br>")
            });

        });
    </script>
</head>
<body class="ContentBody">
<form action="${pageContext.request.contextPath}/project/update" method="post" enctype="multipart/form-data"
      name="saveForm" >
    <input type="hidden" name="projectid" value="${project.projectid}">
    <div class="MainDiv">
        <table width="99%" border="0" cellpadding="0" cellspacing="0" class="CContent">
            <tr>
                <th class="tablestyle_title" >项目编辑</th>
            </tr>
            <tr>
                <td class="CPanel">
                    <table border="0" cellpadding="0" cellspacing="0"
                           style="width:100%">
                        <TR>
                            <TD width="100%">
                                <fieldset style="height:100%;">
                                    <legend>项目信息</legend>
                                    <table border="0" cellpadding="2" cellspacing="1"
                                           style="width:100%">
                                        <tr>
                                            <td nowrap align="right" width="15%">项目名称:</td>
                                            <td width="35%"><input name='projectname'
                                                                   value="${project.projectname}" type="text" class="text" style="width:154px" />
                                                <span class="red">*</span></td>
                                            <td nowrap align="right" width="18%">所属单位:</td>
                                            <td width="35%">
                                                    <select name="companyid">
                                                        <option value="">请选择</option>
                                                        <c:forEach items="${companies}" var="c">
                                                            <option value="${c.companyid}"
                                                                    <c:if test="${project.companyid==c.companyid}">selected</c:if> >${c.companyname}
                                                            </option>
                                                        </c:forEach>
                                                    </select>
                                                <span class="red">*</span></td>
                                        </tr>
                                        <tr>
                                            <td nowrap align="right" width="15%">项目金额:</td>
                                            <td width="35%"><input name='amount'
                                                                   value="${project.amount}" type="text" class="text" style="width:154px"/>
                                            </td>
                                            <td nowrap align="right" width="18%">开发人数:</td>
                                            <td width="35%"><input name='prosum'
                                                                   value="${project.prosum}" type="text" class="text" style="width:154px"/>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td nowrap align="right" width="15%">项目经理:</td>
                                            <td width="35%">
                                                <select name="empid">
                                                    <option value="">请选择</option>
                                                    <c:forEach items="${managers}"
                                                               var="e">
                                                        <option value="${e.empid}" <c:if
                                                                test="${project.empid==e.empid}">selected</c:if> >${e.empname}</option>
                                                    </c:forEach>
                                                </select>
                                            </td>
                                            <td nowrap align="right" width="18%">完成状态:</td>
                                            <td width="35%">
                                                <select name="state">
                                                    <option selected="selected">请选择</option>
                                                    <option value="0" <c:if test="${project.state==0}">selected</c:if> >需求</option>
                                                    <option value="1" <c:if test="${project.state==1}">selected</c:if> >开发</option>
                                                    <option value="2" <c:if test="${project.state==2}">selected</c:if> >测试</option>
                                                    <option value="3" <c:if test="${project.state==3}">selected</c:if> >完成</option>
                                                </select>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td nowrap align="right" width="15%">预算总成本:</td>
                                            <td width="35%"><input name='budget'
                                                                   value="${project.budget}" type="text" class="text" style="width:154px"  />
                                            </td>
                                            <td nowrap="nowrap" align="right">开始日期:</td>
                                            <td><input name='realbegindate'
                                                       value="<fmt:formatDate value='${project.realbegindate}' pattern="yyyy-MM-dd"/>" type="text" class="text" style="width:154px"/> </td>
                                        </tr>
                                        <tr>
                                            <td nowrap="nowrap" align="right">完成日期:</td>
                                            <td><input name='realenddate'
                                                       value="<fmt:formatDate value='${project.realenddate}' pattern="yyyy-MM-dd"/>" type="text" class="text" style="width:154px" />
                                            </td>
                                            <td align="right" >优先级:</td>
                                            <td ><select name="priority" >
                                                <option selected="selected">请选择</option>
                                                <option value="0" <c:if test="${project.priority==0}">selected</c:if> >普通</option>
                                                <option value="1" <c:if test="${project.priority==1}">selected</c:if> >急</option>
                                                <option value="2" <c:if test="${project.priority==2}">selected</c:if> >特急</option>
                                            </select></td>
                                        </tr>
                                        <tr>
                                            <td width="15%" nowrap align="right">备注:
                                            </td>
                                            <td colspan="3"><textarea name="descript"
                                                                      cols="100" rows="10">${project.descript}</textarea></td>
                                        </tr>

                                        <tr>
                                            <td  colspan="4" nowrap align="left"><a id="addFile" href="javascript:void(0);">添加文件</a></td>
                                        </tr>
                                        <tr>
                                            <td  colspan="4" nowrap align="left">
                                                <c:forEach items="${files}" var="f">
                                                    ${f.origname}&nbsp;&nbsp;<a href="${pageContext.request.contextPath}/project/download?id=${f.fid}">下载</a>&nbsp;&nbsp;<a href="javascript:void(0);">删除</a><br>
                                                </c:forEach>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td  colspan="4" id="filetd" nowrap align="left"></td>
                                        </tr>

                                    </table>
                                    <br/>
                                </fieldset> </TD>
                        </TR>
                    </TABLE>
                </td>
            </tr>
            <TR>
                <TD colspan="2" align="center" height="50px">
                    <input type="button" name="Submit" value="保存" id="saveBtn"
                           class="button" />
                    <input type="button" name="Submit2" value="返回" class="button"
                           onclick="window.history.go(-1);"/></TD>
            </TR>
        </TABLE>
        </td>
        </tr>
        </table>
    </div>
</form>
</body>
</html>

8.spring的xml配置文件

applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:mybatis-spring="http://mybatis.org/schema/mybatis-spring"
       xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://mybatis.org/schema/mybatis-spring http://mybatis.org/schema/mybatis-spring.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">

    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver" />
        <property name="url" value="jdbc:mysql://localhost:3306/project?useUnicode=true&amp;characterEncoding=utf8" />
        <property name="username" value="root" />
        <property name="password" value="root" />
    </bean>

    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource"></property>
        <property name="mapperLocations" value="classpath*:com/hyxy/mapper/*.xml"></property>
        <property name="plugins">
            <array>
                <bean class="com.github.pagehelper.PageInterceptor">
                    <property name="properties">
                        <value>
                            helperDialect=mysql
                            reasonable=true
                        </value>
                    </property>
                </bean>
            </array>
        </property>

    </bean>
    <mybatis-spring:scan base-package="com.hyxy.dao"/>
    <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"></property>
    </bean>
    <tx:annotation-driven transaction-manager="txManager" />
    <context:component-scan base-package="com.hyxy.service"></context:component-scan>
</beans>

9.导入的依赖

    <!-- 文件上传包 -->
    <dependency>
      <groupId>commons-fileupload</groupId>
      <artifactId>commons-fileupload</artifactId>
      <version>1.3.1</version>
    </dependency>

10.显示效果

浏览器访问 项目查询页面–点击编辑按钮–点击添加文件超链接–选择上传文件–点击保存按钮
http://localhost/8080/project/project/query
添加文件
在这里插入图片描述
再次访问编辑页面可查看上传的文件
在这里插入图片描述

数据库存储的projectid和上传文件的关系表
在这里插入图片描述

二、文件下载功能

目录结构

1.service包

FileService接口

public interface FileService {
    public TbFiles queryById(int fid);
}

FileServiceImpl.java

@Service
public class FileServiceImpl implements FileService{
    @Autowired
    private TbFilesMapper filesMapper;

    @Override
    public TbFiles queryById(int fid) {
        return filesMapper.selectByPrimaryKey(fid);
    }
}

2.controller包

ProjectController.java

@Controller
@RequestMapping("/project")
public class ProjectController {
    @Autowired
    private ProjectService projectService;//注入
    @Autowired
    private EmpService empService;
    @Autowired
    private CompanyService companyService;
    @Autowired
    private FileService fileService;

    @RequestMapping("/update")
    public String update(MultipartFile[] file, TbProject project, HttpServletRequest request){
        projectService.update(file,project,request.getServletContext().getRealPath(""));
        return "redirect:/project/query";
    }
    @RequestMapping("/download")
    public ResponseEntity<byte[]> download(int id){
        TbFiles files=fileService.queryById(id);
        File downloadFile=new File(files.getPath(),files.getFilename());//要下载的文件
        HttpHeaders headers = new HttpHeaders();
        //通知浏览器以attachment(下载方式)打开图片
        headers.setContentDispositionFormData("attachment", files.getOrigname());//原文件名
        //application/octet-stream : 二进制流数据(最常见的文件下载)。
        headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
        try {
            return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(downloadFile),
                    headers, HttpStatus.CREATED);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}

3.功能测试

点击下载功能的超链接即可下载到本地
在这里插入图片描述

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

SpringMVC实现文件上传和下载功能 的相关文章

  • Java中反射是如何实现的?

    Java 7 语言规范很早就指出 本规范没有详细描述反射 我只是想知道 反射在Java中是如何实现的 我不是问它是如何使用的 我知道可能没有我正在寻找的具体答案 但任何信息将不胜感激 我在 Stackoverflow 上发现了这个 关于 C
  • 在画布上绘图

    我正在编写一个 Android 应用程序 它可以在视图的 onDraw 事件上直接绘制到画布上 我正在绘制一些涉及单独绘制每个像素的东西 为此我使用类似的东西 for int x 0 x lt xMax x for int y 0 y lt
  • Java JDBC:更改表

    我希望对此表进行以下修改 添加 状态列 varchar 20 日期列 时间戳 我不确定该怎么做 String createTable Create table aircraft aircraftNumber int airLineCompa
  • 如何找到给定字符串的最长重复子串

    我是java新手 我被分配寻找字符串的最长子字符串 我在网上研究 似乎解决这个问题的好方法是实现后缀树 请告诉我如何做到这一点或者您是否有任何其他解决方案 请记住 这应该是在 Java 知识水平较低的情况下完成的 提前致谢 附 测试仪字符串
  • 在 HTTPResponse Android 中跟踪重定向

    我需要遵循 HTTPost 给我的重定向 当我发出 HTTP post 并尝试读取响应时 我得到重定向页面 html 我怎样才能解决这个问题 代码 public void parseDoc final HttpParams params n
  • JAXb、Hibernate 和 beans

    目前我正在开发一个使用 Spring Web 服务 hibernate 和 JAXb 的项目 1 我已经使用IDE hibernate代码生成 生成了hibernate bean 2 另外 我已经使用maven编译器生成了jaxb bean
  • INSERT..RETURNING 在 JOOQ 中不起作用

    我有一个 MariaDB 数据库 我正在尝试在表中插入一行users 它有一个生成的id我想在插入后得到它 我见过this http www jooq org doc 3 8 manual sql building sql statemen
  • 控制Android的前置LED灯

    我试图在用户按下某个按钮时在前面的 LED 上实现 1 秒红色闪烁 但我很难找到有关如何访问和使用前置 LED 的文档 教程甚至代码示例 我的意思是位于 自拍 相机和触摸屏附近的 LED 我已经看到了使用手电筒和相机类 已弃用 的示例 但我
  • JavaMail 只获取新邮件

    我想知道是否有一种方法可以在javamail中只获取新消息 例如 在初始加载时 获取收件箱中的所有消息并存储它们 然后 每当应用程序再次加载时 仅获取新消息 而不是再次重新加载它们 javamail 可以做到这一点吗 它是如何工作的 一些背
  • Spring Data JPA 应用排序、分页以及 where 子句

    我目前正在使用 Spring JPA 并利用此处所述的排序和分页 如何通过Spring data JPA通过排序和可分页查询数据 https stackoverflow com questions 10527124 how to query
  • 磁模拟

    假设我在 n m 像素的 2D 表面上有 p 个节点 我希望这些节点相互吸引 使得它们相距越远吸引力就越强 但是 如果两个节点之间的距离 比如 d A B 小于某个阈值 比如 k 那么它们就会开始排斥 谁能让我开始编写一些关于如何随时间更新
  • 如何将 pfx 文件转换为 jks,然后通过使用 wsdl 生成的类来使用它来签署传出的肥皂请求

    我正在寻找一个代码示例 该示例演示如何使用 PFX 证书通过 SSL 访问安全 Web 服务 我有证书及其密码 我首先使用下面提到的命令创建一个 KeyStore 实例 keytool importkeystore destkeystore
  • getResourceAsStream() 可以找到 jar 文件之外的文件吗?

    我正在开发一个应用程序 该应用程序使用一个加载配置文件的库 InputStream in getClass getResourceAsStream resource 然后我的应用程序打包在一个 jar文件 如果resource是在里面 ja
  • 总是使用 Final?

    我读过 将某些东西做成最终的 然后在循环中使用它会带来更好的性能 但这对一切都有好处吗 我有很多地方没有循环 但我将 Final 添加到局部变量中 它会使速度变慢还是仍然很好 还有一些地方我有一个全局变量final 例如android Pa
  • 如何在 javadoc 中使用“<”和“>”而不进行格式化?

    如果我写
  • 在 Mac 上正确运行基于 SWT 的跨平台 jar

    我一直致力于一个基于 SWT 的项目 该项目旨在部署为 Java Web Start 从而可以在多个平台上使用 到目前为止 我已经成功解决了由于 SWT 依赖的系统特定库而出现的导出问题 请参阅相关thread https stackove
  • 无法捆绑适用于 Mac 的 Java 应用程序 1.8

    我正在尝试将我的 Java 应用程序导出到 Mac 该应用程序基于编译器合规级别 1 7 我尝试了不同的方法来捆绑应用程序 1 日食 我可以用来在 Eclipse 上导出的最新 JVM 版本是 1 6 2 马文 看来Maven上也存在同样的
  • Java列表的线程安全

    我有一个列表 它将在线程安全上下文或非线程安全上下文中使用 究竟会是哪一个 无法提前确定 在这种特殊情况下 每当列表进入非线程安全上下文时 我都会使用它来包装它 Collections synchronizedList 但如果不进入非线程安
  • 按日期对 RecyclerView 进行排序

    我正在尝试按日期对 RecyclerView 进行排序 但我尝试了太多的事情 我不知道现在该尝试什么 问题就出在这条线上适配器 notifyDataSetChanged 因为如果我不放 不会显示错误 但也不会更新 recyclerview
  • 如何实现仅当可用内存较低时才将数据交换到磁盘的写缓存

    我想将应用程序生成的数据缓存在内存中 但如果内存变得稀缺 我想将数据交换到磁盘 理想情况下 我希望虚拟机通知它需要内存并将我的数据写入磁盘并以这种方式释放一些内存 但我没有看到任何方法以通知我的方式将自己挂接到虚拟机中before an O

随机推荐

  • 华为OD机试 - 学生方阵(Java)

    题目描述 学校组织活动 将学生排成一个矩形方阵 请在矩形方阵中找到最大的位置相连的男生数量 这个相连位置在一个直线上 方向可以是水平的 垂直的 成对角线的或者呈反对角线的 注 学生个数不会超过10000 输入描述 输入的第一行为矩阵的行数和
  • 2020-08-31微信小程序暗黑模式(深色模式)

    项目新增了一个夜间模式的功能 小程序现在也支持这个模式 类似于写2套css 话不多说 直接上效果和代码图
  • Tomcat目录下写web报500错误

    项目场景 所用Tomcat版本为9 0 16 在Tomcat目录下写web工程并使用cmd黑框打开Tomcat 将 java文件反编译成 class文件 问题描述 当浏览器访问web xml文件下的映射地址时 始终报500错误 原因分析 在
  • 智能指针之概述01

    一 智能指针概述 1 为何使用智能指针 首先我们先谈为何需要智能指针 C 11之前操作堆内存空间都是使用new delete来维护 但是很容易造成new出来的内存忘记delete 开发人员需要大量时间维护修复 而new出来返回的指针也叫裸指
  • Android实现关机代码

    Android实现关机的代码如下 Intent intent new Intent Intent ACTION REQUEST SHUTDOWN intent putExtra Intent EXTRA KEY CONFIRM false
  • vue项目支持js新语法可选链“?.“以及逻辑空分配(双问号)“??“

    先来看两个场景 场景1 我需要判断数组对象中的某个值是否存在进而去做其他事情 let title if data data children data children 0 data children 0 title title data
  • C++:constexpr及constexpr函数

    constexpr变量 constexpr表达式是指值不会改变并且在编译过程就能得到计算结果的表达式 声明为constexpr的变量一定是一个const变量 而且必须用常量表达式初始化 constexpr int mf 20 20是常量表达
  • 【PaddlePaddle飞桨复现论文】—— 2. 采用 DNN 、CNN 和 VGG 实现车牌识别(VGG模型精度提高明显!!)

    一 任务描述 本次实践是一个多分类任务 需要将照片中的每个字符分别进行识别 完成车牌的识别 实践平台 百度AI实训平台 AI Studio PaddlePaddle1 8 0 二 数据集介绍 数据集文件名为characterData zip
  • SpringMVC之JSR303和拦截器

    目录 一 JSR 303 1 1 介绍 1 2 为什么要使用JSR 303 1 3 常用注解 1 4 快速入门 1 4 1 导入依赖 1 4 2 配置校验规则 1 4 3 编写方法校验 1 4 4 测试 二 拦截器 2 1 什么是拦截器 2
  • ClickHouse物化视图(八)

    文章目录 概述 1 物化视图与普通视图的区别 2 优缺点 3 基本语法 1 创建物化视图的限制 2 物化视图的数据更新 4 物化视图创建示例 5 更多文章和干货请关注公众号 概述 ClickHouse 的物化视图是一种查询结果的持久化 它确
  • Vue中TodoList案例_本地存储

    App vue
  • leetcode分类刷题:滑动窗口(三、两个序列+窗口定长类型)

    1 通过对滑动窗口前两个题型的总结 我们几乎已经习惯在给定的一个序列里使用滑动窗口的模板解题了 本次对应的 三 两个序列 窗口定长类型 也是考察连续子数组 连续子串问题 只不过这次会给定两个序列 判断短序列在长序列中是否存在字母异位词或排列
  • SSH 与 SSM

    SSM 指 SpringMVC Spring 和 MyBatis SSH 指 Struts Spring 和 Hibernate 两种框架的对比和对照为 控制器 事务层 持久层 SSH Struts Spring Hibernate SSM
  • Vue组件学习之组件自定义事件

    主要介绍组件的自定义事件的概念 使用等 何为组件自定义事件 组件自定义事件是一种组件间的通信方式 方向是 子组件 gt 父组件 使用场景 A是子组件 B是父组件 如果要把B的数据传给A 可以使用props配置项 如果要把A的数据转给B 就要
  • 【Springboot】集成百度地图实现定位打卡功能

    目录 第一章 需求分析 第二章 概要设计 第三章 详细设计 3 1 环境搭建 3 1 1 获取百度地图ak 3 1 2 创建springboot项目 3 2 配置application properties 3 3 配置pox xml 3
  • pyTorch基本数据类型

    pyTorch基本数据类型 文章目录 pyTorch基本数据类型 首先比较一下python和pytorch的数据类型区别 pyhon的特点 pytorch的特点 维度为0的标量 维度为1的向量 维度为2的Tensor 维度为3的Tensor
  • eclipse学习心得

    1运行程序 在后台遇到断点时 进入debug调试状态 作用域 功能 快捷键 全局 单步返回 F7 全局 单步跳过 F6 全局 单步跳入 F5 全局 单步跳入选择 Ctrl F5 全局 调试上次启动 F11 全局 继续 F8 全局 使用过滤器
  • js设置input只保留一位小数

    前言 input中只保留小数点后一位 直接不让他输入 实现方法 这里主要用 input事件来监听 vue中的话用 input input中加上 type text 注意这里有坑 不能用数字类型 谷歌 360可以 火狐会报错 oninput
  • C++的rapidjson库的安装和用法(包括Windows和Linux)

    C 的rapidjson库的安装和用法 包括Windows和Linux 1 RapidJson在Linux下安装 1 确保安装了git以及cmake make 2 在github官网上clone下RapidJson的工程 git clone
  • SpringMVC实现文件上传和下载功能

    实现文件上传和下载功能 一 文件上传功能 目录结构 设立流程 1 数据库表结构 2 dao包 3 po包 4 service包 5 controller包 6 resources包 7 webapp 8 spring的xml配置文件 9 导