日考第八单元
commit
f4cec0be1e
|
@ -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/
|
|
@ -0,0 +1,78 @@
|
|||
<?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.bwie</groupId>
|
||||
<artifactId>day-08</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>day-08</name>
|
||||
<description>day-08</description>
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<spring-boot.version>2.6.13</spring-boot.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.itlym.shoulder</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>0.1</version>
|
||||
</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>1.8</source>
|
||||
<target>1.8</target>
|
||||
<encoding>UTF-8</encoding>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<version>${spring-boot.version}</version>
|
||||
<configuration>
|
||||
<mainClass>com.bw.Day08Application</mainClass>
|
||||
<skip>true</skip>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>repackage</id>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
Navicat Premium Data Transfer
|
||||
|
||||
Source Server : csh:47.102.213.213
|
||||
Source Server Type : MySQL
|
||||
Source Server Version : 80400
|
||||
Source Host : 47.102.213.213:3306
|
||||
Source Schema : g6_day08
|
||||
|
||||
Target Server Type : MySQL
|
||||
Target Server Version : 80400
|
||||
File Encoding : 65001
|
||||
|
||||
Date: 26/07/2024 09:15:27
|
||||
*/
|
||||
|
||||
SET NAMES utf8mb4;
|
||||
SET FOREIGN_KEY_CHECKS = 0;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for bill
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `bill`;
|
||||
CREATE TABLE `bill` (
|
||||
`id` int NOT NULL AUTO_INCREMENT,
|
||||
`date` datetime NULL DEFAULT NULL,
|
||||
`money` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
|
||||
`user_id` int NULL DEFAULT NULL,
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of bill
|
||||
-- ----------------------------
|
||||
INSERT INTO `bill` VALUES (1, '2024-07-10 09:15:13', '1', 1);
|
||||
|
||||
SET FOREIGN_KEY_CHECKS = 1;
|
|
@ -0,0 +1,13 @@
|
|||
package com.bw;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class Day08Application {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Day08Application.class, args);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
package com.bw.config;
|
||||
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.BitSet;
|
||||
|
||||
/**
|
||||
* @BelongsProject: month-10a
|
||||
* @BelongsPackage: com.bw.config
|
||||
* @Author: zhupengfei
|
||||
* @CreateTime: 2023-03-09 14:44
|
||||
*/
|
||||
@Component
|
||||
public class BloomFilterUtil {
|
||||
private static final int DEFAULT_SIZE = 2 << 24; // 布隆过滤器的比特长度
|
||||
private static final int[] seeds = new int[] {7, 11, 13, 31,37, 61}; // 这里要选取质数,能很好的降低错误率
|
||||
|
||||
private BitSet bits = new BitSet(DEFAULT_SIZE);
|
||||
private SimpleHash[] func = new SimpleHash[seeds.length];
|
||||
|
||||
public static void main(String[] args) {
|
||||
String value = "crankzcool@gmail.com";
|
||||
BloomFilterUtil filter = new BloomFilterUtil();
|
||||
// System.out.println(filter.contains(value));
|
||||
// filter.add(value);
|
||||
// System.out.println(filter.contains(value));
|
||||
|
||||
filter.add("1");
|
||||
filter.add("2");
|
||||
filter.remove("1");
|
||||
System.out.println(filter.contains("1"));
|
||||
}
|
||||
|
||||
public void remove(String value) {
|
||||
if (value == null) {
|
||||
return;
|
||||
}
|
||||
for (SimpleHash f : func) {
|
||||
bits.set(f.hash(value), false);
|
||||
}
|
||||
}
|
||||
|
||||
public BloomFilterUtil() {
|
||||
for (int i = 0; i < seeds.length; i++) {
|
||||
func[i] = new SimpleHash(DEFAULT_SIZE, seeds[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public void add(String value) {
|
||||
for (SimpleHash f: func) {
|
||||
bits.set(f.hash(value), true);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean contains(String value) {
|
||||
if (value == null) {
|
||||
return false;
|
||||
}
|
||||
boolean ret = true;
|
||||
for (SimpleHash f : func) {
|
||||
ret = ret && bits.get(f.hash(value));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
public static class SimpleHash {
|
||||
private int cap;
|
||||
private int seed;
|
||||
|
||||
public SimpleHash(int cap, int seed) {
|
||||
this.cap = cap;
|
||||
this.seed = seed;
|
||||
}
|
||||
|
||||
public int hash(String value) {
|
||||
int result = 0;
|
||||
int len = value.length();
|
||||
for (int i = 0; i < len; i++) {
|
||||
result = seed * result + value.charAt(i);
|
||||
}
|
||||
return (cap - 1) & result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package com.bw.config;
|
||||
|
||||
import com.github.tobato.fastdfs.FdfsClientConfig;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.EnableMBeanExport;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.jmx.support.RegistrationPolicy;
|
||||
|
||||
/**
|
||||
* @BelongsProject: demo02
|
||||
* @BelongsPackage: com.bw.config
|
||||
* @Author: zhupengfei
|
||||
* @CreateTime: 2022-12-16 14:37
|
||||
*/
|
||||
@Configuration
|
||||
// 解决 jmx 重复注册 bean 的问题
|
||||
@EnableMBeanExport(registration = RegistrationPolicy.IGNORE_EXISTING)
|
||||
public class FastConfig {
|
||||
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
package com.bw.config;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
import com.github.tobato.fastdfs.domain.fdfs.StorePath;
|
||||
import com.github.tobato.fastdfs.service.FastFileStorageClient;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* @BelongsProject: 0107day02
|
||||
* @BelongsPackage: com.bw.config
|
||||
* @Author: zhupengfei
|
||||
* @CreateTime: 2023-02-01 08:52
|
||||
*/
|
||||
@Component
|
||||
public class FastUtil {
|
||||
private static final Logger log = LoggerFactory.getLogger(FastUtil.class);
|
||||
|
||||
@Resource
|
||||
private FastFileStorageClient storageClient ;
|
||||
|
||||
/**
|
||||
* 上传文件
|
||||
*/
|
||||
public String upload(MultipartFile multipartFile) throws Exception{
|
||||
String originalFilename = multipartFile.getOriginalFilename().
|
||||
substring(multipartFile.getOriginalFilename().
|
||||
lastIndexOf(".") + 1);
|
||||
StorePath storePath = this.storageClient.uploadImageAndCrtThumbImage(
|
||||
multipartFile.getInputStream(),
|
||||
multipartFile.getSize(),originalFilename , null);
|
||||
return storePath.getFullPath() ;
|
||||
}
|
||||
/**
|
||||
* 删除文件
|
||||
*/
|
||||
public String deleteFile(String fileUrl) {
|
||||
if (StringUtils.isEmpty(fileUrl)) {
|
||||
log.info("fileUrl == >>文件路径为空...");
|
||||
return "文件路径不能为空";
|
||||
}
|
||||
try {
|
||||
StorePath storePath = StorePath.parseFromUrl(fileUrl);
|
||||
storageClient.deleteFile(storePath.getGroup(), storePath.getPath());
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
return "删除成功";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
package com.bw.config;
|
||||
|
||||
|
||||
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.Contact;
|
||||
import springfox.documentation.spi.DocumentationType;
|
||||
import springfox.documentation.spring.web.plugins.Docket;
|
||||
|
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;
|
||||
|
||||
/**
|
||||
* @BelongsProject: demo02
|
||||
* @BelongsPackage: com.bw.handler
|
||||
* @Author: zhupengfei
|
||||
* @CreateTime: 2022-12-11 14:17
|
||||
*/
|
||||
@Configuration
|
||||
@EnableSwagger2WebMvc
|
||||
public class Knife4jConfiguration {
|
||||
|
||||
@Bean(value = "defaultApi2")
|
||||
public Docket defaultApi2() {
|
||||
Docket docket = new Docket(DocumentationType.SWAGGER_2)
|
||||
.apiInfo(new ApiInfoBuilder()
|
||||
.title("测试==demo")
|
||||
.description("# swagger-bootstrap-ui-demo RESTful APIs")
|
||||
.termsOfServiceUrl("http://www.xx.com/")
|
||||
.contact(new Contact("玉面小白龙", "", "123@qq.com"))
|
||||
.version("1.0")
|
||||
.build())
|
||||
//分组名称
|
||||
.groupName("2.X版本")
|
||||
.select()
|
||||
//这里指定文档Controller层扫描包路径
|
||||
.apis(RequestHandlerSelectors.basePackage("com.bw.controller"))
|
||||
.paths(PathSelectors.any())
|
||||
.build();
|
||||
return docket;
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package com.bw.config;
|
||||
|
||||
import com.bw.job.MyJob;
|
||||
import com.bw.job.MyJob2;
|
||||
import org.quartz.*;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @BelongsProject: demo02
|
||||
* @BelongsPackage: com.bw.config
|
||||
* @Author: zhupengfei
|
||||
* @CreateTime: 2022-12-22 14:59
|
||||
*/
|
||||
//把当前类定义为 一个配置文件类
|
||||
@Configuration
|
||||
public class QuartzConfig {
|
||||
@Bean
|
||||
public JobDetail downloadDetail() {
|
||||
return JobBuilder.newJob(MyJob.class) //具体任务类
|
||||
.withIdentity("downloadJobDetail")
|
||||
.usingJobData("job_download","download movie")
|
||||
.storeDurably()
|
||||
.build();
|
||||
}
|
||||
//构建 Trigger 及 Scheduler
|
||||
@Bean
|
||||
public Trigger downloadTrigger() {
|
||||
return TriggerBuilder.newTrigger()
|
||||
.forJob(downloadDetail()) //关联上面的 jobDetail
|
||||
.withIdentity("downloadTrigger")
|
||||
.usingJobData("trigger_download","download")
|
||||
//cron 表达式设置每隔 15 秒执行一次
|
||||
.withSchedule(CronScheduleBuilder.cronSchedule("*/15 * * * * ?"))
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package com.bw.config;
|
||||
|
||||
import com.bw.job.MyJob;
|
||||
import com.bw.job.MyJob2;
|
||||
import org.quartz.*;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @BelongsProject: demo02
|
||||
* @BelongsPackage: com.bw.config
|
||||
* @Author: zhupengfei
|
||||
* @CreateTime: 2022-12-22 14:59
|
||||
*/
|
||||
//把当前类定义为 一个配置文件类
|
||||
@Configuration
|
||||
public class QuartzConfig2 {
|
||||
@Bean
|
||||
public JobDetail downloadDetail2() {
|
||||
return JobBuilder.newJob(MyJob2.class) //具体任务类
|
||||
.withIdentity("downloadJobDetail2")
|
||||
.usingJobData("job_download","download movie")
|
||||
.storeDurably()
|
||||
.build();
|
||||
}
|
||||
//构建 Trigger 及 Scheduler
|
||||
@Bean
|
||||
public Trigger downloadTrigger2() {
|
||||
return TriggerBuilder.newTrigger()
|
||||
.forJob(downloadDetail2()) //关联上面的 jobDetail
|
||||
.withIdentity("downloadTrigger2")
|
||||
.usingJobData("trigger_download","download")
|
||||
//cron 表达式设置每隔 5 秒执行一次
|
||||
.withSchedule(CronScheduleBuilder.cronSchedule("*/30 * * * * ?"))
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package com.bw.config;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
||||
import com.fasterxml.jackson.annotation.PropertyAccessor;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
|
||||
@Configuration
|
||||
public class RedisConfig {
|
||||
|
||||
@Bean
|
||||
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) {
|
||||
|
||||
|
||||
RedisTemplate<String, Object> template = new RedisTemplate<>();
|
||||
template.setConnectionFactory(factory);
|
||||
Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new
|
||||
Jackson2JsonRedisSerializer(Object.class);
|
||||
|
||||
ObjectMapper om = new ObjectMapper();
|
||||
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
|
||||
om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
|
||||
jackson2JsonRedisSerializer.setObjectMapper(om);
|
||||
|
||||
StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
|
||||
// key采用String的序列化方式
|
||||
template.setKeySerializer(stringRedisSerializer);
|
||||
// hash的key也采用String的序列化方式
|
||||
template.setHashKeySerializer(stringRedisSerializer);
|
||||
// value序列化方式采用jackson
|
||||
template.setValueSerializer(jackson2JsonRedisSerializer);
|
||||
// hash的value序列化方式采用jackson
|
||||
template.setHashValueSerializer(jackson2JsonRedisSerializer);
|
||||
template.afterPropertiesSet();
|
||||
|
||||
return template;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package com.bw.config;
|
||||
|
||||
import org.redisson.Redisson;
|
||||
import org.redisson.api.RedissonClient;
|
||||
import org.redisson.config.Config;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @BelongsProject: demo02
|
||||
* @BelongsPackage: com.bw.config
|
||||
* @Author: zhupengfei
|
||||
* @CreateTime: 2022-12-24 09:26
|
||||
*/
|
||||
|
||||
@Configuration
|
||||
public class RedissonConfig {
|
||||
|
||||
@Bean(destroyMethod="shutdown") // 服务停止后调用 shutdown 方法。
|
||||
public RedissonClient redisson() throws IOException {
|
||||
System.out.println("配置类初始加载......");
|
||||
// 1.创建配置
|
||||
Config config = new Config();
|
||||
// 集群模式
|
||||
// config.useClusterServers().addNodeAddress("127.0.0.1:6379", "127.0.0.1:6378");
|
||||
// 2.根据 Config 创建出 RedissonClient 实例。
|
||||
config.useSingleServer().setAddress("redis://127.0.0.1:6379");
|
||||
return Redisson.create(config);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
package com.bw.config;
|
||||
|
||||
import com.bw.interceptor.MyInterceptor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.cors.CorsConfiguration;
|
||||
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
||||
import org.springframework.web.filter.CorsFilter;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
/**
|
||||
* @BelongsProject: 0107day02
|
||||
* @BelongsPackage: com.bw.config
|
||||
* @Author: zhupengfei
|
||||
* @CreateTime: 2023-02-01 08:51
|
||||
*/
|
||||
@Configuration
|
||||
public class WebMvcConfig implements WebMvcConfigurer {
|
||||
|
||||
@Autowired
|
||||
private MyInterceptor myIntercepter;
|
||||
//全局路由
|
||||
@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
registry.addMapping("/**")
|
||||
//.allowedOrigins("*") //注意这个变动项,这个是旧版
|
||||
.allowedOriginPatterns("*")//这个才是新版的要求
|
||||
.allowedMethods("GET","HEAD","POST","PUT","DELETE","OPTIONS")
|
||||
.allowCredentials(true)
|
||||
.maxAge(3600)
|
||||
.allowedHeaders("*");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 静态资源
|
||||
* @author: zhupengfei
|
||||
* @param: [registry]
|
||||
* @return: void
|
||||
**/
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
registry
|
||||
.addResourceHandler("/static/**")
|
||||
.addResourceLocations("classpath:/static/");
|
||||
}
|
||||
|
||||
/**
|
||||
* 拦截器
|
||||
* @author: zhupengfei
|
||||
* @param: [registry]
|
||||
* @return: void
|
||||
**/
|
||||
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
registry.addInterceptor(myIntercepter)
|
||||
.addPathPatterns("/**")
|
||||
.excludePathPatterns("/user/*","/user/*/*"
|
||||
,"/doc.html","/swagger-resources","/webjars/*/*","/webjars/*","/favicon.ico","/error",
|
||||
"/student/fastDfsUpLoad"
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.bw.controller;
|
||||
|
||||
import com.bw.mapper.FillMapper;
|
||||
import com.bw.pojo.Fill;
|
||||
import com.bw.service.Fallservice;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
@Controller
|
||||
|
||||
public class FillController {
|
||||
|
||||
@Resource
|
||||
private Fallservice fallservice;
|
||||
@Resource
|
||||
private FillMapper fillMapper;
|
||||
|
||||
public List<Fill> selectAll(){
|
||||
List<Fill> fills = fillMapper.selectAll();
|
||||
for (Fill fill : fills) {
|
||||
System.out.println(fill);
|
||||
}
|
||||
return fills;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package com.bw.mapper;
|
||||
|
||||
import com.bw.pojo.Fill;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface FillMapper {
|
||||
int add(Fill fill);
|
||||
|
||||
List<Fill> selectAll();
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
package com.bw.pojo;
|
||||
|
||||
public class Fill {
|
||||
private Integer id;
|
||||
private String date;
|
||||
private Integer money;
|
||||
private String userId;
|
||||
|
||||
public Fill(Integer id, String date, Integer money, String userId) {
|
||||
this.id = id;
|
||||
this.date = date;
|
||||
this.money = money;
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public Fill() {
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public void setDate(String date) {
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
public Integer getMoney() {
|
||||
return money;
|
||||
}
|
||||
|
||||
public void setMoney(Integer money) {
|
||||
this.money = money;
|
||||
}
|
||||
|
||||
public String getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(String userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
package com.bw.service;
|
||||
|
||||
public interface Fallservice {
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package com.bw.service;
|
||||
|
||||
import com.bw.mapper.FillMapper;
|
||||
import com.bw.pojo.Fill;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class billManager implements Fallservice{
|
||||
|
||||
|
||||
@Resource
|
||||
private FillMapper fillMapper;
|
||||
|
||||
|
||||
//添加数据
|
||||
public void add(Fill fill){
|
||||
int i = fillMapper.add(fill);
|
||||
if(i>0){
|
||||
System.out.println("已完成定添加的手机号为"+fill);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//添加查询所有fill表
|
||||
public List<Fill> selectAll(){
|
||||
List<Fill> fills = fillMapper.selectAll();
|
||||
for (Fill fill : fills) {
|
||||
System.out.println(fill);
|
||||
}
|
||||
return fills;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,102 @@
|
|||
# 服务器相关
|
||||
|
||||
server:
|
||||
port: 10001
|
||||
|
||||
spring:
|
||||
mvc:
|
||||
pathmatch:
|
||||
matching-strategy: ant_path_matcher
|
||||
datasource:
|
||||
driver-class-name: com.mysql.jdbc.Driver
|
||||
url: jdbc:mysql://47.102.213.213:3306/g6_day08?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false
|
||||
username: root
|
||||
password: csh-12345
|
||||
druid:
|
||||
# 下面为连接池的补充设置,应用到上面所有数据源中
|
||||
# 初始化大小,最小,最大
|
||||
initial-size: 5
|
||||
min-idle: 5
|
||||
max-active: 20
|
||||
# 配置获取连接等待超时的时间
|
||||
max-wait: 60000
|
||||
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
|
||||
time-between-eviction-runs-millis: 60000
|
||||
# 配置一个连接在池中最小生存的时间,单位是毫秒
|
||||
min-evictable-idle-time-millis: 300000
|
||||
validation-query: SELECT 1 FROM DUAL
|
||||
test-while-idle: true
|
||||
test-on-borrow: false
|
||||
test-on-return: false
|
||||
# 打开PSCache,并且指定每个连接上PSCache的大小
|
||||
pool-prepared-statements: true
|
||||
# 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙
|
||||
max-pool-prepared-statement-per-connection-size: 20
|
||||
filters: stat,wall
|
||||
use-global-data-source-stat: true
|
||||
# 通过connectProperties属性来打开mergeSql功能;慢SQL记录
|
||||
connect-properties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
|
||||
application:
|
||||
name: shop-server
|
||||
redis:
|
||||
host: 47.102.213.213
|
||||
port: 6379
|
||||
mail:
|
||||
host: smtp.qq.com
|
||||
username: 2833784085@qq.com
|
||||
password: mkabdcywzisgdggg
|
||||
port: 587 # 这个端口根据实际情况配置,一般都是465
|
||||
protocol: smtp # 这里应该是不用改的,我没试过其他的配置
|
||||
test-connection: false
|
||||
default-encoding: UTF-8
|
||||
properties:
|
||||
mail:
|
||||
debug: true
|
||||
smtp:
|
||||
auth: true
|
||||
connectiontimeout: 10000
|
||||
timeout: 10000
|
||||
writetimeout: 10000
|
||||
socketFactory:
|
||||
class: javax.net.ssl.SSLSocketFactory
|
||||
port: 587
|
||||
starttls:
|
||||
enable: true
|
||||
required: true
|
||||
select:
|
||||
multipart:
|
||||
max-file-size: 100MB # 最大支持文件大小
|
||||
max-request-size: 100MB # 最大请求大小
|
||||
enabled: true
|
||||
|
||||
|
||||
# mybatis
|
||||
mybatis:
|
||||
configuration:
|
||||
map-underscore-to-camel-case: true
|
||||
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||
mapper-locations: classpath*:mapper/*Mapper.xml
|
||||
global-config:
|
||||
db-config:
|
||||
id-type: auto
|
||||
|
||||
|
||||
aliyun:
|
||||
end-point: oss-cn-shanghai.aliyuncs.com
|
||||
access-key-id: LTAI5tSFAGrms29r1xwEFtRM
|
||||
access-key-secret: rztMfqxdYlsMUtIoy9bIOSGEKCWQT7
|
||||
access-pre: https://dongxiaojie.oss-cn-shanghai.aliyuncs.com
|
||||
bucket-name: dongxiaojie
|
||||
|
||||
fdfs:
|
||||
so-timeout: 1500 # socket 连接时长
|
||||
connect-timeout: 600 # 连接 tracker 服务器超时时长
|
||||
# 这两个是你服务器的 IP 地址,注意 23000 端口也要打开,阿里云服务器记得配置安全组。tracker 要和 stroage 服务进行交流
|
||||
tracker-list: 47.102.213.213:22122
|
||||
web-server-url: 47.102.213.213:8888
|
||||
pool:
|
||||
jmx-enabled: false
|
||||
# 生成缩略图
|
||||
thumb-image:
|
||||
height: 500
|
||||
width: 500
|
|
@ -0,0 +1,19 @@
|
|||
<?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">
|
||||
<!--
|
||||
1.在mybats的开发中namespace有特殊的意思,一定要是对应接口的全限定名
|
||||
通过namespace可以简历mapper.xml和接口之间的关系(名字不重要,位置不重要)
|
||||
-->
|
||||
<mapper namespace="com.bw.mapper.FillMapper">
|
||||
<!-- 添加 -->
|
||||
|
||||
|
||||
<insert id="add">
|
||||
insert into bill values(0,#{date},#{userId},#{userId})
|
||||
</insert>
|
||||
<select id="selectAll" resultType="com.bw.pojo.Fill">
|
||||
select * from fill
|
||||
</select>
|
||||
</mapper>
|
|
@ -0,0 +1,13 @@
|
|||
package com.bwie.day08;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class Day08ApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue