Git Product home page Git Product logo

like-admin's Introduction

like-admin

后台

1.后台Mysql执行
  查看 SqlLogInterceptor#getSql()该方法 

上传头像

1.约定访问路径问 http://localhost:8868/image/{sign}.jpg  =>http://localhost:8868/image/1621312619057.jpg 
2.登陆的时候在session中存放http://localhost:8868/image/1621312619057.jpg
3.上传头像=> 删除 userAvatarViewPath + imageName
4.保存新的头像名称 userAvatarViewPath + newImageName
5.更新session
6.更新数据库

配置

upload:
  imageDir: D:\Java\project\stduyproject\like-admin\vue-quasar-manage-template\public\image\
  userAvatarViewPath: http://localhost:8868/image/

前端代码示例

 let formData = new FormData();
      formData.append("file",this.file)
      postUpload("/upload",formData ).then(res => {
        console.log(res);
      })

后端代码示例

    @PostMapping("/upload")
    public String handleFileUpload(@RequestPart(value = "file") final MultipartFile uploadfile) throws IOException {
            return saveUploadedFiles(uploadfile);
            }
    
    private String saveUploadedFiles(final MultipartFile file) throws IOException {
    final byte[] bytes = file.getBytes();
            // TODO: 2021/5/18 type check
            String type = file.getContentType();
    
            // image Name
            String name = file.getOriginalFilename();
            name = new Date().getTime() + name.substring(file.getOriginalFilename().indexOf('.'));
    final Path path = Paths
            .get(uploadConstant.getImageDir() + name);
            Files.write(path, bytes);
    
            // 将用户图片名称保存的session中
            SaSession session = StpUtil.getSession();
            String avatarAddr = session.get(SESSION_KEY_AVATAR).toString();
            String imageName = avatarAddr.replace(uploadConstant.getUserAvatarViewPath(), "");
            // 删除原来的图片
            Files.delete(Paths.get(uploadConstant.getImageDir() + imageName));
            avatarAddr = uploadConstant.getUserAvatarViewPath() + name;
            session.set(SESSION_KEY_AVATAR, avatarAddr);
    
            userService.updateSelectiveById(new UserQuery().setAvatar(avatarAddr).setUserId(StpUtil.getLoginIdAsLong()));
            return name;
            }

todo

使用fdfs

like-admin's People

Contributors

fzdwx avatar likeishacker avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.