SpringBoot
SpringBoot开发经验
冬天的碎冰冰
这个作者很懒,什么都没留下…
展开
-
SpringBoot条件查询导出Excel数据
总结:写excel首行表头信息 String[] headers = { "ID", "姓名"}获取查询数据 userService.findAll();遍历数据,写入excel /** * excel导出 * @param response * @throws IOException */ @RequestMapping(value = "downloadExcel", method = RequestMethod.GET) public原创 2020-11-03 09:25:02 · 673 阅读 · 0 评论 -
ExcelUtils(导入Excel转换实体类)
总结首先创建实体类,然后新建excel文件,第一行的值为Project对应的属性值。写数据访问对象ProjectDao ,继承自JpaRepository。ExcelUtils 通用工具类读取excel文件,根据project对象的属性对应赋值(可以实现数据格式的转换,如日期,时间戳,枚举、基本类型),生成project对象。FileController将数据保存到数据库。1、Project 实体类public class Project { private String id;原创 2020-11-03 09:01:31 · 5542 阅读 · 3 评论 -
DO转换DTO
public class BeanDtoUtils<V, E> { /** * TODO Do 转换 DTO * 同:BeanUtils.copyProperties(dtoEntity, newInstance); * * @param oldClass 原数据--Dto,Vo,entity * @param newClass 转换为--Dto,Vo,entity * @return */ publi.原创 2021-06-02 15:28:45 · 1344 阅读 · 3 评论 -
.stream().collect():流对象迭代处理
1 、对象转换为流,迭代处理:将List< UserDto >相同用户分到一个数组中,list.stream().collect().forEach()List<UserDto> list = userDao.findAll();List<List<UserDto>> groupList = new ArrayList<>();list.stream() .collect(Collectors.groupingBy(UserDto::ge原创 2020-11-05 17:20:00 · 717 阅读 · 1 评论 -
JPA中Specification方法
jpa自定义findAll步骤一:继承JpaRepository@Repositorypublic interface ProjectDao extends JpaRepository<Project, String> { int countByProjectNameAndIdNot(String projectName, String id); Page<Project> findAll(Specification<Project> speci原创 2020-10-30 10:42:00 · 3276 阅读 · 0 评论 -
EntityManager 自定义查询结果分装为实体类
EntityManager 使用方法 @Autowired EntityManager entityManager; @Autowired private Gson gson; /** * 一、领导统计分析 * 1-根据时间计算所有员工工时比 * * @param * @return */ @Override public List<LeaderStatisticTimeDto> st原创 2020-10-30 10:15:29 · 801 阅读 · 0 评论 -
导出Excel样式设置
导出步骤1、创建 workbook.createSheet2、 获取查询数据3、创建行 sheet.createRow(0);设置行高 row.setHeight((short) 600);4、创建列 row.createCell(i);设置行宽 sheet.setColumnWidth(i, 4000);设置单元格样式 cell.setCellStyle(getColumnTopStyle(workbook));excel 单元格样式package ccsah.avatar.we.原创 2020-11-18 09:29:09 · 2816 阅读 · 0 评论 -
SpringBoot实现Excel上传与下载
文件上传@RequestMapping(value = "/doImportExcel", method = RequestMethod.POST) @ApiOperation(value = "上传excel") public Map<String, Object> doUpload(@RequestParam("file") MultipartFile file) { Map<String, Object> result = new HashMa原创 2020-11-03 08:39:03 · 560 阅读 · 0 评论