SpringMVC(五)执行定时任务、配置视图解析器、文件的上传及下载、国际化、验证码—Java基础篇

1.pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.jike</groupId>
<artifactId>SpringMVC</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>SpringMVC Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.0.0.RELEASE</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.springframework/spring-oxm -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-oxm</artifactId>
<version>5.0.0.RELEASE</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.springframework/spring-tx -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>5.0.0.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-fileupload/commons-fileupload -->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.3</version>
</dependency>

<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>


<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-annotations -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.9.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.9.0</version>
</dependency>




<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-validator -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.0.0.Final</version>
</dependency>
</dependencies>
<build>
<finalName>SpringMVC</finalName>
</build>
</project>

2.web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
    http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

<display-name>Archetype Created Web Application</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>

<!-- 加载指定位置的上下文配置文件 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:applicationContext.xml</param-value>
</context-param>

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<servlet>
<servlet-name>Spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- 表示启动容器时初始化该servlet -->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-mvc.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Spring</servlet-name>
<!-- 表示哪些请求需要交给Spring Web MVC处理,/是用来定义默认servlet映射的。也可以如“*.html”表示拦截所有以html为扩展名的请求 -->
<url-pattern>*.html</url-pattern>
</servlet-mapping>

<filter>
<filter-name>localeFilter</filter-name>
<filter-class>com.jike.filter.LocaleFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>localeFilter</filter-name>
<url-pattern>*.html</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>localeFilter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>

</web-app>

3.spring-mvc.xml文件

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


<!--自动扫描该包,使SpringMVC认为包下用了@controller注解的类是控制器 -->
<context:component-scan base-package="com.jike.*" />


<!-- 启用注解驱动的定时任务 -->
<task:annotation-driven />


<!-- 视图解析器 -->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/" />
<property name="suffix" value=".jsp" />
</bean>


<!-- 配置MultipartResover:用于文件上传 -->
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="defaultEncoding" value="UTF-8"></property>
<property name="maxUploadSize" value="10485760000"></property>
<property name="maxInMemorySize" value="4096"></property>
</bean>


<!-- 定义国际化消息 -->
<bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename" value="i18n/message" />
<property name="defaultEncoding" value="utf-8" />
<!-- 如果在国际化资源文件中找不到对应代码的信息,就用这个代码作为名称 -->
<property name="useCodeAsDefaultMessage" value="true" />
</bean>
<mvc:interceptors>
<!-- 国际化操作拦截器 如果采用基于(请求/Session/Cookie)则必需配置 -->
<bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="lang" />
</bean>
</mvc:interceptors>
<!-- 获取本地 -->
<bean id="localeResolver"
class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
<property name="defaultLocale" value="zh"></property>
</bean>


<!-- <mvc:interceptors> <mvc:interceptor> <mvc:mapping path="/user/**" /> 
<bean class="com.jike.interceptor.CheckInterceptor"></bean> </mvc:interceptor> 
</mvc:interceptors> -->


</beans>



4.index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Insert title here</title>
</head>
<body>
<p>
<a href="topage.html?pagename=oneUpload">单文件上传</a>
</p>
<p>
<a href="topage.html?pagename=moreUpload">多文件上传</a>
</p>
<p>
<a href="download.html?fileName=1.jpg">文件下载</a>
</p>
<p>
<a href="topage.html?pagename=i18n">国际化</a>
</p>
<p>
<a href="topage.html?pagename=login">验证码</a>
</p>
</body>
</html>

5.ToolController.java

package com.jike.controller;


import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;


import com.jike.common.RandomValidateCode;
import com.jike.constant.Constants;


@Controller
public class ToolController {


@RequestMapping("topage")
public String toPage(@RequestParam String pagename) {
System.out.println("topage:" + pagename);
return pagename;
}


@RequestMapping("doLogin")
public String login(HttpServletRequest request, HttpServletResponse response, @RequestParam String vcode) {
String url = "";
String sessionCode = (String) request.getSession().getAttribute(Constants.RANDOM_CODE_KEY);
if (vcode.equals(sessionCode)) {
url = "i18n";
} else {
request.setAttribute("error", "验证码错误");
url = "login";
}


return url;
}


@Resource
RandomValidateCode code;


@RequestMapping("vcode")
public void vcode(HttpServletRequest request, HttpServletResponse response) {
code.getRandcode(request, response);
}
}


6.Constants.java

package com.jike.constant;


public class Constants {


public static final String RANDOM_CODE_KEY = "RANDOM_CODE_KEY";
}


7.定时任务类QuartzTask.java

编写定时任务类,用@Component注解标注类

方法上使用注解,同时不能有返回类型

定义cron表达式


package com.jike.task;


import java.text.SimpleDateFormat;
import java.util.Date;


import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;


