1.mybatis配置
1.1 依赖
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
1.2 需要和@Configuration配和使用
@Configuration
@MapperScan("cn.skx.csmall.passport.mapper")
public class MybatisConfiguration {
public MybatisConfiguration(){
System.out.println("创建配置类: MybatisConfiguration" );
}
}
1.3 xml中的配置
mybatis.mapper-locations=classpath/*.xml
1.4 properties配置
spring.datasource.url=jdbc:mysql://localhost:3306/mall_ams?useUnicode=true&characterEncoding=utf-8&serveTimezone=Asia/Shanhai
spring.datasource.username=root
spring.datasource.password=root
mybatis.mapper-locations=classpath:mapper/*.xml
1.5 是一个yml的配置每次启动idea数据库都会执行路径下的sql语句,优先业务执行
spring:
sql:
init:
#ALWAYS 每次啟動都執行 ,NEVER,就是不执行的意思
mode: ALWAYS
#配置脚本文件的编码
encoding: utf-8
continueOnError: true
schemaLocations: classpath:sqlSchema/*.sql
dataLocations: classpath:sqlData/data.sql
1.5.1 目录位置
resources - > sqlData 和 sqlSchema 文件夹
sqlData文件下是插入语句 (我这边都是插入语句,主键都是一样的每次启动不会重新插入的)
sqlSchema文件下是创建表语句
2.Mvc统一异常处理
2.1枚举
package cn.skx.csmall.passport.web;
/**
* 枚举
*/
public enum ServiceCode {
OK(20000),
ERR_NOT_FOUND(40400),
ERR_CONFLICT(40900);
private Integer value;
ServiceCode(Integer value){
this.value = value;
}
public Integer getValue(){
return value;
}
}
2.2后端响应类
import cn.skx.csmall.product.ex.ServiceException;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
/**
* 后端处理响应数据,返回数据类
*/
@Data
public class JsonResult<T> implements Serializable {
/**
* 状态
*/
@ApiModelProperty(value = "响应的状态码")
private Integer state;
/**
* 失败的提示信息
*/
//成功时没有这个,message 为 null时 不传
//@JsonInclude(JsonInclude.Include.NON_NULL)
@ApiModelProperty(value = "业务失败的信息")
private String message;
/**
*操作成功时响应的数据
* T 占位符
*/
@ApiModelProperty(value = "操作成功时响应的数据")
private T data;
/**
* 成功
* 方法的重载
* @return 指定的响应内容
*/
public static JsonResult<Void> ok() {
return ok(null);
}
//经停方法上需要加声明 同类上的声明
public static <T> JsonResult<T> ok(T data) {
JsonResult jsonResult = new JsonResult();
jsonResult.state = ServiceCode.OK.getValue();
jsonResult.message = null;
jsonResult.data = data;
return jsonResult;
}
//自定义业务异常中有状态码和信息,所以可以简写
//方法的重载
public static JsonResult<Void> fail(ServiceException e) {
return fail(e.getServiceCode(),e.getMessage());
}
/**
* 失败
* @param serviceCode 状态
* @param message 内容
* @return 指定的响应内容
*/
public static JsonResult<Void> fail(ServiceCode serviceCode, String message) {
JsonResult jsonResult = new JsonResult();
jsonResult.state = serviceCode.getValue();
jsonResult.message = message;
return jsonResult;
}
}
2.3 创建业务异常类
package cn.skx.csmall.passport.ex;
import cn.skx.csmall.passport.web.ServiceCode;
/**
* 业务异常
* @author sun
* @version 0.0.1
*/
public class ServiceException extends RuntimeException{
private ServiceCode serviceCode;
public ServiceCode getServiceCode() {
return serviceCode;
}
public ServiceException(ServiceCode serviceCode,String message){
super(message);
this.serviceCode = serviceCode;
}
}
2.4 全局接口异常处理类
package cn.skx.csmall.passport.ex.handler;
import cn.skx.csmall.passport.ex.ServiceException;
import cn.skx.csmall.passport.web.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
/**
* 全局controller接口处理异常类
* @author sun
* @version 0.0.1
*/
@Slf4j
@RestControllerAdvice //单纯的使用 @controllerAdvice 响应的是文件名 + @ResponseBody 才可以返回字符串信息
public class GlobalExceptionHandler {
public GlobalExceptionHandler(){
System.out.println("全局异常处理器对象 : GlobalExceptionHandler");
}
/**
* 老祖宗异常 兜底的 ,让这个系统永远不会报 500 错误,异常一定会有人处理
* @param e 老祖宗异常
* @return 报错信息
*/
@ExceptionHandler
public String handleThrowable(Throwable e){
log.debug("捕获到Throwable:{}", e.getMessage());
e.printStackTrace();
return "服务器运行过程中出现未知错误,请联系系统管理员";
}
/**
* 自己声明的异常处理
* @param e 业务异常
* @return 报错信息
*/
@ExceptionHandler
public JsonResult handleServiceException(ServiceException e){
log.debug("捕获到ServiceException:{}", e.getMessage());
return JsonResult.fail(e);
}
}
2.5 业务层调用
String phone = adminAddNewDTO.getPhone();
int count = adminMapper.countByphone(phone);
if(count != 0){
String message = "添加管理员失败,手机号【"+ phone +"】已经被占用";
throw new ServiceException(ServiceCode.ERR_CONFLICT,message);
}
2.6 properties 配置,可以让返回数据 message 为空时 返回的json中就没有这个字段
spring.jackson.default-property-inclusion=non_null
2.7 controller调用
@ApiOperation(value = "删除相册")
@ApiOperationSupport(order = 300)
@ApiImplicitParam(name = "id" , value = "相册id",required = true,dataType = "long")
@PostMapping(value = {"/delete/{id:[0-9]+}"})
public JsonResult<Void> deleteById(@PathVariable Long id){
albumService.deleteById(id);
return JsonResult.ok();
}
/**
* 获取相册列表
* @return 相册集合
*/
@ApiOperation(value = "查询相册列表")
@ApiOperationSupport(order = 420)
@GetMapping("")
public JsonResult<List<AlbumListVo>> getList(){
List<AlbumListVo> list = albumService.list();
return JsonResult.ok(list);
}
3.空白的mapper.xml配置文件
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="cn.skx.csmall.passport.mapper.AdminMapper">
</mapper>
4. properties配置 多个时 使用那个配置文件
spring.profiles.active=dev
5. knife4j 在线api文档
5.1 xml依赖
<!--api在线文档-->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
<version>2.0.9</version>
</dependency>
5.2 配置类
package cn.skx.csmall.passport.config;
import com.github.xiaoymin.knife4j.spring.extension.OpenApiExtensionResolver;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;
/**
* Knife4j配置类
*
* @author java@tedu.cn
* @version 0.0.1
*/
@Slf4j
@Configuration
@EnableSwagger2WebMvc
public class Knife4jConfiguration {
/**
* 【重要】指定Controller包路径
*/
private String basePackage = "cn.skx.csmall.passport.controller";
/**
* 分组名称
*/
private String groupName = "product";
/**
* 主机名
*/
private String host = "http://java.tedu.cn";
/**
* 标题
*/
private String title = "酷鲨商城在线API文档--商品管理";
/**
* 简介
*/
private String description = "酷鲨商城在线API文档--商品管理";
/**
* 服务条款URL
*/
private String termsOfServiceUrl = "http://www.apache.org/licenses/LICENSE-2.0";
/**
* 联系人
*/
private String contactName = "Java教学研发部";
/**
* 联系网址
*/
private String contactUrl = "http://java.tedu.cn";
/**
* 联系邮箱
*/
private String contactEmail = "java@tedu.cn";
/**
* 版本号
*/
private String version = "1.0.0";
@Autowired
private OpenApiExtensionResolver openApiExtensionResolver;
public Knife4jConfiguration() {
log.debug("加载配置类:Knife4jConfiguration");
}
@Bean
public Docket docket() {
String groupName = "1.0.0";
Docket docket = new Docket(DocumentationType.SWAGGER_2)
.host(host)
.apiInfo(apiInfo())
.groupName(groupName)
.select()
.apis(RequestHandlerSelectors.basePackage(basePackage))
.paths(PathSelectors.any())
.build()
.extensions(openApiExtensionResolver.buildExtensions(groupName));
return docket;
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title(title)
.description(description)
.termsOfServiceUrl(termsOfServiceUrl)
.contact(new Contact(contactName, contactUrl, contactEmail))
.version(version)
.build();
}
}
5.3 properties配置
knife4j.enable=true
5.4 controller的使用
//类上
@Api(tags = "01. 管理员模块")
//方法上
@ApiOperation(value = "新增管理员")
@ApiOperationSupport(order = 100)//升序排列
//参数为单个
@ApiImplictParam(name = "id",value = "相册的id",required = true,dataType = "long")
//参数为多个
@ApiImplictParams({
@ApiImplictParam(xxx),
@ApiImplictParam(xxx),
@ApiImplictParam(xxx)
})
5.5 登录的网址
5.6 实体上需要加的注解
@ApiModelProperty(value = "名称",required = true,example = "示例的相册")
5.7 后端接收的参数 是对象还是formData类型的
@RequestBody 此注解加上
在线文档调试界面 不会显示请求参数的输入框,提供的是一个JSON字符串供编辑
前端传递的数据类型是 FormData类型的
name=jack&age=18&sex=男
后端就不能使用@RequestBody注解 api调试就是输入框
前端 formData 数据类型 和 后端注解 @RequestBody 互斥
6.前端Vue脚手架按照 QS
6.1 安装指令
npm i qs -S
6.2 配置main.js
import qs from 'qs';
Vue.prototype.qs = qs;
6.3 使用
let formData = this.qs.stringify(this.ruleForm);
7. Validation 用于检查请求参数
7.1 依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
7.2 controller中使用
在类上,方法上,方法参数前加上 @Validated 或者 @Valid 注解
7.3 实体上的使用
一般是放在字段上实际底层代码这样的
@Target({ElementType.METHOD, ElementType.FIELD, ElementType.ANNOTATION_TYPE, ElementType.CONSTRUCTOR, ElementType.PARAMETER, ElementType.TYPE_USE})
@NotNull(message = "添加相册失败,必须提叫相册名称")
7.4 快速失败配置类
package cn.skx.csmall.passport.config;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.HibernateValidator;
import org.hibernate.validator.constraintvalidation.HibernateConstraintValidator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.validation.Validation;
/**
* validated 配置类
* @author sun
*/
@Slf4j
@Configuration
public class ValidationConfiguration {
public ValidationConfiguration(){
log.debug("创建配置类:ValidationConfiguration");
}
@Bean
public javax.validation.Validator validator(){
return Validation.byProvider(HibernateValidator.class)
.configure()
.failFast(true)//快速失败
.buildValidatorFactory()
.getValidator();
}
}
7.5 响应新增 BindException
@ExceptionHandler
public JsonResult HandleBindException(BindException e){
log.debug("捕获到BindException:{}", e.getMessage());
//以下两行代码,如果有多种错误,将随机获取其中一种错误的信息,并相应
String mssage = e.getFieldError().getDefaultMessage();
return JsonResult.fail(ServiceCode.ERR_BAD_REQUEST, mssage);
/*StringBuilder stringBuilder = new StringBuilder();
List<FieldError> fieldErrors = e.getFieldErrors();
for(FieldError fieldError : fieldErrors){
stringBuilder.append(fieldError.getDefaultMessage());
}
return JsonResult.fail(ServiceCode.ERR_BAD_REQUEST, stringBuilder.toString());*/
}
8. 生成二维码
8.1 java代码的依赖
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>core</artifactId>
<version>3.4.1</version>
</dependency>
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>javase</artifactId>
<version>3.4.1</version>
</dependency>
8.2 代码
@Test
void contextLoads() {
String text = "https://www.baidu.com"; // 要生成二维码的文本内容
int width = 300; // 二维码图片的宽度
int height = 300; // 二维码图片的高度
String format = "png"; // 二维码图片的格式
// 设置二维码参数
QRCodeWriter qrCodeWriter = new QRCodeWriter();
BitMatrix bitMatrix;
try {
bitMatrix = qrCodeWriter.encode(text, BarcodeFormat.QR_CODE, width, height);
BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
// 将BitMatrix转换为BufferedImage
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
bufferedImage.setRGB(x, y, bitMatrix.get(x, y) ? 0xFF000000 : 0xFFFFFFFF);
}
}
// 保存生成的二维码图片
ImageIO.write(bufferedImage, format, new File("qrcode." + format));
System.out.println("二维码生成成功!");
} catch (WriterException | IOException e) {
e.printStackTrace();
}
}
9. excel的导出
9.1 依赖
<!--导出需要的依赖-->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.1.2</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.2</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>2.2.10</version>
</dependency>
9.2 代码
package com.example.erweima;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.io.FileOutputStream;
import java.io.IOException;
public class excel {
public static void main(String[] args) {
//二维数组
String[][] data = {
{"Name", "Age", "City"},
{"John", "25", "New York"},
{"Alice", "30", "London"}
};
String filePath = "output.xlsx";
exportToExcel(data, filePath);
System.out.println("Excel file exported successfully!");
}
public static void exportToExcel(String[][]data, String filePath){
try (Workbook workbook = new XSSFWorkbook()) {
Sheet sheet = workbook.createSheet("Sheet1");
for (int i = 0; i < data.length; i++) {
Row row = sheet.createRow(i);
for (int j = 0; j < data[i].length; j++) {
Cell cell = row.createCell(j);
cell.setCellValue(data[i][j]);
}
}
try (FileOutputStream outputStream = new FileOutputStream(filePath)) {
workbook.write(outputStream);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
10. excel的导入
10.1 依赖
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.1.2</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.2</version>
</dependency>
<dependency>
<groupId>net.sourceforge.jexcelapi</groupId>
<artifactId>jxl</artifactId>
<version>2.6.12</version>
</dependency>
10.2 代码
package com.example.erweima;
import org.apache.poi.ss.usermodel.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
public class ExcelImport {
public static void main(String[] args) {
//指定路径的文件
String filePath = "D:\\project5\\erweima\\output.xlsx";
try {
FileInputStream fis = new FileInputStream(new File(filePath));
Workbook workbook = WorkbookFactory.create(fis);
Sheet sheet = workbook.getSheetAt(0); // 假设你要处理的是第一个工作表
// 遍历行
for (Row row : sheet) {
// 遍历单元格
for (Cell cell : row) {
String cellValue = "";
switch (cell.getCellType()) {
case STRING:
cellValue = cell.getStringCellValue();
break;
case NUMERIC:
cellValue = String.valueOf(cell.getNumericCellValue());
break;
// 其他类型的单元格处理方式可以根据需要添加
}
System.out.print(cellValue + " ");
}
System.out.println();
}
workbook.close();
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
11 cors 跨域
配置类
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
* 跨域配置
* @author sun
*/
@Configuration
public class MyMvcConfiguration implements WebMvcConfigurer {
public MyMvcConfiguration(){
System.out.println("创建配置类MyMvcConfiguration");
}
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.maxAge(3600)
.allowedHeaders("*")
.allowedMethods("*")
.allowedOriginPatterns("*")
.allowCredentials(true);
}
}
12 密码加密
12.1 pom.xml配置
<!--Spring Security 安全框架-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
12.2 创建全局唯一的配置类
/**
* 把 BCryptPasswordEncoder() 交给容器管理
* 默认就是单例的
* 全局唯一
*/
@Slf4j
@Configuration
public class SecurityConfiguration {
//只需要创建一个就好了
@Bean
public PasswordEncoder passwordEncoder(){
log.debug("创建@Bean方法定义的对象:PasswordEncoder");
return new BCryptPasswordEncoder();
}
}
12.3 业务层使用
@Autowired
private PasswordEncoder passwordEncoder;
//TODO 取出原密码 进行加密.并把密文装回Admin对象中
String rawPassword = admin.getPassword();
String encodePassword = passwordEncoder.encode(rawPassword);
admin.setPassword(encodePassword);
13. java中判断当前运行的系统
//先在配置文件中,分别定义路径
@Value("${file.path}")
private String basePath;
@Value("${file.linux_path}")
private String linuxPath;
//判斷系統是windows还是linux
Properties properties = System.getProperties();
String osName = properties.getProperty("os.name"); //操作系统名称
String url;
if (osName.toLowerCase().contains("windows")) {
// 创建新的文件
url = basePath + "/" + filepath;
}else{
url = linuxPath + "/" + filepath;
}
File fileExist = new File(url);
14. 天气预报
14.1 xml
<properties> <lunar.version>1.2.28</lunar.version> </properties><dependencyManagement>
<dependency>
<groupId>cn.6tail</groupId>
<artifactId>lunar</artifactId>
<version>${lunar.version}</version>
</dependency></dependencyManagement>
14.2 实体
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
/**
* 当前天天气预报
* @Author: taicl
* @Date: 2024/7/9 13:45
*/
@Schema(name = "当前天天气预报", description = "当前天天气预报")
@Data
public class TodayWeatherForecastVo {
@Schema(description = "日期")
private String todayDate = "";
@Schema(description = "农历日期")
private String lunarCalendar = "";
@Schema(description = "星期")
private String weeks = "";
@Schema(description = "天气")
private String weather = "";
@Schema(description = "城市")
private String city = "";
@Schema(description = "当前温度")
private String currentTemperature = "";
@Schema(description = "湿度")
private String humidity = "";
@Schema(description = "风力")
private String windPower = "";
}
14.3 yml配置
weather:
#昌图县
city: 101071103
14.4 配置变量
@Data
@Component
public class ConfigConstants {
/**
* @Description: 天气城市
* @Author: taicl
* @Date: 2024/6/7 14:25
*/
@Value("${weather.city}")
String weatherCity;
}
14.5 业务代码
import com.nlf.calendar.Lunar;
import com.nlf.calendar.Solar;
import com.nlf.calendar.util.HolidayUtil;
import java.text.ParseException;
import java.text.SimpleDateFormat;
/**
* 查询当前天天气预报
* @Author: taicl
* @Date: 2024/7/9 14:23
*/
@Override
public TodayWeatherForecastVo getTodayWeatherForecast() {
Lunar lunar = Lunar.fromDate(new Date());
TodayWeatherForecastVo todayWeatherForecastVo = new TodayWeatherForecastVo();
try{
URL url = new URL("http://t.weather.itboy.net/api/weather/city/" + constants.getWeatherCity());
InputStreamReader isReader = new InputStreamReader(url.openStream(),"UTF-8");//“UTF- 8”万国码,可以显示中文,这是为了防止乱码
BufferedReader br = new BufferedReader(isReader);//采用缓冲式读入
String str;
while((str = br.readLine()) != null){
String regex="\\p{Punct}+";
String digit[]=str.split(regex);
todayWeatherForecastVo.setTodayDate(digit[50]+"年"+digit[51]+"月"+digit[52]+"日");
todayWeatherForecastVo.setLunarCalendar(lunar.getYearInGanZhi() + "年" + lunar.getMonthInChinese() + "月" + lunar.getDayInChinese());
todayWeatherForecastVo.setWeeks(digit[54]);
todayWeatherForecastVo.setWeather(digit[68]);
todayWeatherForecastVo.setCity(digit[18]);
todayWeatherForecastVo.setCurrentTemperature(digit[38]);
todayWeatherForecastVo.setHumidity(digit[28]);
todayWeatherForecastVo.setWindPower(digit[64]+digit[66]);
}
br.close();//网上资源使用结束后,数据流及时关闭
isReader.close();
} catch(Exception exp){
System.out.println(exp);
}
return todayWeatherForecastVo;
}
/**
* 查询近七天天气预报
* @Author: taicl
* @Date: 2024/7/9 14:23
*/
@Override
public List<SevenDaysWeatherForecastVo> getSevenDaysWeatherForecast() {
List<SevenDaysWeatherForecastVo> list = new ArrayList<>();
SevenDaysWeatherForecastVo one = new SevenDaysWeatherForecastVo();
SevenDaysWeatherForecastVo two = new SevenDaysWeatherForecastVo();
SevenDaysWeatherForecastVo three = new SevenDaysWeatherForecastVo();
SevenDaysWeatherForecastVo four = new SevenDaysWeatherForecastVo();
SevenDaysWeatherForecastVo five = new SevenDaysWeatherForecastVo();
SevenDaysWeatherForecastVo six = new SevenDaysWeatherForecastVo();
SevenDaysWeatherForecastVo seven = new SevenDaysWeatherForecastVo();
try{
URL url = new URL("http://t.weather.itboy.net/api/weather/city/" + constants.getWeatherCity());
InputStreamReader isReader = new InputStreamReader(url.openStream(),"UTF-8");//“UTF- 8”万国码,可以显示中文,这是为了防止乱码
BufferedReader br = new BufferedReader(isReader);//采用缓冲式读入
String str;
while((str = br.readLine()) != null){
String regex="\\p{Punct}+";
String digit[]=str.split(regex);
// 第一天
one.setWeeks(digit[54]);
one.setTodayDate(digit[51]+"/"+digit[52]);
one.setWeather(digit[68]);
one.setWindPowerOne(digit[64]);
one.setWindPowerTwo(digit[66]);
if(digit[46] !=null) {
one.setHighestTemperature((digit[46].substring(2,digit[46].length()-1)).trim());
}
if(digit[48] !=null) {
one.setLowestTemperature((digit[48].substring(2,digit[48].length()-1)).trim());
}
// 第二天
two.setWeeks(digit[82]);
two.setTodayDate(digit[79]+"/"+digit[80]);
two.setWeather(digit[96]);
two.setWindPowerOne(digit[92]);
two.setWindPowerTwo(digit[94]);
if(digit[74] !=null) {
two.setHighestTemperature((digit[74].substring(2,digit[74].length()-1)).trim());
}
if(digit[76] !=null) {
two.setLowestTemperature((digit[76].substring(2,digit[76].length()-1)).trim());
}
// 第三天
three.setWeeks(digit[110]);
three.setTodayDate(digit[107]+"/"+digit[108]);
three.setWeather(digit[124]);
three.setWindPowerOne(digit[120]);
three.setWindPowerTwo(digit[122]);
if(digit[102] !=null) {
three.setHighestTemperature((digit[102].substring(2,digit[102].length()-1)).trim());
}
if(digit[104] !=null) {
three.setLowestTemperature((digit[104].substring(2,digit[104].length()-1)).trim());
}
// 第四天
four.setWeeks(digit[138]);
four.setTodayDate(digit[135]+"/"+digit[136]);
four.setWeather(digit[152]);
four.setWindPowerOne(digit[148]);
four.setWindPowerTwo(digit[150]);
if(digit[130] !=null) {
four.setHighestTemperature((digit[130].substring(2,digit[130].length()-1)).trim());
}
if(digit[132] !=null) {
four.setLowestTemperature((digit[132].substring(2,digit[132].length()-1)).trim());
}
// 第五天
five.setWeeks(digit[166]);
five.setTodayDate(digit[163]+"/"+digit[164]);
five.setWeather(digit[180]);
five.setWindPowerOne(digit[176]);
five.setWindPowerTwo(digit[178]);
if(digit[158] !=null) {
five.setHighestTemperature((digit[158].substring(2,digit[158].length()-1)).trim());
}
if(digit[160] !=null) {
five.setLowestTemperature((digit[160].substring(2,digit[160].length()-1)).trim());
}
// 第六天
six.setWeeks(digit[194]);
six.setTodayDate(digit[191]+"/"+digit[192]);
six.setWeather(digit[208]);
six.setWindPowerOne(digit[204]);
six.setWindPowerTwo(digit[206]);
if(digit[186] !=null) {
six.setHighestTemperature((digit[186].substring(2,digit[186].length()-1)).trim());
}
if(digit[188] !=null) {
six.setLowestTemperature((digit[188].substring(2,digit[188].length()-1)).trim());
}
// 第七天
seven.setWeeks(digit[222]);
seven.setTodayDate(digit[219]+"/"+digit[220]);
seven.setWeather(digit[236]);
seven.setWindPowerOne(digit[232]);
seven.setWindPowerTwo(digit[234]);
if(digit[214] !=null) {
seven.setHighestTemperature((digit[214].substring(2,digit[214].length()-1)).trim());
}
if(digit[216] !=null) {
seven.setLowestTemperature((digit[216].substring(2,digit[216].length()-1)).trim());
}
}
br.close();//网上资源使用结束后,数据流及时关闭
isReader.close();
}
catch(Exception exp){
System.out.println(exp);
}
list.add(one);
list.add(two);
list.add(three);
list.add(four);
list.add(five);
list.add(six);
list.add(seven);
return list;
}