Просмотр исходного кода

Merge branch 'master' of http://git.semsx.com/zhangxiaoyu/springbootdemo

 Conflicts:
	src/main/resources/application-dev.yml
	src/main/resources/application.yml
zhangxiaoyu лет назад: 2
Родитель
Сommit
960958be60
22 измененных файлов с 476 добавлено и 11 удалено
  1. 22 5
      pom.xml
  2. 1 1
      src/main/java/com/example/Thread/ThreadRunnable.java
  3. 18 0
      src/main/java/com/example/mqListener/MqListener.java
  4. 3 1
      src/main/java/com/example/springbootdemo/SpringbootdemoApplication.java
  5. 31 0
      src/main/java/com/example/springbootdemo/config/AsyncConfiguration.java
  6. 36 0
      src/main/java/com/example/springbootdemo/config/CustomRabbitListener.java
  7. 30 0
      src/main/java/com/example/springbootdemo/config/DeviceRabbitConfig.java
  8. 12 0
      src/main/java/com/example/springbootdemo/config/MyBeanConfig.java
  9. 87 0
      src/main/java/com/example/springbootdemo/config/RabbitMQConfiguration.java
  10. 18 0
      src/main/java/com/example/springbootdemo/config/WebMvcConfig.java
  11. 47 1
      src/main/java/com/example/springbootdemo/controller/HelloController.java
  12. 1 0
      src/main/java/com/example/springbootdemo/controller/MybatisPlusController.java
  13. 16 0
      src/main/java/com/example/springbootdemo/controller/TestBeanController.java
  14. 28 2
      src/main/java/com/example/springbootdemo/controller/TrainJavaController.java
  15. 17 0
      src/main/java/com/example/springbootdemo/entity/Person.java
  16. 8 0
      src/main/java/com/example/springbootdemo/form/PostForm.java
  17. 22 0
      src/main/java/com/example/springbootdemo/interceptor/Myinterceptor.java
  18. 12 0
      src/main/java/com/example/springbootdemo/query/DateQuery.java
  19. 4 0
      src/main/java/com/example/springbootdemo/websocket/WSServer.java
  20. 34 0
      src/main/java/com/example/util/MailUtil.java
  21. 12 1
      src/main/resources/application.yml
  22. 17 0
      src/test/java/com/example/springbootdemo/SpringbootdemoApplicationTests.java

+ 22 - 5
pom.xml

@@ -25,6 +25,10 @@
25 25
             <groupId>org.springframework.boot</groupId>
26 26
             <artifactId>spring-boot-starter-data-jpa</artifactId>
27 27
         </dependency>
28
+        <dependency>
29
+            <groupId>org.springframework.boot</groupId>
30
+            <artifactId>spring-boot-starter-amqp</artifactId>
31
+        </dependency>
28 32
         <dependency>
29 33
             <groupId>org.projectlombok</groupId>
30 34
             <artifactId>lombok</artifactId>
@@ -54,11 +58,24 @@
54 58
             <artifactId>hutool-all</artifactId>
55 59
             <version>4.1.1</version>
56 60
         </dependency>
57
-<!--        <dependency>-->
58
-<!--            <groupId></groupId>-->
59
-<!--            <artifactId></artifactId>-->
60
-<!--        </dependency>-->
61
-
61
+        <dependency>
62
+            <groupId>com.sun.mail</groupId>
63
+            <artifactId>javax.mail</artifactId>
64
+            <version>1.6.2</version>
65
+        </dependency>
66
+        <dependency>
67
+            <groupId>junit</groupId>
68
+            <artifactId>junit</artifactId>
69
+        </dependency>
70
+        <dependency>
71
+            <groupId>com.alibaba</groupId>
72
+            <artifactId>fastjson</artifactId>
73
+            <version>1.2.72</version>
74
+        </dependency>
75
+        <dependency>
76
+            <groupId>org.springframework.boot</groupId>
77
+            <artifactId>spring-boot-starter-websocket</artifactId>
78
+        </dependency>
62 79
     </dependencies>
63 80
 
64 81
     <build>

+ 1 - 1
src/main/java/com/example/Thread/ThreadRunnable.java

@@ -32,7 +32,7 @@ class ThreadRun implements Runnable {
32 32
 class ProxyTest implements Runnable {
33 33
     @Override
34 34
     public void run() {
35
-        System.out.println("proxyTest---" + Thread.currentThread().getName());
35
+        System.out.println("proxyTest11---" + Thread.currentThread().getName());
36 36
     }
37 37
 }
38 38
 // 代理模式,可以把它当成是Thread 类

+ 18 - 0
src/main/java/com/example/mqListener/MqListener.java

@@ -0,0 +1,18 @@
1
+package com.example.mqListener;
2
+
3
+import org.springframework.amqp.rabbit.annotation.Queue;
4
+import org.springframework.amqp.rabbit.annotation.QueueBinding;
5
+import org.springframework.amqp.rabbit.annotation.RabbitListener;
6
+import org.springframework.stereotype.Component;
7
+
8
+@Component
9
+public class MqListener {
10
+    public static final String EXCHANGE_NAME = "deviceTopicExchange";
11
+    public static final String ROUTER_KEY = "device1.#";
12
+    public static final String QUE = "device01";
13
+    @RabbitListener( queues = QUE)
14
+    public void device1(String message) {
15
+        System.out.println(message);
16
+    }
17
+
18
+}

+ 3 - 1
src/main/java/com/example/springbootdemo/SpringbootdemoApplication.java

@@ -1,15 +1,17 @@
1 1
 package com.example.springbootdemo;
2 2
 
3
+import com.example.springbootdemo.config.CustomRabbitListener;
3 4
 import org.mybatis.spring.annotation.MapperScan;
4 5
 import org.springframework.boot.SpringApplication;
5 6
 import org.springframework.boot.autoconfigure.SpringBootApplication;
6 7
 import org.springframework.context.ConfigurableApplicationContext;
7 8
 import org.springframework.context.annotation.ComponentScan;
8 9
 @SpringBootApplication(scanBasePackages = {"com.example"})
9
-@ComponentScan({"com.example.demo","com.example.springbootdemo"})
10
+@ComponentScan({"com.example"})
10 11
 public class SpringbootdemoApplication {
11 12
     public static void main(String[] args) {
12 13
         ConfigurableApplicationContext run  = SpringApplication.run(SpringbootdemoApplication.class, args);
14
+        CustomRabbitListener bean = run.getBean(CustomRabbitListener.class);
13 15
 //        String[] names = run.getBeanDefinitionNames();
14 16
 //        for(String name:names) {
15 17
 //            System.out.println(name);

+ 31 - 0
src/main/java/com/example/springbootdemo/config/AsyncConfiguration.java

@@ -0,0 +1,31 @@
1
+package com.example.springbootdemo.config;
2
+
3
+import org.springframework.context.annotation.Bean;
4
+import org.springframework.context.annotation.Configuration;
5
+import org.springframework.scheduling.annotation.EnableAsync;
6
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
7
+
8
+import java.util.concurrent.Executor;
9
+import java.util.concurrent.ThreadPoolExecutor;
10
+
11
+@Configuration
12
+@EnableAsync
13
+public class AsyncConfiguration {
14
+    @Bean("doSomethingExecutor")
15
+    public Executor doExecutor() {
16
+        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
17
+        executor.setCorePoolSize(10);
18
+        // 最大线程数:线程池最大的线程数,只有在缓冲队列满了之后才会申请超过核心线程数的线程
19
+        executor.setMaxPoolSize(20);
20
+        // 缓冲队列:用来缓冲执行任务的队列
21
+        executor.setQueueCapacity(500);
22
+        // 允许线程的空闲时间60秒:当超过了核心线程之外的线程在空闲时间到达之后会被销毁
23
+        executor.setKeepAliveSeconds(60);
24
+        // 线程池名的前缀:设置好了之后可以方便我们定位处理任务所在的线程池
25
+        executor.setThreadNamePrefix("do-something-");
26
+        // 缓冲队列满了之后的拒绝策略:由调用线程处理(一般是主线程)
27
+        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.DiscardPolicy());
28
+        executor.initialize();
29
+        return executor;
30
+    }
31
+}

+ 36 - 0
src/main/java/com/example/springbootdemo/config/CustomRabbitListener.java

@@ -0,0 +1,36 @@
1
+package com.example.springbootdemo.config;
2
+
3
+import com.rabbitmq.client.Channel;
4
+import org.springframework.amqp.core.Message;
5
+import org.springframework.amqp.rabbit.annotation.Exchange;
6
+import org.springframework.amqp.rabbit.annotation.Queue;
7
+import org.springframework.amqp.rabbit.annotation.QueueBinding;
8
+import org.springframework.amqp.rabbit.annotation.RabbitListener;
9
+import org.springframework.amqp.support.AmqpHeaders;
10
+import org.springframework.messaging.handler.annotation.Headers;
11
+import org.springframework.stereotype.Component;
12
+
13
+import java.io.IOException;
14
+import java.util.Map;
15
+
16
+@Component
17
+public class CustomRabbitListener {
18
+//    @org.springframework.amqp.rabbit.annotation.RabbitListener(queues = "crm_foot_info_14049")
19
+//    public void a(Message message) {
20
+//        System.out.println(message);
21
+//    }
22
+    @RabbitListener (queues = RabbitMQConfiguration.dealQueueOrder)
23
+    public void process(String order, Message message, @Headers Map<String, Object> headers, Channel channel) throws IOException {
24
+        System.out.println("死信ie zh++"+ order);
25
+        Long l = (Long)headers.get(AmqpHeaders.DELIVERY_TAG);
26
+        channel.basicAck(l,false);
27
+    }
28
+    @RabbitListener (queues = RabbitMQConfiguration.orderQueue)
29
+    public void orderQueue(String order, Message message, @Headers Map<String, Object> headers, Channel channel) throws IOException {
30
+        System.out.println("orderQueue收到隊列消息並進行拒絕"+ order);
31
+        Long l = (Long)headers.get(AmqpHeaders.DELIVERY_TAG);
32
+        channel.basicNack(l,false,false);
33
+    }
34
+
35
+
36
+}

+ 30 - 0
src/main/java/com/example/springbootdemo/config/DeviceRabbitConfig.java

@@ -0,0 +1,30 @@
1
+package com.example.springbootdemo.config;
2
+
3
+import com.rabbitmq.client.AMQP;
4
+import com.rabbitmq.client.Channel;
5
+import org.springframework.amqp.core.Binding;
6
+import org.springframework.amqp.core.BindingBuilder;
7
+import org.springframework.amqp.core.Queue;
8
+import org.springframework.amqp.rabbit.core.RabbitTemplate;
9
+import org.springframework.beans.factory.annotation.Autowired;
10
+import org.springframework.context.annotation.Bean;
11
+import org.springframework.context.annotation.Configuration;
12
+import org.springframework.stereotype.Component;
13
+
14
+import java.io.IOException;
15
+import java.util.concurrent.TimeoutException;
16
+
17
+@Component
18
+public class DeviceRabbitConfig {
19
+    @Autowired
20
+    RabbitTemplate rabbitTemplate;
21
+    @Bean
22
+    public AMQP.Queue.BindOk declareDeviceQueue() throws IOException, TimeoutException {
23
+        Channel channel = rabbitTemplate.getConnectionFactory().createConnection().createChannel(false);
24
+        channel.queueDeclare("device001", true, false, false, null);
25
+        return channel.queueBind("device001", "deviceExchange", "device001");
26
+//        return new Queue("device001",true,false,false,null);
27
+    }
28
+
29
+
30
+}

+ 12 - 0
src/main/java/com/example/springbootdemo/config/MyBeanConfig.java

@@ -0,0 +1,12 @@
1
+package com.example.springbootdemo.config;
2
+
3
+import org.springframework.context.annotation.Bean;
4
+import org.springframework.context.annotation.Configuration;
5
+
6
+@Configuration
7
+public class MyBeanConfig {
8
+    @Bean
9
+    public String getName() {
10
+        return "nimadeo";
11
+    }
12
+}

+ 87 - 0
src/main/java/com/example/springbootdemo/config/RabbitMQConfiguration.java

@@ -0,0 +1,87 @@
1
+package com.example.springbootdemo.config;
2
+
3
+import org.springframework.amqp.core.*;
4
+import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
5
+import org.springframework.beans.factory.annotation.Autowired;
6
+import org.springframework.context.annotation.Bean;
7
+import org.springframework.context.annotation.Configuration;
8
+
9
+import java.util.HashMap;
10
+import java.util.Map;
11
+
12
+@Configuration
13
+public class RabbitMQConfiguration {
14
+    //队列名称
15
+    public   final static String orderQueue = "order_queue";
16
+
17
+    //交换机名称
18
+    public  final static String orderExchange = "order_exchange";
19
+
20
+    // routingKey
21
+    public  final static String routingKeyOrder = "routing_key_order";
22
+
23
+    //死信消息队列名称
24
+    public  final static String dealQueueOrder = "deal_queue_order";
25
+
26
+    //死信交换机名称
27
+    public  final static String dealExchangeOrder = "deal_exchange_order";
28
+
29
+    //死信 routingKey
30
+    public final static String deadRoutingKeyOrder = "dead_routing_key_order";
31
+
32
+    //死信队列 交换机标识符
33
+    public static final String DEAD_LETTER_QUEUE_KEY = "x-dead-letter-exchange";
34
+
35
+    //死信队列交换机绑定键标识符
36
+    public static final String DEAD_LETTER_ROUTING_KEY = "x-dead-letter-routing-key";
37
+
38
+    @Autowired
39
+    private CachingConnectionFactory connectionFactory;
40
+
41
+    @Bean
42
+    public Queue orderQueue() {
43
+        // 将普通队列绑定到死信队列交换机上
44
+        Map<String, Object> args = new HashMap<>(2);
45
+//        args.put("x-message-ttl", 5 * 1000);//直接设置 Queue 延迟时间 但如果直接给队列设置过期时间,这种做法不是很灵活
46
+        //这里采用发送消息动态设置延迟时间,这样我们可以灵活控制
47
+        args.put(DEAD_LETTER_QUEUE_KEY, dealExchangeOrder);
48
+        args.put(DEAD_LETTER_ROUTING_KEY, deadRoutingKeyOrder);
49
+        return new Queue(RabbitMQConfiguration.orderQueue, true, false, false, args);
50
+    }
51
+
52
+    //声明一个direct类型的交换机
53
+    @Bean
54
+    DirectExchange orderExchange() {
55
+        return new DirectExchange(RabbitMQConfiguration.orderExchange);
56
+    }
57
+    @Bean
58
+    FanoutExchange fanoutT1Exchange() {
59
+        return new FanoutExchange("TT1");
60
+    }
61
+
62
+    //绑定Queue队列到交换机,并且指定routingKey
63
+    @Bean
64
+    Binding bindingDirectExchangeDemo5(   ) {
65
+        return BindingBuilder.bind(orderQueue()).to(orderExchange()).with(routingKeyOrder);
66
+    }
67
+
68
+    //创建配置死信队列
69
+    @Bean
70
+    public Queue deadQueueOrder() {
71
+        Queue queue = new Queue(dealQueueOrder, true);
72
+        return queue;
73
+    }
74
+
75
+    //创建死信交换机
76
+    @Bean
77
+    public DirectExchange deadExchangeOrder() {
78
+        return new DirectExchange(dealExchangeOrder);
79
+    }
80
+
81
+    //死信队列与死信交换机绑定
82
+    @Bean
83
+    public Binding bindingDeadExchange() {
84
+        return BindingBuilder.bind(deadQueueOrder()).to(deadExchangeOrder()).with(deadRoutingKeyOrder);
85
+    }
86
+
87
+}

+ 18 - 0
src/main/java/com/example/springbootdemo/config/WebMvcConfig.java

@@ -0,0 +1,18 @@
1
+package com.example.springbootdemo.config;
2
+
3
+import com.example.springbootdemo.interceptor.Myinterceptor;
4
+import org.springframework.context.annotation.Configuration;
5
+import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
6
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
7
+
8
+import javax.annotation.Resource;
9
+@Configuration
10
+public class WebMvcConfig implements WebMvcConfigurer {
11
+    @Resource
12
+    private Myinterceptor myinterceptor;
13
+    @Override
14
+    public void addInterceptors(InterceptorRegistry registry) {
15
+        registry.addInterceptor(myinterceptor).addPathPatterns("/**");
16
+//        WebMvcConfigurer.super.addInterceptors(registry);
17
+    }
18
+}

+ 47 - 1
src/main/java/com/example/springbootdemo/controller/HelloController.java

@@ -4,19 +4,30 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
4 4
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
5 5
 import com.example.springbootdemo.entity.FootScanEntity;
6 6
 import com.example.springbootdemo.entity.FootScanGroup;
7
+import com.example.springbootdemo.form.PostForm;
7 8
 import com.example.springbootdemo.mapper.FootScanMapper;
9
+import com.example.springbootdemo.query.DateQuery;
8 10
 import com.example.springbootdemo.service.FootScanGroupService;
9 11
 import com.example.springbootdemo.service.FootScanService;
10 12
 import com.example.springbootdemo.zxyTeST.sql.dao.ArmGrabRepository;
11 13
 import com.example.springbootdemo.zxyTeST.sql.dao.ColorRepository;
12 14
 import com.example.springbootdemo.zxyTeST.sql.entity.ArmGrabEntity;
13 15
 import com.example.springbootdemo.zxyTeST.sql.entity.Color;
16
+import com.example.util.MailUtil;
14 17
 import org.springframework.beans.factory.annotation.Autowired;
15 18
 import org.springframework.dao.EmptyResultDataAccessException;
16 19
 import org.springframework.jdbc.core.JdbcTemplate;
17 20
 import org.springframework.web.bind.annotation.*;
18 21
 
22
+import javax.mail.Address;
23
+import javax.mail.Session;
24
+import javax.mail.Transport;
25
+import javax.mail.internet.MimeMessage;
26
+import java.text.SimpleDateFormat;
19 27
 import java.util.List;
28
+import java.util.Properties;
29
+import java.util.concurrent.ConcurrentHashMap;
30
+import java.util.logging.SimpleFormatter;
20 31
 
21 32
 @RestController
22 33
 public class HelloController {
@@ -32,7 +43,8 @@ public class HelloController {
32 43
     FootScanGroupService footScanGroupService;
33 44
     @Autowired
34 45
     FootScanMapper footScanMapper;
35
-
46
+    @Autowired
47
+    MailUtil mailUtil;
36 48
 
37 49
     @RequestMapping("/hello")
38 50
     public void hello() {
@@ -81,6 +93,40 @@ public class HelloController {
81 93
 //        footScanService.page(footScanEntityPage,null);
82 94
 //        return  footScanEntityPage.getRecords();
83 95
 //    }
96
+    @RequestMapping("testDate")
97
+    public String testDate(DateQuery dateQuery) {
98
+        SimpleDateFormat simpleFormatter = new SimpleDateFormat("今天是 yyyy 年 MM 月 dd 日 E HH 点 mm 分 ss 秒");
99
+        return simpleFormatter.format(dateQuery.getDate());
100
+    }
101
+    @PostMapping("postTest")
102
+    public void testPost(@RequestBody PostForm postForm) {
103
+        ConcurrentHashMap<String, String> stringStringConcurrentHashMap = new ConcurrentHashMap<>();
104
+        stringStringConcurrentHashMap.put("1","123");
105
+        System.out.println(postForm.getName());
106
+    }
107
+
108
+    @RequestMapping("testMail")
109
+    public void testMail() {
110
+        Properties properties = new Properties();
111
+        properties.setProperty("mail.transport.protocol", "smtp");   // 使用的协议(JavaMail规范要求)
112
+        properties.setProperty("mail.smtp.host", "smtp.exmail.qq.com");   // 发件人的邮箱的 SMTP 服务器地址
113
+        properties.setProperty("mail.smtp.auth", "true");
114
+        Session session = Session.getDefaultInstance(properties);
115
+        session.setDebug(true);                                 // 设置为debug模式, 可以查看详细的发送 log
116
+        try {
117
+            MimeMessage message = mailUtil.createMimeMessage(session, "software@semsx.com",
118
+                    "771799477@qq.com,1152047207@qq.com");
119
+            Transport transport = session.getTransport();
120
+            transport.connect("software@semsx.com","RNDmdjNarRkqg4ge");
121
+            Address[] allRecipients = message.getAllRecipients();
122
+        //    transport.sendMessage(message,message.getAllRecipients());
123
+            transport.close();
124
+        } catch (Exception e) {
125
+            e.printStackTrace();
126
+        }
127
+
128
+    }
129
+
84 130
 
85 131
 }
86 132
 

+ 1 - 0
src/main/java/com/example/springbootdemo/controller/MybatisPlusController.java

@@ -7,6 +7,7 @@ import com.example.springbootdemo.entity.FootScanEntity;
7 7
 import com.example.springbootdemo.mapper.DeviceMapper;
8 8
 import com.example.springbootdemo.service.FootScanService;
9 9
 import com.example.springbootdemo.service.GoodsBindsShoesLastService;
10
+import org.apache.tomcat.util.codec.binary.StringUtils;
10 11
 import org.springframework.beans.factory.annotation.Autowired;
11 12
 import org.springframework.web.bind.annotation.RequestMapping;
12 13
 import org.springframework.web.bind.annotation.RequestParam;

+ 16 - 0
src/main/java/com/example/springbootdemo/controller/TestBeanController.java

@@ -0,0 +1,16 @@
1
+package com.example.springbootdemo.controller;
2
+
3
+import com.example.springbootdemo.config.MyBeanConfig;
4
+import org.springframework.beans.factory.annotation.Autowired;
5
+import org.springframework.web.bind.annotation.RequestMapping;
6
+import org.springframework.web.bind.annotation.RestController;
7
+
8
+@RestController
9
+public class TestBeanController {
10
+    @Autowired
11
+    MyBeanConfig myBeanConfig;
12
+    @RequestMapping("/mybean")
13
+    public void myBean() {
14
+        System.out.println(myBeanConfig.getName());
15
+    }
16
+}

+ 28 - 2
src/main/java/com/example/springbootdemo/controller/TrainJavaController.java

@@ -1,13 +1,18 @@
1 1
 package com.example.springbootdemo.controller;
2 2
 
3
+import com.example.springbootdemo.config.RabbitMQConfiguration;
3 4
 import com.example.springbootdemo.zxyTeST.sql.dao.FootScanCommonRepository;
4 5
 import com.example.springbootdemo.zxyTeST.sql.entity.FootScanCommonEntity;
5 6
 import com.example.springbootdemo.zxyTeST.ymlConfig.SemsxUser;
7
+import com.rabbitmq.client.Channel;
8
+import org.springframework.amqp.core.Message;
9
+import org.springframework.amqp.rabbit.core.RabbitTemplate;
6 10
 import org.springframework.beans.factory.annotation.Autowired;
7 11
 import org.springframework.web.bind.annotation.*;
8 12
 
9 13
 import java.util.List;
10 14
 import java.util.Map;
15
+import java.util.UUID;
11 16
 
12 17
 @RestController
13 18
 public class TrainJavaController {
@@ -15,10 +20,14 @@ public class TrainJavaController {
15 20
     FootScanCommonRepository footScanCommonRepository;
16 21
     @Autowired
17 22
     SemsxUser semsxUser;
23
+    @Autowired
24
+    RabbitTemplate rabbitTemplate;
18 25
     @RequestMapping("/footScan")
19 26
     public String getFootScanInfo() {
20
-        FootScanCommonEntity  footScanCommonInfo = footScanCommonRepository.findByFootScanId(14815);
21
-        return  footScanCommonInfo.getFootScanSign();
27
+//        FootScanCommonEntity  footScanCommonInfo = footScanCommonRepository.findByFootScanId(14815);
28
+//        return  footScanCommonInfo.getFootScanSign();
29
+        System.out.println(123);
30
+        return "sitn";
22 31
     }
23 32
     @RequestMapping("/postTest")
24 33
     public void getFootScanList(@RequestParam Map<Integer,Object> params) {
@@ -33,4 +42,21 @@ public class TrainJavaController {
33 42
         return  semsxUser;
34 43
     }
35 44
 
45
+    @RequestMapping("/dtl")
46
+    public String dtl(Message message1, Channel channel) {
47
+        String orderId = UUID.randomUUID().toString();
48
+        rabbitTemplate.convertAndSend(
49
+                RabbitMQConfiguration.orderExchange, //发送至订单交换机
50
+                RabbitMQConfiguration.routingKeyOrder, //订单定routingKey
51
+                orderId //订单号   这里可以传对象 比如直接传订单对象
52
+                , message -> {
53
+                    // 如果配置了 params.put("x-message-ttl", 5 * 1000);
54
+                    // 那么这一句也可以省略,具体根据业务需要是声明 Queue 的时候就指定好延迟时间还是在发送自己控制时间
55
+                    message.getMessageProperties().setExpiration(5 * 10 + "");
56
+                    String msg = new String(message.getBody());
57
+                    return message;
58
+                });
59
+
60
+        return "{'orderId':'"+orderId+"'}";
61
+    }
36 62
 }

+ 17 - 0
src/main/java/com/example/springbootdemo/entity/Person.java

@@ -0,0 +1,17 @@
1
+package com.example.springbootdemo.entity;
2
+
3
+import com.alibaba.fastjson.annotation.JSONField;
4
+import lombok.Data;
5
+
6
+@Data
7
+public class Person {
8
+    @JSONField(name = "aage")
9
+    private int age;
10
+    @JSONField(name = "nname")
11
+    private String name;
12
+
13
+    public Person(int age, String name) {
14
+        this.age = age;
15
+        this.name = name;
16
+    }
17
+}

+ 8 - 0
src/main/java/com/example/springbootdemo/form/PostForm.java

@@ -0,0 +1,8 @@
1
+package com.example.springbootdemo.form;
2
+
3
+import lombok.Data;
4
+
5
+@Data
6
+public class PostForm {
7
+    private String name;
8
+}

+ 22 - 0
src/main/java/com/example/springbootdemo/interceptor/Myinterceptor.java

@@ -0,0 +1,22 @@
1
+package com.example.springbootdemo.interceptor;
2
+
3
+
4
+import org.springframework.stereotype.Component;
5
+import org.springframework.web.servlet.HandlerInterceptor;
6
+import org.springframework.web.servlet.ModelAndView;
7
+
8
+import javax.servlet.http.HttpServletRequest;
9
+import javax.servlet.http.HttpServletResponse;
10
+@Component
11
+public class Myinterceptor  implements HandlerInterceptor {
12
+    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
13
+        System.out.println("pre");
14
+        return true;
15
+    }
16
+    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
17
+        System.out.println("chulihou");
18
+    }
19
+    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
20
+        System.out.println("clean");
21
+    }
22
+}

+ 12 - 0
src/main/java/com/example/springbootdemo/query/DateQuery.java

@@ -0,0 +1,12 @@
1
+package com.example.springbootdemo.query;
2
+
3
+import lombok.Data;
4
+import org.springframework.format.annotation.DateTimeFormat;
5
+
6
+import java.util.Date;
7
+
8
+@Data
9
+public class DateQuery {
10
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
11
+    private Date date;
12
+}

+ 4 - 0
src/main/java/com/example/springbootdemo/websocket/WSServer.java

@@ -0,0 +1,4 @@
1
+package com.example.springbootdemo.websocket;
2
+
3
+public class WSServer {
4
+}

+ 34 - 0
src/main/java/com/example/util/MailUtil.java

@@ -0,0 +1,34 @@
1
+package com.example.util;
2
+
3
+import com.example.springbootdemo.config.MailConfig;
4
+import org.springframework.beans.factory.annotation.Autowired;
5
+import org.springframework.stereotype.Component;
6
+
7
+import javax.mail.Session;
8
+import javax.mail.internet.InternetAddress;
9
+import javax.mail.internet.MimeMessage;
10
+import java.util.Date;
11
+@Component
12
+public class MailUtil {
13
+    @Autowired
14
+    MailConfig mailConfig;
15
+    public MimeMessage createMimeMessage(Session session, String sendMail, String users) throws Exception {
16
+        // 1. 创建一封邮件
17
+        MimeMessage message = new MimeMessage(session);
18
+        // 2. From: 发件人
19
+        message.setFrom(new InternetAddress(sendMail, "【semsx】", "UTF-8"));
20
+        // 3. To: 收件人(可以增加多个收件人、抄送、密送)
21
+//        Address[] internetAddresses = new InternetAddress().parse(users);
22
+        message.setRecipients(MimeMessage.RecipientType.TO, users);
23
+        // 4. Subject: 邮件主题
24
+        message.setSubject("打折钜惠", "UTF-8");
25
+        // 5. Content: 邮件正文(可以使用html标签)
26
+        message.setContent("XX用户你好 <br/> 今天全场5折,<br/> 快来抢购, 错过今天再等一年。。。", "text/html;charset=UTF-8");
27
+        // 6. 设置发件时间
28
+        message.setSentDate(new Date());
29
+        // 7. 保存设置
30
+        message.saveChanges();
31
+        return message;
32
+    }
33
+
34
+}

+ 12 - 1
src/main/resources/application.yml

@@ -13,11 +13,22 @@ spring:
13 13
   datasource:
14 14
     url: jdbc:mysql://localhost:3306/test?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
15 15
     username: root
16
-    password:
16
+    password: 123456
17 17
     driver-class-name: com.mysql.cj.jdbc.Driver
18 18
   jpa:
19 19
     database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
20 20
     open-in-view: false
21
+  rabbitmq:
22
+    host: 192.168.50.100
23
+    port: 5672
24
+    username: guest
25
+    password: guest
26
+    publisher-returns: true
27
+    virtual-host: /scanmq
28
+    listener:
29
+      simple:
30
+        acknowledge-mode: manual
31
+        default-requeue-rejected: false
21 32
 mybatis-plus:
22 33
   configuration:
23 34
     log-impl: org.apache.ibatis.logging.stdout.StdOutImpl

Разница между файлами не показана из-за своего большого размера
+ 17 - 0
src/test/java/com/example/springbootdemo/SpringbootdemoApplicationTests.java