@Component
public class QuartzTask {


@Scheduled(cron = "* 1/10 * * * ?")
public void checkTimeJob() {

System.out.println("使用SpringMVC框架配置定时任务");
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// 设置日期格式
System.out.println(df.format(new Date()));// new Date()为获取当前系统时间
}

}

8.oneUpload.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Insert title here</title>
</head>
<body>


<form action="oneUpload.html" method="post"
enctype="multipart/form-data">
<p>
<span>文件:</span> <input type="file" name="imageFile" />
</p>
<p>
<input type="submit" value="submit" />
</p>
</form>
</body>
</html>

9.moreUpload.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Insert title here</title>
</head>
<body>


<form action="moreUpload.html" method="post"
enctype="multipart/form-data">
<p>
<span>文件:</span> <input type="file" name="imageFile1" />
</p>
<p>
<span>文件:</span> <input type="file" name="imageFile2" />
</p>
<p>
<input type="submit" value="submit" />
</p>
</form>
</body>
</html>

10.moreUploadResult.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.util.List"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Insert title here</title>
</head>
<body>


<%
List<String> files = (List<String>) request.getAttribute("files");
for (String url : files) {
%>
<a href="<%=url%>"> <img alt="" src="<%=url%>" />
</a>
<%
}
%>
</body>
</html>

11.UploadController.java

package com.jike.controller;


import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;


import javax.servlet.http.HttpServletRequest;


import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;


