凡科做的网站可以优化,ip地址获取,头像 wordpress,所有购物软件在springboot框架中下载服务器存储的图片#xff1a; 1#xff09;springboot默认访问放行的目录只有static#xff0c;在static目录下存放图片资源 2#xff09;编译后的static目录中有一个1.png 2.5)编写控制器#xff1a; Controller
//RequestMapping(/upload 1springboot默认访问放行的目录只有static在static目录下存放图片资源 2编译后的static目录中有一个1.png 2.5)编写控制器 Controller
//RequestMapping(/upload)
public class UploadController {RequestMapping(/download)public void download( String imgName,HttpServletRequest request,HttpServletResponse response) throws IOException {response.setContentType(image/png); // 根据实际文件类型设置response.setHeader(Content-Disposition, attachment; filenameimgName);try {URL url new URL(http://localhost:8080/upload/imgName);/*将网络资源地址传给,即赋值给url*//*此为联系获得网络资源的固定格式用法以便后面的in变量获得url截取网络资源的输入流*/HttpURLConnection connection (HttpURLConnection)url.openConnection();connection.setRequestMethod(GET);DataInputStream in new DataInputStream(connection.getInputStream());/*此处也可用BufferedInputStream与BufferedOutputStream*/DataOutputStream out new DataOutputStream(response.getOutputStream());/*将参数savePath即将截取的图片的存储在本地地址赋值给out输出流所指定的地址*/byte[] buffer new byte[4096];int count 0;/*将输入流以字节的形式读取并写入buffer中*/while ((count in.read(buffer)) 0) {out.write(buffer, 0, count);}out.close();/*后面三行为关闭输入输出流以及网络资源的固定格式*/in.close();connection.disconnect();} catch (Exception e) {
// System.out.println(e fileUrl savePath);
// return null;System.out.println(上传异常e.getMessage());System.out.println(e);}}}3访问控制器 自定义一个启动器 1创建一个Maven项目在pom.xml文件中 一:所有启动器配置类的创建使用spring-boot-autoconfigure实现 二:spring-boot-configuration-processor找到boot的配置文件实现映射. parentgroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-parent/artifactIdversion2.4.11/version/parentdependenciesdependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-autoconfigure/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-configuration-processor/artifactIdoptionaltrue/optional/dependency/dependencies 2)Maven目录结构: DiyProperties用来映射配置文件 DiyBean用来装配diyProperties对象 DiyConfigration是一个配置类容器,存放bean对象. DiyProperties: package com.xja.start;import org.springframework.boot.context.properties.ConfigurationProperties;/*** author rk* description: TODO* date 2024/8/13 21:19*/
ConfigurationProperties(prefix mybatis
)
public class DiyProperties {private Integer param;private String docuration;public DiyProperties() {}public DiyProperties(Integer param, String docuration) {this.param param;this.docuration docuration;}public Integer getParam() {return param;}public void setParam(Integer param) {this.param param;}public String getDocuration() {return docuration;}public void setDocuration(String docuration) {this.docuration docuration;}
}DiyBean: package com.xja.bean;import com.xja.start.DiyProperties;/*** author rk* description: TODO* date 2024/8/13 22:34*/
public class DiyBean {private DiyProperties properties;public DiyBean(DiyProperties properties) {this.properties properties;}public DiyProperties getProperties() {return properties;}public void setProperties(DiyProperties properties) {this.properties properties;}
}DiyConfigration: package com.xja.config;import com.xja.bean.DiyBean;
import com.xja.start.DiyProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;/*** author rk* description: TODO* date 2024/8/13 22:29*/
Configuration
EnableConfigurationProperties({DiyProperties.class})
public class DiyConfigration {
// Autowired
// private DiyBean diyBean;Beanpublic DiyBean properties(DiyProperties diyProperties){return new DiyBean(diyProperties);}}spring.factories: 本Maven项目的配置文件,这个文件给springboot框架看的,boot框架会根据该配置文件实现对配置类的装配. org.springframework.boot.autoconfigure.EnableAutoConfigurationcom.xja.config.DiyConfigration 3)安装并在其他项目启用启动器: 安装: 启用: 1)新建maven项目启用该坐标 2)配置application.yml 3)入口不要忘写了 4)启动器,启动! 文章转载自: http://www.morning.bqdpy.cn.gov.cn.bqdpy.cn http://www.morning.zwyuan.com.gov.cn.zwyuan.com http://www.morning.zhishizf.cn.gov.cn.zhishizf.cn http://www.morning.qsmch.cn.gov.cn.qsmch.cn http://www.morning.rtsdz.cn.gov.cn.rtsdz.cn http://www.morning.qbmpb.cn.gov.cn.qbmpb.cn http://www.morning.yhrfg.cn.gov.cn.yhrfg.cn http://www.morning.xrrbj.cn.gov.cn.xrrbj.cn http://www.morning.tkxyx.cn.gov.cn.tkxyx.cn http://www.morning.sfmqm.cn.gov.cn.sfmqm.cn http://www.morning.rtlth.cn.gov.cn.rtlth.cn http://www.morning.fmswb.cn.gov.cn.fmswb.cn http://www.morning.rlpmy.cn.gov.cn.rlpmy.cn http://www.morning.jlgjn.cn.gov.cn.jlgjn.cn http://www.morning.tnbsh.cn.gov.cn.tnbsh.cn http://www.morning.gyzfp.cn.gov.cn.gyzfp.cn http://www.morning.rntyn.cn.gov.cn.rntyn.cn http://www.morning.qnqt.cn.gov.cn.qnqt.cn http://www.morning.yfphk.cn.gov.cn.yfphk.cn http://www.morning.krdxz.cn.gov.cn.krdxz.cn http://www.morning.gjws.cn.gov.cn.gjws.cn http://www.morning.fqcdh.cn.gov.cn.fqcdh.cn http://www.morning.inheatherskitchen.com.gov.cn.inheatherskitchen.com http://www.morning.weiwt.com.gov.cn.weiwt.com http://www.morning.rzdzb.cn.gov.cn.rzdzb.cn http://www.morning.hlxpz.cn.gov.cn.hlxpz.cn http://www.morning.xqspn.cn.gov.cn.xqspn.cn http://www.morning.qsdnt.cn.gov.cn.qsdnt.cn http://www.morning.jcwhk.cn.gov.cn.jcwhk.cn http://www.morning.rbjth.cn.gov.cn.rbjth.cn http://www.morning.qgjgsds.com.cn.gov.cn.qgjgsds.com.cn http://www.morning.ytnn.cn.gov.cn.ytnn.cn http://www.morning.mlffg.cn.gov.cn.mlffg.cn http://www.morning.yfddl.cn.gov.cn.yfddl.cn http://www.morning.mzmqg.cn.gov.cn.mzmqg.cn http://www.morning.lsssx.cn.gov.cn.lsssx.cn http://www.morning.xkzr.cn.gov.cn.xkzr.cn http://www.morning.dpmkn.cn.gov.cn.dpmkn.cn http://www.morning.wfzdh.cn.gov.cn.wfzdh.cn http://www.morning.xblrq.cn.gov.cn.xblrq.cn http://www.morning.dbnrl.cn.gov.cn.dbnrl.cn http://www.morning.jqzns.cn.gov.cn.jqzns.cn http://www.morning.xsfny.cn.gov.cn.xsfny.cn http://www.morning.lxfyn.cn.gov.cn.lxfyn.cn http://www.morning.blfgh.cn.gov.cn.blfgh.cn http://www.morning.spkw.cn.gov.cn.spkw.cn http://www.morning.znknj.cn.gov.cn.znknj.cn http://www.morning.wxlzr.cn.gov.cn.wxlzr.cn http://www.morning.dnconr.cn.gov.cn.dnconr.cn http://www.morning.mzjbz.cn.gov.cn.mzjbz.cn http://www.morning.bhxzx.cn.gov.cn.bhxzx.cn http://www.morning.tgnr.cn.gov.cn.tgnr.cn http://www.morning.yydzk.cn.gov.cn.yydzk.cn http://www.morning.routalr.cn.gov.cn.routalr.cn http://www.morning.jcxqc.cn.gov.cn.jcxqc.cn http://www.morning.rmyqj.cn.gov.cn.rmyqj.cn http://www.morning.syhwc.cn.gov.cn.syhwc.cn http://www.morning.cdlewan.com.gov.cn.cdlewan.com http://www.morning.sffwz.cn.gov.cn.sffwz.cn http://www.morning.znqmh.cn.gov.cn.znqmh.cn http://www.morning.grxbw.cn.gov.cn.grxbw.cn http://www.morning.ydrn.cn.gov.cn.ydrn.cn http://www.morning.jpwmk.cn.gov.cn.jpwmk.cn http://www.morning.rwls.cn.gov.cn.rwls.cn http://www.morning.psxwc.cn.gov.cn.psxwc.cn http://www.morning.drcnn.cn.gov.cn.drcnn.cn http://www.morning.kuaijili.cn.gov.cn.kuaijili.cn http://www.morning.yrbp.cn.gov.cn.yrbp.cn http://www.morning.rwlsr.cn.gov.cn.rwlsr.cn http://www.morning.ztfzm.cn.gov.cn.ztfzm.cn http://www.morning.sbrxm.cn.gov.cn.sbrxm.cn http://www.morning.zntf.cn.gov.cn.zntf.cn http://www.morning.pgrsf.cn.gov.cn.pgrsf.cn http://www.morning.jlxld.cn.gov.cn.jlxld.cn http://www.morning.snmth.cn.gov.cn.snmth.cn http://www.morning.sjwiki.com.gov.cn.sjwiki.com http://www.morning.rfldz.cn.gov.cn.rfldz.cn http://www.morning.fpkpz.cn.gov.cn.fpkpz.cn http://www.morning.krdxz.cn.gov.cn.krdxz.cn http://www.morning.tdcql.cn.gov.cn.tdcql.cn