提交 77113ed1 编写于 作者: Q qinyingjie

fix:添加定时任务

上级 00158d24
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId> <artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.6</version> <version>2.6.6</version>
<relativePath/> <!-- lookup parent from repository --> <relativePath/> <!-- lookup parent from repository -->
</parent> </parent>
<groupId>com.kwan</groupId> <groupId>com.kwan</groupId>
...@@ -17,47 +17,16 @@ ...@@ -17,47 +17,16 @@
<java.version>1.8</java.version> <java.version>1.8</java.version>
</properties> </properties>
<dependencies> <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/com.alibaba/druid --> <!-- https://mvnrepository.com/artifact/com.alibaba/druid -->
<dependency> <dependency>
<groupId>com.alibaba</groupId> <groupId>com.alibaba</groupId>
<artifactId>druid</artifactId> <artifactId>druid</artifactId>
<version>1.2.3</version> <version>1.2.3</version>
</dependency> </dependency>
<!-- 引入swagger2包 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<!-- 引入自带UI,可选-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
<!-- 模板引擎 -->
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-engine-core</artifactId>
<version>2.0</version>
</dependency>
<!-- lang3--> <!-- lang3-->
<dependency> <dependency>
<groupId>org.apache.commons</groupId> <groupId>org.apache.commons</groupId>
...@@ -68,19 +37,18 @@ ...@@ -68,19 +37,18 @@
<dependency> <dependency>
<groupId>com.baomidou</groupId> <groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId> <artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.4.3.1</version> <version>3.4.3</version>
</dependency> </dependency>
<!--mysql驱动--> <!--mysql驱动-->
<dependency> <dependency>
<groupId>mysql</groupId> <groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId> <artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope> <version>8.0.11</version>
</dependency> </dependency>
<!--简化代码的工具包--> <!--简化代码的工具包-->
<dependency> <dependency>
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId> <artifactId>lombok</artifactId>
<optional>true</optional>
</dependency> </dependency>
<!--测试--> <!--测试-->
<dependency> <dependency>
...@@ -88,15 +56,6 @@ ...@@ -88,15 +56,6 @@
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>
......
package com.kwan.springbootkwan; package com.kwan.springbootkwan;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.EnableScheduling;
@EnableScheduling @EnableScheduling
@SpringBootApplication @SpringBootApplication
public class SpringBootKwanApplication { public class SpringBootKwanApplication {
......
package com.kwan.springbootkwan.config;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@MapperScan("com.kwan.springbootkwan.mapper")//扫描我们的mapper文件夹 这里添加了@MapperScan注解就不需要Springboot启动类上加入@MapperScan注解了
@EnableTransactionManagement //事务控制
@Configuration //配置类
public class MyBatisPlusConfig {
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor(){
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
//注册乐观锁插件
interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
//分页插件
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
return interceptor;
}
}
package com.kwan.springbootkwan.config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
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.EnableSwagger2;
/**
* Swagger2配置
*
* @author : qinyingjie
* @version : 2.2.0
* @date : 2022/12/9 11:33
*/
@Configuration
@EnableSwagger2
@ConfigurationProperties(prefix = "swagger")
public class Swagger2 {
private static final String BASE_PACKAGE = "com.kwan.springbootkwan";
@Value("${swagger.enable}")
private boolean enableSwagger;
@Bean
public Docket helloDocket() {
return new Docket(DocumentationType.SWAGGER_2)
//用于分组功能,也可以不配置
.groupName("admin")
//注册整体api信息
.apiInfo(apiInfo())
//swagger功能是否启用,可以通过配置设置,也可以先写死
.enable(enableSwagger)
.select()
//指定扫描的包
.apis(RequestHandlerSelectors.basePackage(BASE_PACKAGE))
//设置此组只匹配admin/**的请求
.paths(PathSelectors.ant("/admin/**"))
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder().title("后台管理项目")
.description("通用的CRUD")
.contact(new Contact("Van", "", ""))
.version("1.0.0")
.build();
}
}
\ No newline at end of file
package com.kwan.springbootkwan.controller;
import com.kwan.springbootkwan.entity.User;
import com.kwan.springbootkwan.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/user")
public class UserController {
@Autowired
private IUserService userService;
@RequestMapping(value = "/all", method = RequestMethod.GET)
public List<User> addAdvertise() {
return userService.getUsers();
}
@RequestMapping(value = "/getUserById/{id}", method = RequestMethod.GET)
public User getUserById(@PathVariable Integer id) {
return userService.getUserById(id);
}
}
\ No newline at end of file
...@@ -5,15 +5,11 @@ import com.baomidou.mybatisplus.annotation.TableName; ...@@ -5,15 +5,11 @@ import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Builder; import lombok.Builder;
import lombok.Data; import lombok.Data;
import java.io.Serializable;
@Data @Data
@Builder @Builder
@TableName(value = "User")//指定表名 @TableName(value = "user")
public class User implements Serializable { public class User {
private static final long serialVersionUID = -5644799954031156649L; @TableId(value = "id", type = IdType.AUTO)
//value与数据库主键列名一致,若实体类属性名与表主键列名一致可省略value
@TableId(value = "id", type = IdType.AUTO)//指定自增策略
private Integer id; private Integer id;
private String name; private String name;
private String sex; private String sex;
......
package com.kwan.springbootkwan.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.kwan.springbootkwan.entity.User;
import org.springframework.stereotype.Repository;
//@Mapper
@Repository // 代表持久层
public interface UserMapper extends BaseMapper<User> {
}
package com.kwan.springbootkwan.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.kwan.springbootkwan.entity.User;
import java.util.List;
public interface IUserService extends IService<User> {
/**
* 获取所有用户
*
* @return
*/
List<User> getUsers();
/**
* 获取一个用户
*
* @return
*/
User getUserById(Integer id);
}
package com.kwan.springbootkwan.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kwan.springbootkwan.entity.User;
import com.kwan.springbootkwan.mapper.UserMapper;
import com.kwan.springbootkwan.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {
@Autowired
private UserMapper userMapper;
@Override
public List<User> getUsers() {
return userMapper.selectList(null);
}
@Override
public User getUserById(Integer id) {
return userMapper.selectById(id);
}
}
\ No newline at end of file
...@@ -9,16 +9,27 @@ spring: ...@@ -9,16 +9,27 @@ spring:
mvc: mvc:
pathmatch: pathmatch:
matching-strategy: ant_path_matcher matching-strategy: ant_path_matcher
profiles:
active: dev
# mysql # mysql
datasource: datasource:
driver-class-name: com.mysql.cj.jdbc.Driver driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/kwan?useSSL=false&useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&serverTimezone=Asia/Shanghai url: jdbc:mysql://127.0.0.1:3306/kwan?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
username: root username: root
password: 716288qwe password: 716288qwe
#mybatis-plus配置
mybatis-plus: mybatis-plus:
mapper-locations: mapper/*.xml
configuration: configuration:
map-underscore-to-camel-case: true
call-setters-on-nulls: true
auto-mapping-behavior: full
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
map-underscore-to-camel-case: true mapper-locations: classpath*:mapper/**/*Mapper.xml
\ No newline at end of file global-config:
banner: false
# 逻辑删除配置
db-config:
id-type: AUTO
logic-delete-field: delFlag
logic-delete-value: 1
logic-not-delete-value: 0
table-underline: true
\ No newline at end of file
<!--<?xml version="1.0" encoding="UTF-8"?>--> <?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">--> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!--<mapper namespace="com.kwan.springbootkwan.mapper.UserMapper">--> <mapper namespace="com.kwan.springbootkwan.mapper.UserMapper">
<!--</mapper>-->
</mapper>
//package com.kwan.springbootkwan; package com.kwan.springbootkwan;
//
// import com.kwan.springbootkwan.entity.User;
//import com.kwan.springbootkwan.entity.User; import com.kwan.springbootkwan.mapper.UserMapper;
//import com.kwan.springbootkwan.service.impl.UserServiceImpl; import org.junit.jupiter.api.Test;
//import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest;
//import org.springframework.boot.test.context.SpringBootTest;
//
//import java.util.ArrayList;
//import java.util.List; @SpringBootTest
// public class UserServiceImplTest {
//
//@SpringBootTest @Autowired
//public class UserServiceImplTest { private UserMapper userService;
//
// @Autowired @Test
// UserServiceImpl userService; public void queryAll() {
// @Test User user = userService.selectById(1);
// public void queryAll() { System.out.println(user);
// userService.queryAll().forEach(System.out::println); }
// } }
// \ No newline at end of file
// @Test
// public void add() {
// List<User> users = new ArrayList<>();
// for (int i = 0; i < 15; ++i) {
// User user = User.builder().id(i + 1).name("test" + i).sex(i % 2 == 0 ? "男" : "女").pwd("aaaa").email("123" + i + "@qq.com").build();
//
// users.add(user);
// }
// users.forEach(System.out::println);
// userService.add(users);
//
//
// }
//
// @Test
// public void query() {
// userService.queryAll().forEach(System.out::println);
//
// userService.queryByName1("test1").forEach(System.out::println);
// userService.queryByName2("test1").forEach(System.out::println);
// User user = userService.queryById(User.builder().id(2).build());
// System.out.println(user);
// userService.queryByNameMap("test1").forEach(System.out::println);
// System.out.println(userService.count());
// }
//
// @Test
// public void delete() {
// User user = User.builder().id(2).build();
// userService.deleteById(user);
//
// userService.deleteBy("name", "test15");
//
// userService.deleteByIds();
//
// }
//
// @Test
// public void change() {
// User user1 = User.builder().name("蔡徐坤").build();
// userService.changeBy(user1, "sex", "男");
//
// user1.setName("蔡徐坤2");
// userService.changeUserById(user1);
// }
//
//// public void test1(){
//// userService.register()
//// }
//
//}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册