第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定

大神們,幫幫忙吧

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns="http://java.sun.com/xml/ns/javaee"

xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"

id="WebApp_ID" version="3.0">

<display-name>Z_Test</display-name>

<servlet>

<servlet-name>springmvc</servlet-name>

<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

<init-param>

<param-name>contextConfigLocation</param-name>

<param-value>classpath:applicationContext-mvc.xml</param-value>

</init-param>

<load-on-startup>1</load-on-startup>

</servlet>


<servlet-mapping>

<servlet-name>springmvc</servlet-name>

<url-pattern>/</url-pattern>

</servlet-mapping>

<welcome-file-list>

<welcome-file>index.html</welcome-file>

<welcome-file>index.htm</welcome-file>

<welcome-file>index.jsp</welcome-file>

<welcome-file>default.html</welcome-file>

<welcome-file>default.htm</welcome-file>

<welcome-file>default.jsp</welcome-file>

</welcome-file-list>

</web-app>

--------------------------------------------------------------------------------------

<?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:tx="http://www.springframework.org/schema/tx"?

xmlns:context="http://www.springframework.org/schema/context"

xmlns:mvc="http://www.springframework.org/schema/mvc"

xmlns:jdbc="http://www.springframework.org/schema/jdbc"

xmlns:jee="http://www.springframework.org/schema/jee"

xmlns:aop="http://www.springframework.org/schema/aop"

xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd

http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd

http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.2.xsd

http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.2.xsd

http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd

? ? ? ? http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd

? ? ? ? http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">


<mvc:default-servlet-handler/>

<mvc:annotation-driven/>

<context:component-scan base-package="*"/>

<bean id="viewResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">

<property name="defaultEnconding " value="utf-8"></property>

<property name="maxUploadSize " value="10485760000"></property>

<property name="maxInMemorySize " value="40960"></property>


</bean>



</beans>

------------------------------------------------------------------------------------------

@Controller

@RequestMapping("/")

public class ThumbnailAction {

private UploadService uploadService;

private ThumbnailService thumbnailService;

@RequestMapping(value="/thumbnail",method=RequestMethod.POST)

public ModelAndView thumbnail(@RequestParam("image")CommonsMultipartFile file,HttpSession session)throws Exception{

//上傳后圖片的路徑(相對路徑)

String uploadPath = "/images";

//轉(zhuǎn)化為在服務(wù)器的絕對路徑

String realUploadPath=session.getServletContext().getRealPath(uploadPath);

//原圖在服務(wù)器上的相對路徑信息

String imageUrl=uploadService.uploadImage(file, uploadPath, realUploadPath);

//縮略圖的訪問路徑

String thumImageUrl=thumbnailService.thumbnail(file, uploadPath, realUploadPath);

ModelAndView ret=new ModelAndView();

//設(shè)置返回的參數(shù)信息

ret.addObject("imageURl",imageUrl);

ret.addObject("thumImageURl",thumImageUrl);

//thumbnail:縮略圖的名字

ret.setViewName("thumbnail");

return ret;

}

@Autowired

public void setUploadService(UploadService uploadService) {

this.uploadService = uploadService;

}

@Autowired

public void setThumbnailService(ThumbnailService thumbnailService) {

this.thumbnailService = thumbnailService;

}

---------------------------------------------------------------------------------------------

@Service

public class ThumbnailService {

public static final int WIDTH = 100;

public static final int HEIGHT = 100;

public String thumbnail(CommonsMultipartFile file, String uploadPath, String realUploadPath ){

try {

String des = realUploadPath+"/thum"+file.getOriginalFilename();

//通過原圖的輸入流,獲得原圖的數(shù)據(jù)信息,指定大小;toFile(des):保存到服務(wù)器上

Thumbnails.of(file.getInputStream()).size(WIDTH, HEIGHT).toFile(des);

} catch (Exception e) {

e.printStackTrace();

}

//

return uploadPath + "/thum_" + file.getOriginalFilename();

}

-------------------------------------------------------------------------------------

@Service

public class UploadService {


public String uploadImage(CommonsMultipartFile file, String uploadPath, String realUploadPath) {

InputStream is = null;

OutputStream os = null;


try {

//獲取輸入流信息

is=file.getInputStream();

//目標路徑=服務(wù)器的絕對路徑+文件名稱

String des = realUploadPath+"/"+file.getOriginalFilename();

//輸出流 指向 目標文件的路徑

os=new FileOutputStream(des);

byte[] buffer=new byte[1024];

int len = 0;

//通過輸入流讀取字節(jié),字節(jié)大小大于0,說明有內(nèi)容

while ((len=is.read(buffer))>0) {

//輸出流循環(huán)寫出來

os.write(buffer);

}


} catch (Exception e) {

e.printStackTrace();

} finally {

if (is != null) {

try {

is.close();

} catch (Exception e) {

e.printStackTrace();

}

}

if (os != null) {

try {

os.close();

} catch (Exception e) {

e.printStackTrace();

}

}

}


// 原圖訪問路徑

return uploadPath + "/" + file.getOriginalFilename();


}


正在回答

2 回答

是不是要:如果目錄不存在,創(chuàng)建
/**
?*?上傳文件
?*?@param?file?文件
?*?@param?uploadPath?上傳相對路徑
?*?@param?realUploadPath?絕對路徑
?*?@return
?*/
public??String?uploadImage(MultipartFile?file,?String?uploadPath,?String?realUploadPath){
????InputStream?is?=?null;
????OutputStream?os?=?null;
?????
?????//如果目錄不存在,創(chuàng)建


????try?{
????????is?=?file.getInputStream();


0 回復 有任何疑惑可以回復我~

?????你要問啥????

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消
Java實現(xiàn)圖片等比例縮略圖
  • 參與學習       25330    人
  • 解答問題       17    個

視頻教程以實例的方式,講解Java平臺實現(xiàn)圖片等比例縮略圖生成

進入課程

大神們,幫幫忙吧

我要回答 關(guān)注問題
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號