java中使用POI生成Excel并導(dǎo)出過(guò)程
注:本文章中代碼均為本地Demo版本,若后續(xù)代碼更新將不會(huì)更新文章
需求說(shuō)明及實(shí)現(xiàn)方式
1.根據(jù)從數(shù)據(jù)庫(kù)查詢出的數(shù)據(jù),將其寫入excel表并導(dǎo)出
- 我的想法是通過(guò)在實(shí)體屬性上寫自定義注解的方式去完成。因?yàn)槲覀冊(cè)诖a中可以通過(guò)反射的方式去獲取實(shí)體類中全部的注解及屬性名稱等等。
- 我們可以在自定義注解中聲明一個(gè)參數(shù)
value,這里面就存儲(chǔ)其標(biāo)題,這樣我們
2.數(shù)據(jù)查詢type不同,則顯示的標(biāo)題數(shù)量不同
- 在注解類中增加
type參數(shù) - 只有滿足對(duì)應(yīng)
type的屬性會(huì)被導(dǎo)出至excel中
3.數(shù)據(jù)查詢type不同,則顯示的標(biāo)題不同(同一個(gè)字段)
- 優(yōu)化參數(shù)
value,判斷傳入的value是否為json字符串,如果是json字符串則找到其與type對(duì)應(yīng)的value
4.數(shù)據(jù)的格式化(時(shí)間類型格式化、數(shù)據(jù)格式化顯示)
- 數(shù)據(jù)格式化顯示通過(guò)在注解類中增加
dict參數(shù),該參數(shù)傳入json字符串。
本來(lái)我是想著通過(guò)easyExcel來(lái)完成這些功能,但是由于項(xiàng)目中已經(jīng)引入了POI的3.9版本依賴,然后easyExcel中POI的依賴版本又高于該版本,而且不管是版本升級(jí)還是版本排除降級(jí),總會(huì)有一個(gè)出現(xiàn)問(wèn)題,最終也只能通過(guò)最基礎(chǔ)的POI編寫代碼實(shí)現(xiàn)。
需求完成
依賴引入:
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.33</version>
</dependency>
通用代碼
1.ExcelExport
value:標(biāo)題,也可為json字符串dict:json字符串格式的字典,格式如User中所示type:數(shù)組類型,查詢數(shù)據(jù)type類型是什么值時(shí)這個(gè)字段會(huì)寫入excel中。如我type = {"a"},則我在查詢數(shù)據(jù)時(shí)傳入的type為b則不會(huì)將這個(gè)字段寫入excel中,如果傳入的是a則會(huì)正常寫入。
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface ExcelExport {
String value();
String dict() default "";
String[] type() default {};
}2.User
@ExcelExport:即自定義的注解,其中值的含義在上面已經(jīng)說(shuō)清楚了
@Data
@AllArgsConstructor
@NoArgsConstructor
@Accessors(chain = true)
public class User {
@ExcelExport(value = "用戶名",type = {"a"})
private String userName;
@ExcelExport(value = "{a: '年齡',b: '年紀(jì)'}",type = {"a","b"})
private Integer age;
@ExcelExport(value = "性別",
dict = "[{ value: \"0\", label: \"女\" }," +
"{ value: \"1\", label: \"男\(zhòng)" }]",
type = {"a","b"})
private Integer sex;
@ExcelExport(value = "生日",type = {"b"})
private Date birthday;
}
版本1
版本1中未實(shí)現(xiàn)數(shù)據(jù)查詢type不同,則顯示的標(biāo)題不同(同一個(gè)字段)這一功能,如需要加請(qǐng)看PoiExcelUtil中writeTitleCellData方法。
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.lzj.anno.ExcelExport;
import com.lzj.entity.User;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.*;
import org.springframework.util.StringUtils;
import java.io.*;
import java.lang.reflect.Field;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* <p>
*
* </p>
*
* @author:雷子杰
* @date:2023/7/4
*/
public class One {
public static void main(String[] args) throws IOException {
List<User> userList = new ArrayList<>();
userList.add(new User("lzj1",1,1,new Date()));
userList.add(new User("lzj2",2,0,new Date()));
userList.add(new User("lzj3",3,1,new Date()));
userList.add(new User("lzj4",4,0,new Date()));
//聲明XSSF對(duì)象
XSSFWorkbook xssfSheets = new XSSFWorkbook();
//創(chuàng)建sheet
XSSFSheet userSheet = xssfSheets.createSheet("user");
//創(chuàng)建標(biāo)題字體
XSSFFont titleFont = xssfSheets.createFont();
titleFont.setBold(true);//加粗
titleFont.setFontName("微軟雅黑");
titleFont.setFontHeightInPoints((short) 12);//字體大小
//創(chuàng)建通用字體
XSSFFont commonFont = xssfSheets.createFont();
commonFont.setBold(false);//加粗
commonFont.setFontName("微軟雅黑");
commonFont.setFontHeightInPoints((short) 12);//字體大小
// 創(chuàng)建標(biāo)題行單元格樣式
CellStyle titleCellStyle = xssfSheets.createCellStyle();
titleCellStyle.setBorderTop(CellStyle.BORDER_THIN);//框線
titleCellStyle.setBorderBottom(CellStyle.BORDER_THIN);
titleCellStyle.setBorderLeft(CellStyle.BORDER_THIN);
titleCellStyle.setBorderRight(CellStyle.BORDER_THIN);
titleCellStyle.setAlignment(CellStyle.ALIGN_CENTER);//水平對(duì)齊方式
titleCellStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);//垂直對(duì)齊方式
titleCellStyle.setFont(titleFont);//字體樣式
titleCellStyle.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);//單元格前景色
titleCellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);//填充單元格
//創(chuàng)建通用行單元格樣式
CellStyle commonCellStyle = xssfSheets.createCellStyle();
commonCellStyle.setBorderTop(CellStyle.BORDER_THIN);
commonCellStyle.setBorderBottom(CellStyle.BORDER_THIN);
commonCellStyle.setBorderLeft(CellStyle.BORDER_THIN);
commonCellStyle.setBorderRight(CellStyle.BORDER_THIN);
commonCellStyle.setAlignment(CellStyle.ALIGN_CENTER);
commonCellStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
commonCellStyle.setFont(commonFont);
commonCellStyle.setWrapText(true);//自動(dòng)換行
//獲取實(shí)體類中全部屬性
Field[] fields = User.class.getDeclaredFields();
//當(dāng)前行
int currentRow = 0;
//當(dāng)前列
int currentColumn = 0;
//行高
float rowHeight = 40.1f;
//列寬
int columnWidth = 33 * 256;
//創(chuàng)建行
XSSFRow row = userSheet.createRow(currentRow);
當(dāng)前行+1
//currentRow++;
//創(chuàng)建標(biāo)題行
// 遍歷每個(gè)字段
for (Field field : fields) {
// 檢查字段是否帶有Explanation注解
if (field.isAnnotationPresent(ExcelExport.class)) {
// 獲取Explanation注解實(shí)例
ExcelExport explanation = field.getAnnotation(ExcelExport.class);
// 獲取注解中的解釋
String value = explanation.value();
//創(chuàng)建單元格,傳入值,設(shè)置單元格樣式
XSSFCell cell = row.createCell(currentColumn);
cell.setCellValue(value);
cell.setCellStyle(titleCellStyle);
//設(shè)置行高度
row.setHeightInPoints(rowHeight);
//設(shè)置列的寬度
userSheet.setColumnWidth(currentColumn,columnWidth);
//當(dāng)前列+1
currentColumn++;
}
}
//重置當(dāng)前列
currentColumn = 0;
//創(chuàng)建數(shù)據(jù)行
for (User user : userList) {
//每次循環(huán)時(shí)重置列
currentColumn = 0;
//當(dāng)前行+1
currentRow++;
//創(chuàng)建行
row = userSheet.createRow(currentRow);
for (Field field : fields) {
if (field.isAnnotationPresent(ExcelExport.class)) {
try {
//解除private限制
field.setAccessible(true);
// 獲取Explanation注解實(shí)例
ExcelExport explanation = field.getAnnotation(ExcelExport.class);
// 獲取屬性的值
Object value = field.get(user);
//日期類型格式化
if (value != null && field.getType() == Date.class){
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
value = sdf.format(value);
}
//獲取對(duì)應(yīng)字典
String dict = explanation.dict();
if (!StringUtils.isEmpty(dict) && value != null){
//JSONObject jsonObject = JSON.parseObject(dict);
List<String> list = JSON.parseArray(dict, String.class);
for (String item : list) {
JSONObject jsonObject = JSON.parseObject(item);
if(value == null ? false : jsonObject.getString("value").equals(value.toString()) ){
value = jsonObject.getString("label");
break;
}
}
//value = jsonObject.get(value.toString());
}
//創(chuàng)建單元格,傳入值,設(shè)置單元格樣式
XSSFCell cell = row.createCell(currentColumn);
cell.setCellValue(value == null?"":value.toString());
cell.setCellStyle(commonCellStyle);
//設(shè)置行高度
row.setHeightInPoints(rowHeight);
//當(dāng)前列+1
currentColumn++;
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}
}
// 將生成的excel文件輸出流轉(zhuǎn)為字節(jié)數(shù)組
byte[] bytes = null;
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
xssfSheets.write(outputStream);
outputStream.close();
bytes = outputStream.toByteArray();
//讀取字節(jié)數(shù)組為文件輸入流
InputStream inputStream = new ByteArrayInputStream(bytes);
inputStream.close();
//在聲明一個(gè)輸出流將文件下載到本地
File file = new File("C:\\Users\\86158\\Desktop\\zzzzzz.xlsx");
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(file));
//將bytes中的內(nèi)容寫入
bufferedOutputStream.write(bytes);
//刷新輸出流,否則不會(huì)寫出數(shù)據(jù)
bufferedOutputStream.flush();
bufferedOutputStream.close();
}
}版本2
版本二相比與版本1,其主要優(yōu)勢(shì)是將POI相關(guān)操作都封裝進(jìn)了PoiExcelUtil中。
PoiExcelUtil
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.lzj.anno.ExcelExport;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.xssf.usermodel.*;
import org.springframework.util.StringUtils;
import java.lang.reflect.Field;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* <p>
*
* </p>
*
* @author:雷子杰
* @date:2023/7/6
*/
public class PoiExcelUtil {
/**
* 獲取標(biāo)題字體
* @param xssfWorkbook
* @return
*/
public static XSSFFont getTitleFont(XSSFWorkbook xssfWorkbook){
//創(chuàng)建標(biāo)題字體
XSSFFont titleFont = xssfWorkbook.createFont();
titleFont.setBold(true);//加粗
titleFont.setFontName("微軟雅黑");
titleFont.setFontHeightInPoints((short) 12);//字體大小
return titleFont;
}
/**
* 獲取通用字體
* @param xssfWorkbook
* @return
*/
public static XSSFFont getCommonFont(XSSFWorkbook xssfWorkbook){
//創(chuàng)建通用字體
XSSFFont commonFont = xssfWorkbook.createFont();
commonFont.setBold(false);//加粗
commonFont.setFontName("微軟雅黑");
commonFont.setFontHeightInPoints((short) 12);//字體大小
return commonFont;
}
/**
* 獲取標(biāo)題單元格樣式
* @param xssfWorkbook
* @param xssfFont
* @return
*/
public static CellStyle getTitleCellStyle(XSSFWorkbook xssfWorkbook , XSSFFont xssfFont){
// 創(chuàng)建標(biāo)題行單元格樣式
CellStyle titleCellStyle = xssfWorkbook.createCellStyle();
titleCellStyle.setBorderTop(CellStyle.BORDER_THIN);//框線
titleCellStyle.setBorderBottom(CellStyle.BORDER_THIN);
titleCellStyle.setBorderLeft(CellStyle.BORDER_THIN);
titleCellStyle.setBorderRight(CellStyle.BORDER_THIN);
titleCellStyle.setAlignment(CellStyle.ALIGN_CENTER);//水平對(duì)齊方式
titleCellStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);//垂直對(duì)齊方式
titleCellStyle.setFont(xssfFont);//字體樣式
titleCellStyle.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);//單元格前景色
titleCellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);//填充單元格
return titleCellStyle;
}
/**
* 獲取通用單元格樣式
* @param xssfWorkbook
* @param xssfFont
* @return
*/
public static CellStyle getCommonCellStyle(XSSFWorkbook xssfWorkbook, XSSFFont xssfFont){
//創(chuàng)建通用行單元格樣式
CellStyle commonCellStyle = xssfWorkbook.createCellStyle();
commonCellStyle.setBorderTop(CellStyle.BORDER_THIN);
commonCellStyle.setBorderBottom(CellStyle.BORDER_THIN);
commonCellStyle.setBorderLeft(CellStyle.BORDER_THIN);
commonCellStyle.setBorderRight(CellStyle.BORDER_THIN);
commonCellStyle.setAlignment(CellStyle.ALIGN_CENTER);
commonCellStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
commonCellStyle.setFont(xssfFont);
commonCellStyle.setWrapText(true);//自動(dòng)換行
return commonCellStyle;
}
/**
* 寫入單個(gè)單元格數(shù)據(jù)
* @param row 行對(duì)象
* @param xssfSheet sheet對(duì)象
* @param value 單元格的值
* @param cellStyle 單元格樣式
* @param rowHeight 行高
* @param columnWidth 列寬
*/
public static void writeCellData(XSSFRow row, XSSFSheet xssfSheet , Object value ,CellStyle cellStyle,Integer currentColumn,Float rowHeight,Integer columnWidth){
//創(chuàng)建單元格,傳入值,設(shè)置單元格樣式
XSSFCell cell = row.createCell(currentColumn);
cell.setCellValue(value == null ? "" : value.toString());
cell.setCellStyle(cellStyle);
//設(shè)置行高度
row.setHeightInPoints(rowHeight);
//設(shè)置列的寬度
xssfSheet.setColumnWidth(currentColumn,columnWidth);
}
/**
*
* @param row 行對(duì)象
* @param xssfSheet sheet對(duì)象
* @param cellStyle 單元格樣式
* @param fields 反射獲取得到的實(shí)體對(duì)象的全部屬性
* @param currentColumn 當(dāng)前列
* @param rowHeight 行高
* @param columnWidth 列寬
* @param type 類型
*/
public static void writeTitleCellData(XSSFRow row,XSSFSheet xssfSheet,CellStyle cellStyle,Field[] fields,Integer currentColumn,Float rowHeight,Integer columnWidth,String type){
//創(chuàng)建標(biāo)題行
// 遍歷每個(gè)字段
for (Field field : fields) {
// 檢查字段是否帶有ExcelExport注解
if (field.isAnnotationPresent(ExcelExport.class)) {
// 獲取Explanation注解實(shí)例
ExcelExport explanation = field.getAnnotation(ExcelExport.class);
//判斷是否是需要寫入的數(shù)據(jù)類型
String[] typeArray = explanation.type();
Set<String> set = new HashSet<>(Arrays.asList(typeArray));
if (!set.contains(type)){
continue;
}
// 獲取注解中的解釋
String value = explanation.value();
//判斷value是否是json格式數(shù)據(jù)
boolean isJson = true;
try{
Object parse = JSON.parse(value);
}catch (Exception e){
isJson = false;
}
if (isJson == true){//如果是json格式數(shù)據(jù),則給他對(duì)應(yīng)對(duì)應(yīng)類型的值
JSONObject jsonObject = JSON.parseObject(value);
value = jsonObject.getString(type);
}
//寫入單元格數(shù)據(jù)
PoiExcelUtil.writeCellData(row,xssfSheet,value,cellStyle,currentColumn,rowHeight,columnWidth);
//當(dāng)前列+1
currentColumn++;
}
}
}
/**
* 將集合數(shù)據(jù)全部寫入單元格
* @param list 需要寫入excel的集合數(shù)據(jù)
* @param currentRow 當(dāng)前行
* @param currentColumn 當(dāng)前列
* @param row 行對(duì)象
* @param xssfSheet sheet對(duì)象
* @param cellStyle 單元格樣式
* @param fields 反射獲取得到的實(shí)體對(duì)象的全部屬性
* @param rowHeight 行高
* @param columnWidth 列寬
* @param type 類型
* @param <T>
*/
public static <T> void writeCommonRowCellData(List<T> list,Integer currentRow ,Integer currentColumn, XSSFRow row,XSSFSheet xssfSheet,CellStyle cellStyle,Field[] fields,Float rowHeight,Integer columnWidth,String type){
//創(chuàng)建數(shù)據(jù)行
for (T obj : list) {
//每次循環(huán)時(shí)重置列
currentColumn = 0;
//當(dāng)前行+1
currentRow++;
//創(chuàng)建行
row = xssfSheet.createRow(currentRow);
for (Field field : fields) {
// 檢查字段是否帶有ExcelExport注解
if (field.isAnnotationPresent(ExcelExport.class)) {
try {
//解除private限制
field.setAccessible(true);
// 獲取Explanation注解實(shí)例
ExcelExport explanation = field.getAnnotation(ExcelExport.class);
//判斷是否是需要寫入的數(shù)據(jù)類型
String[] typeArray = explanation.type();
Set<String> set = new HashSet<>(Arrays.asList(typeArray));
if (!set.contains(type)){
continue;
}
// 獲取屬性的值
Object value = field.get(obj);
//日期類型格式化
if (value != null && field.getType() == Date.class){
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
value = sdf.format(value);
}
//獲取對(duì)應(yīng)字典
String dict = explanation.dict();
if (!StringUtils.isEmpty(dict) && value != null){
List<String> parseArray = JSON.parseArray(dict, String.class);
for (String item : parseArray) {
JSONObject jsonObject = JSON.parseObject(item);
if(value == null ? false : jsonObject.getString("value").equals(value.toString()) ){
value = jsonObject.getString("label");
break;
}
}
}
//寫入單元格數(shù)據(jù)
PoiExcelUtil.writeCellData(row,xssfSheet,value,cellStyle,currentColumn,rowHeight,columnWidth);
//當(dāng)前列+1
currentColumn++;
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}
}
}
}
Two
import com.lzj.entity.User;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.xssf.usermodel.*;
import java.io.*;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* <p>
*
* </p>
*
* @author:雷子杰
* @date:2023/7/4
*/
public class Two {
public static void main(String[] args) throws IOException {
List<User> userList = new ArrayList<>();
userList.add(new User("lzj1",1,1,new Date()));
userList.add(new User("lzj2",2,0,new Date()));
userList.add(new User("lzj3",3,1,new Date()));
userList.add(new User("lzj4",4,0,new Date()));
//聲明XSSF對(duì)象
XSSFWorkbook xssfWorkbook = new XSSFWorkbook();
//創(chuàng)建sheet
XSSFSheet userSheet = xssfWorkbook.createSheet("user");
//創(chuàng)建標(biāo)題字體
XSSFFont titleFont = PoiExcelUtil.getTitleFont(xssfWorkbook);
//創(chuàng)建通用字體
XSSFFont commonFont = PoiExcelUtil.getCommonFont(xssfWorkbook);
// 創(chuàng)建標(biāo)題行單元格樣式
CellStyle titleCellStyle = PoiExcelUtil.getTitleCellStyle(xssfWorkbook,titleFont);
//創(chuàng)建通用行單元格樣式
CellStyle commonCellStyle = PoiExcelUtil.getCommonCellStyle(xssfWorkbook,commonFont);
//獲取實(shí)體類中全部屬性
Field[] fields = User.class.getDeclaredFields();
//當(dāng)前行
int currentRow = 0;
//當(dāng)前列
int currentColumn = 0;
//行高
float rowHeight = 40.1f;
//列寬
int columnWidth = 33 * 256;
//創(chuàng)建行
XSSFRow row = userSheet.createRow(currentRow);
//創(chuàng)建標(biāo)題行
PoiExcelUtil.writeTitleCellData(row,userSheet,titleCellStyle,fields,currentColumn,rowHeight,columnWidth,"b");
//重置當(dāng)前列
currentColumn = 0;
//創(chuàng)建數(shù)據(jù)行
PoiExcelUtil.writeCommonRowCellData(userList,currentRow,currentColumn,row,userSheet,commonCellStyle,fields,rowHeight,columnWidth,"b");
// 將生成的excel文件輸出流轉(zhuǎn)為字節(jié)數(shù)組
byte[] bytes = null;
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
xssfWorkbook.write(outputStream);
outputStream.close();
bytes = outputStream.toByteArray();
//讀取字節(jié)數(shù)組為文件輸入流
InputStream inputStream = new ByteArrayInputStream(bytes);
inputStream.close();
//在聲明一個(gè)輸出流將文件下載到本地
File file = new File("C:\\Users\\86158\\Desktop\\zzzzzz.xlsx");
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(file));
//將bytes中的內(nèi)容寫入
bufferedOutputStream.write(bytes);
//刷新輸出流,否則不會(huì)寫出數(shù)據(jù)
bufferedOutputStream.flush();
bufferedOutputStream.close();
}
}結(jié)果展示
這是我初始化時(shí)的數(shù)據(jù)

下面的是我type參數(shù)不同時(shí)的數(shù)據(jù),均是以版本2來(lái)進(jìn)行的寫入導(dǎo)出。
type參數(shù)修改位置如下:

type參數(shù)為a

type參數(shù)為b

總結(jié)
在項(xiàng)目開(kāi)發(fā)過(guò)程中總會(huì)遇到各式各樣的問(wèn)題,只有不斷的學(xué)習(xí),不斷的積累,自身水平才能提高。
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Spring Boot集成spring-boot-devtools開(kāi)發(fā)時(shí)實(shí)現(xiàn)熱部署的方式
這篇文章主要介紹了Spring Boot集成spring-boot-devtools開(kāi)發(fā)時(shí)實(shí)現(xiàn)熱部署的方式,文中還給大家提到了spring boot 實(shí)現(xiàn)熱部署的方式及集成注意事項(xiàng),感興趣的朋友跟隨腳本之家小編一起學(xué)習(xí)吧2018-05-05
Java集合遍歷全指南(迭代器&增強(qiáng)for及列表迭代器)
本文詳盡介紹了Java集合遍歷的5種方式:迭代器、增強(qiáng)for、列表迭代器、普通for及Lambda表達(dá)式,通過(guò)代碼示例和原理解析,幫助讀者徹底掌握集合遍歷的核心知識(shí),避免常見(jiàn)錯(cuò)誤如并發(fā)修改異常和指針復(fù)位問(wèn)題,適合Java初學(xué)者及面試復(fù)習(xí),需要的朋友可以參考下2026-02-02
Springboot集成JSR303參數(shù)校驗(yàn)的方法實(shí)現(xiàn)
這篇文章主要介紹了Springboot集成JSR303參數(shù)校驗(yàn)的方法實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-09-09
springboot之SpringApplication生命周期和事件機(jī)制解讀
這篇文章主要介紹了springboot之SpringApplication生命周期和事件機(jī)制,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-06-06
Java畢業(yè)設(shè)計(jì)實(shí)戰(zhàn)項(xiàng)目之在線服裝銷售商城系統(tǒng)的實(shí)現(xiàn)流程
基礎(chǔ)掌握怎么樣,用實(shí)戰(zhàn)檢驗(yàn)就知道了,本篇文章手把手帶你用java+SpringBoot+Maven+Vue+mysql實(shí)現(xiàn)一個(gè)在線服裝銷售商城系統(tǒng),大家可以在過(guò)程中查缺補(bǔ)漏,提升水平2022-01-01
Spring-Validation 后端數(shù)據(jù)校驗(yàn)的實(shí)現(xiàn)
這篇文章主要介紹了Spring-Validation 后端數(shù)據(jù)校驗(yàn)的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-07-07
JVM類運(yùn)行機(jī)制實(shí)現(xiàn)原理解析
這篇文章主要介紹了JVM類運(yùn)行機(jī)制實(shí)現(xiàn)原理解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-12-12

