Commit 101e917d authored by xd's avatar xd

feo job init

parent 97160df9
Pipeline #3608 failed with stages
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.tanpu.feo</groupId>
<artifactId>feo-job</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>feo-job</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.2.0</version>
</dependency>
<dependency>
<groupId>p6spy</groupId>
<artifactId>p6spy</artifactId>
<version>3.9.1</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.4.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
package com.tanpu.feo.feojob;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
@MapperScan("com.tanpu.feo.feojob")
public class FeoJobApplication {
public static void main(String[] args) {
SpringApplication.run(FeoJobApplication.class, args);
}
}
package com.tanpu.feo.feojob.config;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.github.pagehelper.PageInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* created by xd on 2021/5/18
*/
@Configuration
public class MybatisPlusPageConfig {
/**
* pagehelper的分页插件
*/
@Bean
public PageInterceptor pageInterceptor() {
return new PageInterceptor();
}
/**
* 新的分页插件,一缓和二缓遵循mybatis的规则,需要设置 MybatisConfiguration#useDeprecatedExecutor = false 避免缓存出现问题
*/
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
return interceptor;
}
}
package com.tanpu.feo.feojob.controller;
import org.springframework.web.bind.annotation.RestController;
/**
* created by xd on 2021/5/18
*/
@RestController
public class DemoController {
}
package com.tanpu.feo.feojob.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tanpu.feo.feojob.entity.DemoEntity;
import org.apache.ibatis.annotations.Mapper;
/**
* created by xd on 2021/5/18
*/
@Mapper
public interface DemoMapper extends BaseMapper<DemoEntity> {
}
package com.tanpu.feo.feojob.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* created by xd on 2021/5/18
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@TableName("demo")
public class DemoEntity {
@TableId(type = IdType.AUTO)
private Long id;
private String name;
private Integer age;
}
package com.tanpu.feo.feojob.jobs;
/**
* created by xd on 2021/5/18
*/
public class WxcpOrgSyncJob {
}
package com.tanpu.feo.feojob.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tanpu.feo.feojob.dao.DemoMapper;
import com.tanpu.feo.feojob.entity.DemoEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* created by xd on 2021/5/18
*/
@Service
public class DemoService {
@Autowired
private DemoMapper demoMapper;
public List<DemoEntity> getByName(String name) {
return demoMapper.selectList(new LambdaQueryWrapper<DemoEntity>().eq(DemoEntity::getName, name));
}
}
server:
port: 8091
spring:
application:
name: feo-jobs
DELETE
FROM demo;
INSERT INTO demo (name, age)
VALUES ('Jone', 18),
('Jack', 21),
('Jack', 20),
('Jack', 19),
('Ted', 30),
('Billie', 18);
-- noinspection SqlNoDataSourceInspectionForFile
DROP TABLE IF EXISTS demo;
CREATE TABLE demo
(
id BIGINT(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
name VARCHAR(30) NOT NULL DEFAULT '' COMMENT '姓名',
age INTEGER(11) NOT NULL DEFAULT 0 COMMENT '年龄',
PRIMARY KEY (id)
);
package com.tanpu.feo.feojob;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class FeoJobApplicationTests {
@Test
void contextLoads() {
}
}
package com.tanpu.feo.feojob.dao;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanpu.feo.feojob.entity.DemoEntity;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
import java.util.List;
/**
* created by xd on 2021/5/18
*/
@RunWith(SpringRunner.class)
@SpringBootTest
public class DemoMapperTest {
@Resource
private DemoMapper demoMapper;
@Test
public void testSelect() {
List<DemoEntity> all = demoMapper.selectList(null);
Assert.assertTrue(all.size() > 0);
}
@Test
public void testPage() {
Page<DemoEntity> mpPage = demoMapper.selectPage(new Page<>(1, 2),
new QueryWrapper<DemoEntity>().lambda().gt(DemoEntity::getAge, 18));
List<DemoEntity> records = mpPage.getRecords();
Assert.assertEquals(2, records.size());
}
}
package com.tanpu.feo.feojob.service;
import com.tanpu.feo.feojob.entity.DemoEntity;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
import java.util.List;
/**
* created by xd on 2021/5/18
*/
@RunWith(SpringRunner.class)
@SpringBootTest
public class DemoServiceTest {
@Resource
private DemoService demoService;
@Test
public void testGetByName() {
List<DemoEntity> all = demoService.getByName("Jack");
Assert.assertEquals(3, all.size());
}
}
# DataSource Config
spring:
datasource:
driver-class-name: org.h2.Driver
schema: classpath:db/schema-h2.sql
data: classpath:db/data-h2.sql
url: jdbc:h2:mem:test
username: root
password: test
# Logger Config
logging:
level:
com.tanpu.feo.feojob: debug
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment