会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132843个问题
Python 全系列/第二阶段:Python 深入与提高/文件处理 33136楼

老师这是怎么回事,后台也没有报错

package com.bjsxt.ego.manager.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.bjsxt.ego.beans.PictureResult;
import com.bjsxt.manager.service.ManagerItemService;

@Controller
public class ItemImageController {

	@Autowired
	private ManagerItemService managerItemService;
	
	/**
	 * 处理图片上传请求
	 */
	@RequestMapping(value="pic/upload",produces=MediaType.APPLICATION_JSON_VALUE
			+";charset=UTF-8")
	@ResponseBody
	public PictureResult picUpLoad(MultipartFile uploadFile) {
		return managerItemService.uploadItemPic(uploadFile);
	}
	
}
package com.bjsxt.ego.beans;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;

public class FtpUtils {

	public static void main(String[] args)  {
		
		/**
		 * 完成图片上传,通过ftp将图片上传到图片服务器
		 */
		
		String hostname = "192.168.86.135";
		int port = 21;
		String username = "ftpuer";
		String password = "xuxiaoqin";
		String pathname = "/home/ftpuser/jd";
		String remote="demo.jpg";
		InputStream local =null;
		try {
			local = new FileInputStream("D:/笔记/第八章/第四章/02 软件/pic/1.jpg");
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		FtpUtils a = new FtpUtils();
		
		a.uploadFile(hostname, port, username, password, pathname, remote, local);
				
		
	}
	
	public static boolean uploadFile(String hostname, 
			int port, String username, 
			String password, String pathname,
			String remote,InputStream local) {
		
		Boolean flag = false;
		try {
			//创建FtpClient对象
			FTPClient client = new FTPClient();
			//建立和ftp服务器的连接
			client.connect(hostname,port);
			//登录ftp服务器
			client.login(username, password);
			//设置上传的文件的类型
			client.setFileType(FTP.BINARY_FILE_TYPE);
			//切换工作目录,文件上传后保存到那个目录
			if(!client.changeWorkingDirectory(pathname)){
				if(client.makeDirectory(pathname)){
					client.changeWorkingDirectory(pathname);
				}
			}
			
			local = new FileInputStream("D:/笔记/第八章/第四章/02 软件/pic/1.jpg");
			//实现文件上传
			client.storeFile(remote, local);
			 
			local.close();
			
			client.logout();
			client.disconnect();
			flag = true;
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return flag;
	}
	
	
}
@Override
	public PictureResult uploadItemPic(MultipartFile file) {
		// TODO Auto-generated method stub
		
		Boolean flag = null;
		String fileName = null;
		
		try {
			//获得信息的文件的名字
			fileName = IDUtils.genImageName();
			//获得上传的文件的原始名字
			String oriName = file.getOriginalFilename();
			//获得文件扩展名
			String ext = oriName.substring(oriName.lastIndexOf("."));
			
			fileName = fileName+ext;
			
			InputStream local = file.getInputStream();
			
			//实现文件上传到ftp
			flag = FtpUtils.uploadFile(FTP_HOST, FTP_PORT, FTP_USERNAME, 
					FTP_PASSWORD, FTP_PATH, fileName, local);
			
			
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			flag = false;
		}
		
		PictureResult result = null;
		
		if(flag) {
			result = new PictureResult();
			result.setError(0);
			result.setUrl(IMAGE_HTTP_PATH+"/"+fileName);
			result.setMessage("ok");
			System.out.println(1);
		}else {
			result = new PictureResult();
			result.setError(1);
			result.setUrl("url");
			result.setMessage("error");
		}
		
		return result;
	}



ego.zip

image.png

image.png

JAVA 全系列/(旧的隐藏)第八阶段:电商高级项目_架构/编码/电商ego-使用VSFTPD_Nginx完成商品新增 33138楼
Python 全系列/第一阶段:Python入门/编程基本概念 33139楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/异常机制 33140楼
JAVA 全系列/第一阶段:JAVA 快速入门/变量、数据类型、运算符 33141楼
Python 全系列/第一阶段:Python入门/编程基本概念 33142楼
JAVA 全系列/第一阶段:JAVA 快速入门/变量、数据类型、运算符 33145楼

-------------------------------代码部分如下-----------------------------------

import math

import re


def inputdata(i) :

    # 输入第一个坐标点a

    x1, y1 = input("请输入第{}坐标点的x值和y值,以空格隔开:".format(i)).split()

    # 正则表达式判断是否为小数,若不为小数,则给出提示,重新输入

    float_data = re.compile(r'^[-+]?[0-9]+\.?[0-9]*$')

    x = float_data.match(x1)

    y = float_data.match(y1)

    # x,y坐标同时满足要求时返回值,否则重新输入

    if x and y :

        print(x1, y1)

        print(type(x1),type(y1)) # 是string类型

        return float(x1), float(y1)  # string类型转换成浮点型

    else :

        print("输入错误,请输入整数或浮点数")

        # return 0,0 

        inputdata(i)



# 获取第一个坐标点

ax, ay = inputdata(1)

# print(type(ax))

# 获取第二个坐标点

bx, by = inputdata(2)

# 获取第三个坐标点

cx, cy = inputdata(3)

# print(cx+cy)

# print(type(cx))

# 计算三条边长

a = math.sqrt(math.pow((ax - bx), 2) + math.pow((ay - by), 2))

b = math.sqrt(math.pow((bx - cx), 2) + math.pow((by - cy), 2))

c = math.sqrt(math.pow((ax - cx), 2) + math.pow((ay - cy), 2))

if a + b > c and a + c > b and b + c > a :

    # 海伦公式

    p = (a + b + c)

    print('p:', p, a, b, c)

    S = math.sqrt(p * (p - a) * (p - b) * (p - c))

    print("三角形面积为:%.2f" % S)

else :

    print("三角形不成立")


-----------------------------------------问题----------------------------------------

运算结果如下,为什么第二次输入错误的坐标,再按提示重新输入正确的坐标表后,返回值接受不到?

image.png


Python 全系列/第一阶段:Python入门/函数和内存分析 33146楼

1.zip


老师我在父组件中发送网络请求获取了数据,

通过props传递给了子组件

然后我利用v-for指令渲染了dom元素,这里都OK


但是我在mounted生命周期中查找元素,获取不到元素

mounted(){

    console.log(document.querySelectorAll('li'))

    console.log(this.bannerData.length)

  }

我需要获取到元素利用js来操作。


问题描述:我利用axios获取数据,然后传递给了子组件,然后利用v-for渲染了数据,页面渲染成功但是我在mounted获取元素获取不到


WEB前端全系列/第十九阶段:Vue2知识体系(旧)/Vue基础知识 33148楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/多线程和并发编程(旧) 33150楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637