@Controller
public class UploadController {


@RequestMapping("oneUpload")
public String oneUpload(@RequestParam("imageFile") MultipartFile imageFile, HttpServletRequest request) {
System.out.println("oneUpload start");
/*修改tomcat的Server Locations为Use Tomcat installation
* 为灰色,不能修改的时候
* 1.remove 部署的项目
* 2.clean server
     */
String path = request.getSession().getServletContext().getRealPath("/") + "upload/";
String filename = imageFile.getOriginalFilename();


File dir = new File(path);
if (!dir.exists()) {
dir.mkdirs();
}


System.out.println("文件上传到:" + path + filename);


File targetFile = new File(path + filename);
if (!targetFile.exists()) {
try {
targetFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}


try {
imageFile.transferTo(targetFile);
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}


return "redirect:http://localhost:8080/SpringMVC/upload/" + filename;
}


@RequestMapping("moreUpload")
public String moreUpload(HttpServletRequest request) {
System.out.println("moreUpload start");
MultipartHttpServletRequest mRequest = (MultipartHttpServletRequest) request;
Map<String, MultipartFile> map = mRequest.getFileMap();


String path = request.getSession().getServletContext().getRealPath("/") + "upload/";
File dir = new File(path);
if (!dir.exists()) {
dir.mkdirs();
}


List<String> fileList = new ArrayList<String>();
for (MultipartFile file : map.values()) {


File targetFile = new File(path + file.getOriginalFilename());
if (!targetFile.exists()) {
try {
targetFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
try {
file.transferTo(targetFile);
fileList.add("http://localhost:8080/SpringMVC/upload/" + file.getOriginalFilename());
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}


request.setAttribute("files", fileList);


return "moreUploadResult";
}

}

12.文件下载DownloadController.java 

package com.jike.controller;


import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;


@Controller
public class DownloadController {


@RequestMapping("download")
private String download(@RequestParam String fileName, HttpServletRequest request, HttpServletResponse response) {
System.out.println("download" + fileName);
response.setContentType("text/html;charset=utf-8");
try {
request.setCharacterEncoding("utf-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}


BufferedInputStream bis = null;
BufferedOutputStream bos = null;


String ctxPath = request.getSession().getServletContext().getRealPath("/") + "upload/";
String downloadPath = ctxPath + fileName;
System.out.println(downloadPath);


try {
long fileLength = new File(downloadPath).length();
response.setContentType("application/x-msdownload");
response.setHeader("Content-Length", String.valueOf(fileLength));
response.setHeader("Content-disposition",
"attachment;filename=" + new String(fileName.getBytes("GB2312"), "ISO_8859_1"));


bis = new BufferedInputStream(new FileInputStream(downloadPath));
bos = new BufferedOutputStream(response.getOutputStream());


byte[] buff = new byte[2048];
int byteRead;
while ((byteRead = bis.read(buff, 0, buff.length)) != -1) {
bos.write(buff, 0, byteRead);
}
} catch (Exception e) {


} finally {
if (bis != null) {
try {
bis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (bos != null) {
try {
bos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}


return null;
}

}

13.i18n.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><spring:message code="title"></spring:message></title>
</head>
<body>
<script type="text/javascript">
function changeLocale(lang) {
var exdate = new Date();
exdate.setDate(exdate.getDate() + 365);
document.cookie = "lang=" + lang + ";expires="
+ exdate.toGMTString();
location.reload();
}
</script>
<a href="javascript:changeLocale('zh');">中文</a>
<a href="javascript:changeLocale('en');">英文</a>
<spring:message code="desc"></spring:message>
</body>

</html>

14.message_en.properties

title=english

desc=this is desc

15.message_zh.properties

title=中文

desc=中文描述

16.LocaleFilter.java

package com.jike.filter;


import java.io.IOException;
import java.util.Locale;


import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;


import org.springframework.web.servlet.i18n.SessionLocaleResolver;


public class LocaleFilter implements Filter {


@Override
public void init(FilterConfig filterConfig) throws ServletException {
// TODO Auto-generated method stub
Filter.super.init(filterConfig);
}


@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
String lang = "zh";
Cookie[] cookies = ((HttpServletRequest) request).getCookies();
if (cookies != null && cookies.length > 0) {
for (Cookie cookie : cookies) {
if ("lang".equals(cookie.getName())) {
lang = cookie.getValue();
}
}
}
System.out.println("change locale to:" + lang);


((HttpServletRequest) request).getSession().setAttribute(SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME,
new Locale(lang));
chain.doFilter(request, response);
}


@Override
public void destroy() {
// TODO Auto-generated method stub
Filter.super.destroy();
}


}

17.login.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Insert title here</title>
</head>
<body>
<script>
var i = 1;
function changeCode() {
document.getElementById("id").src = "vcode.html?v=" + (i++);
}
</script>
<form action="doLogin.html" method="post">
<p>
<input type="text" name="vcode">
</p>


<p>
<input type="image" id="vcode" src="vcode.html"
onclick="changeCode()">
</p>
<p>
<input type="submit" value="submit" />
</p>
</form>
<font color="red">${error}</font>
</body>

</html>

18.RandomValidateCode.java

package com.jike.common;


import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.util.Random;


import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


import org.springframework.stereotype.Component;


import com.jike.constant.Constants;


@Component
public class RandomValidateCode {
private Random random = new Random();
private String randString = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";// 随机产生的字符串


private int width = 80;// 图片宽
private int height = 26;// 图片高
private int lineSize = 20;// 干扰线数量
private int stringNum = 4;// 随机产生字符数量
/*
* 获得字体
*/


private Font getFont() {
return new Font("Fixedsys", Font.CENTER_BASELINE, 18);
}


/*
* 获得颜色
*/
private Color getRandColor(int fc, int bc) {
if (fc > 255)
fc = 255;
if (bc > 255)
bc = 255;
int r = fc + random.nextInt(bc - fc - 16);
int g = fc + random.nextInt(bc - fc - 14);
int b = fc + random.nextInt(bc - fc - 18);
return new Color(r, g, b);
}


/**
* 生成随机图片
*/
public void getRandcode(HttpServletRequest request, HttpServletResponse response) {
HttpSession session = request.getSession();
// BufferedImage类是具有缓冲区的Image类,Image类是用于描述图像信息的类
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_BGR);
Graphics g = image.getGraphics();// 产生Image对象的Graphics对象,改对象可以在图像上进行各种绘制操作
g.fillRect(0, 0, width, height);
g.setFont(new Font("Times New Roman", Font.ROMAN_BASELINE, 18));
g.setColor(getRandColor(110, 133));
// 绘制干扰线
for (int i = 0; i <= lineSize; i++) {
drowLine(g);
}
// 绘制随机字符
String randomString = "";
for (int i = 1; i <= stringNum; i++) {
randomString = drowString(g, randomString, i);
}
session.removeAttribute(Constants.RANDOM_CODE_KEY);
session.setAttribute(Constants.RANDOM_CODE_KEY, randomString);
System.out.println(randomString);
g.dispose();
try {
// 禁止图像缓存
response.setHeader("Pragma", "no-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
// 将内存中的图片通过字符流形式输出到客户端
ImageIO.write(image, "JPEG", response.getOutputStream());// 将内存中的图片通过流动形式输出到客户端
} catch (Exception e) {
e.printStackTrace();
}
}


/*
* 绘制字符串
*/
private String drowString(Graphics g, String randomString, int i) {
g.setFont(getFont());
g.setColor(new Color(random.nextInt(101), random.nextInt(111), random.nextInt(121)));
String rand = String.valueOf(getRandomString(random.nextInt(randString.length())));
randomString += rand;
g.translate(random.nextInt(3), random.nextInt(3));
g.drawString(rand, 13 * i, 16);
return randomString;
}


/*
* 绘制干扰线
*/
private void drowLine(Graphics g) {
int x = random.nextInt(width);
int y = random.nextInt(height);
int xl = random.nextInt(13);
int yl = random.nextInt(15);
g.drawLine(x, y, x + xl, y + yl);
}


/*
* 获取随机的字符
*/
public String getRandomString(int num) {
return String.valueOf(randString.charAt(num));
}

}

猜你喜欢

转载自blog.csdn.net/qidiantianxia/article/details/80663596