This commit is contained in:
wyb 2023-08-13 18:25:36 +08:00
parent fdc901e84d
commit e28686efd0
10 changed files with 308 additions and 0 deletions

33
jacoco/jacoco-demo/.gitignore vendored Normal file
View File

@ -0,0 +1,33 @@
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/

View File

@ -0,0 +1,73 @@
<?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>
<groupId>com.ybw</groupId>
<artifactId>jacoco-demo</artifactId>
<version>1.0.0</version>
<name>jacoco-demo</name>
<description>jacoco-demo</description>
<properties>
<java.version>17</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<spring-boot.version>3.0.2</spring-boot.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</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>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>17</source>
<target>17</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot.version}</version>
<executions>
<execution>
<id>repackage</id>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,13 @@
package com.ybw;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class JacocoDemoApplication {
public static void main(String[] args) {
SpringApplication.run(JacocoDemoApplication.class, args);
}
}

View File

@ -0,0 +1,40 @@
package com.ybw.controller;
import com.ybw.service.UserService;
import com.ybw.vo.UserVO;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 用户
*
* @author ybw
* @version V1.0
* @className TestController
* @date 2023/8/13
**/
@Slf4j
@RequestMapping("/user")
@RestController
public class UserController {
@Resource
private UserService userService;
/**
* 获取用户
*
* @param id
* @methodName: getUser
* @return: com.ybw.vo.UserVO
* @author: ybw
* @date: 2023/8/13
**/
@GetMapping("/getUser")
public UserVO getUser(Long id) {
return userService.getUser(id);
}
}

View File

@ -0,0 +1,20 @@
package com.ybw.service;
import com.ybw.vo.UserVO;
/**
* @author ybw
* @version V1.0
* @className UserService
* @date 2023/8/13
**/
public interface UserService {
/**
* @param id
* @methodName: getUser
* @return: com.ybw.vo.UserVO
* @author: ybw
* @date: 2023/8/13
**/
UserVO getUser(Long id);
}

View File

@ -0,0 +1,29 @@
package com.ybw.service.impl;
import com.ybw.service.UserService;
import com.ybw.vo.UserVO;
import org.springframework.stereotype.Service;
/**
* @author ybw
* @version V1.0
* @className UserServiceImpl
* @date 2023/8/13
**/
@Service
public class UserServiceImpl implements UserService {
@Override
public UserVO getUser(Long id) {
if (id.equals(1L)) {
return new UserVO(1L, "张三1");
}
if (id.equals(2L)) {
return new UserVO(2L, "张三2");
}
if (id.equals(3L)) {
return new UserVO(3L, "张三3");
}
return new UserVO(10L, "张三10");
}
}

View File

@ -0,0 +1,19 @@
package com.ybw.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author ybw
* @version V1.0
* @className UserVO
* @date 2023/8/13
**/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class UserVO {
private Long id;
private String name;
}

View File

@ -0,0 +1,2 @@
server:
port: 8080

View File

@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!--定义日志文件的存储地址 勿在 LogBack 的配置中使用相对路径 -->
<!-- <property name="LOG_HOME" value="d:" /> -->
<!-- ch.qos.logback.core.ConsoleAppender 控制台输出 -->
<appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %logger{36} - %msg%n
</pattern>
</encoder>
</appender>
<!-- error日志输出 -->
<appender name="ErrorFile"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>${LOG_HOME:-c:/}logs/error/error.log</File>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<FileNamePattern>${LOG_HOME:-c:/}logs/error/error-%d{yyyy-MM-dd}.%i.log
</FileNamePattern>
<!--日志保留天数-->
<MaxHistory>3600</MaxHistory>
<TimeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<MaxFileSize>100MB</MaxFileSize>
</TimeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %logger{36} - %msg%n
</pattern>
</layout>
<filter class="ch.qos.logback.classic.filter.LevelFilter"><!-- 只打印错误日志 -->
<level>ERROR</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<!-- 所有日志输出 -->
<appender name="AllFile"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>${LOG_HOME:-c:/}logs/all/all.log</File>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<FileNamePattern>${LOG_HOME:-c:/}logs/all/all-%d{yyyy-MM-dd}.%i.log
</FileNamePattern>
<MaxHistory>3600</MaxHistory>
<TimeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<MaxFileSize>100MB</MaxFileSize>
</TimeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %logger{36} - %msg%n
</pattern>
</layout>
</appender>
<root level="info">
<appender-ref ref="stdout"/>
<appender-ref ref="ErrorFile"/>
<appender-ref ref="AllFile"/>
</root>
</configuration>

View File

@ -0,0 +1,13 @@
package com.ybw;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class JacocoDemoApplicationTests {
@Test
void contextLoads() {
}
}