设为首页 加入收藏

TOP

Spring boot 整合各种功能(三)
2023-08-26 21:10:53 】 浏览:60
Tags:Spring boot
List<Emp> emps = empDao.selectAll(); PageInfo<Emp> pageInfo=new PageInfo<>(emps); return new Result(200,"查询成功",pageInfo); } }

(6)controller接口层

package com.zjw.controller;

import com.zjw.entity.Emp;
import com.zjw.service.EmpService;
import com.zjw.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/emp")
public class EmpController {
    @Autowired
    private EmpService empService;
    @DeleteMapping
    public Result deleteById(Integer id){
        return empService.deleteById(id);
    }

    @PostMapping
    public Result insert(@RequestBody Emp emp){
        return empService.insert(emp);
    }

    @PutMapping
    public Result update(@RequestBody Emp emp){
        return empService.update(emp);
    }

    @GetMapping
    public Result getById(Integer id){
        return empService.findById(id);
    }


    @GetMapping("/getAll")
    public Result getAll(Integer current,Integer pageSize){
        return empService.findAll(current, pageSize);
    }
}

8. springboot整合定时器。

可以在规定的时间内执行相应的代码。

比如: OSS文件上传---OSS的文件冗余的文件。----OSS的浪费。---->指定的时间自动删除。[夜间删除]

比如: 下单--->30分钟未支付---取消订单。

(1)引入定时器的依赖--


        <!--引入定时器-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-quartz</artifactId>
        </dependency>

(2)编写定义的业务代码

@Component
public class My {

    @Autowired
    private EmpDao empDao;
    //定时任务执行的代码
    @Scheduled(cron = "0 0 2 * * ?")
    public void show(){
        System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~");
        //可以写自己的写完代码
        empDao.delete();
    }
}

(3)开启定时的注解驱动

1692349987813

首页 上一页 1 2 3 4 下一页 尾页 3/4/4
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇java与es8实战之一:以builder pa.. 下一篇《深入理解Java虚拟机》读书笔记..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目