-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathatom.xml
562 lines (311 loc) · 312 KB
/
atom.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>辣椒の酱</title>
<subtitle>尚未执佩剑,转眼即江湖</subtitle>
<link href="https://removeif.github.io/atom.xml" rel="self"/>
<link href="https://removeif.github.io/"/>
<updated>2025-01-06T09:42:34.426Z</updated>
<id>https://removeif.github.io/</id>
<author>
<name>辣椒の酱</name>
</author>
<generator uri="https://hexo.io/">Hexo</generator>
<entry>
<title>springboot websocket server服务端代码demo</title>
<link href="https://removeif.github.io/java/frame/springboot-websocket-server%E4%BB%A3%E7%A0%81demo%E7%A4%BA%E4%BE%8B.html"/>
<id>https://removeif.github.io/java/frame/springboot-websocket-server%E4%BB%A3%E7%A0%81demo%E7%A4%BA%E4%BE%8B.html</id>
<published>2025-01-04T18:28:26.000Z</published>
<updated>2025-01-06T09:42:34.426Z</updated>
<content type="html"><![CDATA[<p>后端java springboot 项目</p><p>简单websocket server 端代码</p><span id="more"></span><figure class="highlight xml"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta"><?xml version=<span class="string">"1.0"</span> encoding=<span class="string">"UTF-8"</span>?></span></span><br><span class="line"><span class="tag"><<span class="name">project</span> <span class="attr">xmlns</span>=<span class="string">"http://maven.apache.org/POM/4.0.0"</span> <span class="attr">xmlns:xsi</span>=<span class="string">"http://www.w3.org/2001/XMLSchema-instance"</span></span></span><br><span class="line"><span class="tag"><span class="attr">xsi:schemaLocation</span>=<span class="string">"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"</span>></span></span><br><span class="line"><span class="tag"><<span class="name">modelVersion</span>></span>4.0.0<span class="tag"></<span class="name">modelVersion</span>></span></span><br><span class="line"></span><br><span class="line"><span class="tag"><<span class="name">groupId</span>></span>com.cloudkd<span class="tag"></<span class="name">groupId</span>></span></span><br><span class="line"><span class="tag"><<span class="name">artifactId</span>></span>websocket-server<span class="tag"></<span class="name">artifactId</span>></span></span><br><span class="line"><span class="tag"><<span class="name">version</span>></span>1.0<span class="tag"></<span class="name">version</span>></span></span><br><span class="line"><span class="tag"><<span class="name">packaging</span>></span>jar<span class="tag"></<span class="name">packaging</span>></span></span><br><span class="line"></span><br><span class="line"><span class="tag"><<span class="name">name</span>></span>websocket<span class="tag"></<span class="name">name</span>></span></span><br><span class="line"><span class="tag"><<span class="name">description</span>></span>websocket for Spring Boot<span class="tag"></<span class="name">description</span>></span></span><br><span class="line"></span><br><span class="line"><span class="tag"><<span class="name">parent</span>></span></span><br><span class="line"><span class="tag"><<span class="name">groupId</span>></span>org.springframework.boot<span class="tag"></<span class="name">groupId</span>></span></span><br><span class="line"><span class="tag"><<span class="name">artifactId</span>></span>spring-boot-starter-parent<span class="tag"></<span class="name">artifactId</span>></span></span><br><span class="line"><span class="tag"><<span class="name">version</span>></span>2.0.5.RELEASE<span class="tag"></<span class="name">version</span>></span></span><br><span class="line"><span class="tag"><<span class="name">relativePath</span>/></span> <span class="comment"><!-- lookup parent from repository --></span></span><br><span class="line"><span class="tag"></<span class="name">parent</span>></span></span><br><span class="line"></span><br><span class="line"><span class="tag"><<span class="name">properties</span>></span></span><br><span class="line"><span class="tag"><<span class="name">project.build.sourceEncoding</span>></span>UTF-8<span class="tag"></<span class="name">project.build.sourceEncoding</span>></span></span><br><span class="line"><span class="tag"><<span class="name">project.reporting.outputEncoding</span>></span>UTF-8<span class="tag"></<span class="name">project.reporting.outputEncoding</span>></span></span><br><span class="line"><span class="tag"><<span class="name">java.version</span>></span>1.8<span class="tag"></<span class="name">java.version</span>></span></span><br><span class="line"><span class="tag"></<span class="name">properties</span>></span></span><br><span class="line"></span><br><span class="line"><span class="tag"><<span class="name">dependencies</span>></span></span><br><span class="line"><span class="tag"><<span class="name">dependency</span>></span></span><br><span class="line"><span class="tag"><<span class="name">groupId</span>></span>org.springframework.boot<span class="tag"></<span class="name">groupId</span>></span></span><br><span class="line"><span class="tag"><<span class="name">artifactId</span>></span>spring-boot-starter-web<span class="tag"></<span class="name">artifactId</span>></span></span><br><span class="line"><span class="tag"></<span class="name">dependency</span>></span></span><br><span class="line"><span class="tag"><<span class="name">dependency</span>></span></span><br><span class="line"><span class="tag"><<span class="name">groupId</span>></span>org.springframework.boot<span class="tag"></<span class="name">groupId</span>></span></span><br><span class="line"><span class="tag"><<span class="name">artifactId</span>></span>spring-boot-starter-websocket<span class="tag"></<span class="name">artifactId</span>></span></span><br><span class="line"><span class="tag"></<span class="name">dependency</span>></span></span><br><span class="line"></span><br><span class="line"><span class="tag"><<span class="name">dependency</span>></span></span><br><span class="line"><span class="tag"><<span class="name">groupId</span>></span>org.springframework.boot<span class="tag"></<span class="name">groupId</span>></span></span><br><span class="line"><span class="tag"><<span class="name">artifactId</span>></span>spring-boot-devtools<span class="tag"></<span class="name">artifactId</span>></span></span><br><span class="line"><span class="tag"><<span class="name">scope</span>></span>runtime<span class="tag"></<span class="name">scope</span>></span></span><br><span class="line"><span class="tag"></<span class="name">dependency</span>></span></span><br><span class="line"><span class="tag"><<span class="name">dependency</span>></span></span><br><span class="line"><span class="tag"><<span class="name">groupId</span>></span>org.springframework.boot<span class="tag"></<span class="name">groupId</span>></span></span><br><span class="line"><span class="tag"><<span class="name">artifactId</span>></span>spring-boot-starter-test<span class="tag"></<span class="name">artifactId</span>></span></span><br><span class="line"><span class="tag"><<span class="name">scope</span>></span>test<span class="tag"></<span class="name">scope</span>></span></span><br><span class="line"><span class="tag"></<span class="name">dependency</span>></span></span><br><span class="line"><span class="tag"><<span class="name">dependency</span>></span></span><br><span class="line"><span class="tag"><<span class="name">groupId</span>></span>com.alibaba<span class="tag"></<span class="name">groupId</span>></span></span><br><span class="line"><span class="tag"><<span class="name">artifactId</span>></span>fastjson<span class="tag"></<span class="name">artifactId</span>></span></span><br><span class="line"><span class="tag"><<span class="name">version</span>></span>2.0.20<span class="tag"></<span class="name">version</span>></span></span><br><span class="line"><span class="tag"></<span class="name">dependency</span>></span></span><br><span class="line"><span class="tag"></<span class="name">dependencies</span>></span></span><br><span class="line"></span><br><span class="line"><span class="tag"><<span class="name">build</span>></span></span><br><span class="line"><span class="tag"><<span class="name">plugins</span>></span></span><br><span class="line"><span class="tag"><<span class="name">plugin</span>></span></span><br><span class="line"><span class="tag"><<span class="name">groupId</span>></span>org.springframework.boot<span class="tag"></<span class="name">groupId</span>></span></span><br><span class="line"><span class="tag"><<span class="name">artifactId</span>></span>spring-boot-maven-plugin<span class="tag"></<span class="name">artifactId</span>></span></span><br><span class="line"><span class="tag"></<span class="name">plugin</span>></span></span><br><span class="line"><span class="tag"></<span class="name">plugins</span>></span></span><br><span class="line"><span class="tag"></<span class="name">build</span>></span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="tag"></<span class="name">project</span>></span></span><br><span class="line"></span><br></pre></td></tr></tbody></table></figure><p>// 定义相关地址,以及session集合,用户存储管理client</p><p>ws://{ip}:{port}/websocket/data</p><figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.cloudkd.websocket;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.io.IOException;</span><br><span class="line"><span class="keyword">import</span> java.util.HashMap;</span><br><span class="line"><span class="keyword">import</span> java.util.HashSet;</span><br><span class="line"><span class="keyword">import</span> java.util.Map;</span><br><span class="line"><span class="keyword">import</span> java.util.Set;</span><br><span class="line"><span class="keyword">import</span> java.util.concurrent.ConcurrentHashMap;</span><br><span class="line"><span class="keyword">import</span> java.util.concurrent.CopyOnWriteArraySet;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> javax.websocket.OnClose;</span><br><span class="line"><span class="keyword">import</span> javax.websocket.OnError;</span><br><span class="line"><span class="keyword">import</span> javax.websocket.OnMessage;</span><br><span class="line"><span class="keyword">import</span> javax.websocket.OnOpen;</span><br><span class="line"><span class="keyword">import</span> javax.websocket.Session;</span><br><span class="line"><span class="keyword">import</span> javax.websocket.server.ServerEndpoint;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> com.alibaba.fastjson.JSONObject;</span><br><span class="line"><span class="keyword">import</span> org.slf4j.Logger;</span><br><span class="line"><span class="keyword">import</span> org.slf4j.LoggerFactory;</span><br><span class="line"><span class="keyword">import</span> org.springframework.stereotype.Component;</span><br><span class="line"></span><br><span class="line"><span class="meta">@ServerEndpoint("/websocket/data")</span></span><br><span class="line"><span class="meta">@Component</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">WebSocketServer</span> {</span><br><span class="line"> <span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">final</span> <span class="type">Logger</span> <span class="variable">log</span> <span class="operator">=</span> LoggerFactory.getLogger(WebSocketServer.class);</span><br><span class="line"> <span class="comment">//静态变量,用来记录当前在线连接数。应该把它设计成线程安全的。</span></span><br><span class="line"> <span class="keyword">private</span> <span class="keyword">static</span> <span class="type">int</span> <span class="variable">onlineCount</span> <span class="operator">=</span> <span class="number">0</span>;</span><br><span class="line"> <span class="comment">//concurrent包的线程安全Set,用来存放每个客户端对应的MyWebSocket对象。</span></span><br><span class="line"> <span class="keyword">private</span> <span class="keyword">static</span> CopyOnWriteArraySet<WebSocketServer> webSocketSet = <span class="keyword">new</span> <span class="title class_">CopyOnWriteArraySet</span><WebSocketServer>();</span><br><span class="line"> <span class="comment">//与某个客户端的连接会话,需要通过它来给客户端发送数据</span></span><br><span class="line"></span><br><span class="line"> <span class="keyword">private</span> Session session;</span><br><span class="line"></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">kill</span><span class="params">(String id)</span> {</span><br><span class="line"> <span class="keyword">for</span> (WebSocketServer item : webSocketSet) {</span><br><span class="line"> <span class="keyword">try</span> {</span><br><span class="line"> <span class="keyword">if</span> (item.session.getId().equals(id)) {</span><br><span class="line"> log.info(<span class="string">"Kill {} success"</span>, id);</span><br><span class="line"> item.session.close();</span><br><span class="line"> }</span><br><span class="line"> } <span class="keyword">catch</span> (IOException ignored) {</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">static</span> Map<String, Object> <span class="title function_">getAllSessionIds</span><span class="params">()</span> {</span><br><span class="line"> Map<String, Object> map = <span class="keyword">new</span> <span class="title class_">HashMap</span><>();</span><br><span class="line"> <span class="keyword">for</span> (WebSocketServer item : webSocketSet) {</span><br><span class="line"> map.put(item.session.getId(),item.session.getId());</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> map;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 连接建立成功调用的方法</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"> <span class="meta">@OnOpen</span></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">onOpen</span><span class="params">(Session session)</span> {</span><br><span class="line"> <span class="built_in">this</span>.session = session;</span><br><span class="line"> <span class="comment">//加入set中</span></span><br><span class="line"> webSocketSet.add(<span class="built_in">this</span>);</span><br><span class="line"> <span class="comment">//在线数加1</span></span><br><span class="line"> addOnlineCount();</span><br><span class="line"> log.info(<span class="string">"有新连接加入!当前在线人数为"</span> + getOnlineCount());</span><br><span class="line"> <span class="keyword">try</span> {</span><br><span class="line"> sendMessage(<span class="string">"连接成功"</span>);</span><br><span class="line"> } <span class="keyword">catch</span> (IOException e) {</span><br><span class="line"> log.error(<span class="string">"websocket IO异常"</span>);</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="comment">////连接打开时执行</span></span><br><span class="line"> <span class="comment">//@OnOpen</span></span><br><span class="line"> <span class="comment">//public void onOpen(@PathParam("user") String user, Session session) {</span></span><br><span class="line"> <span class="comment">//currentUser = user;</span></span><br><span class="line"> <span class="comment">//System.out.println("Connected ... " + session.getId());</span></span><br><span class="line"> <span class="comment">//}</span></span><br><span class="line"></span><br><span class="line"> <span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 连接关闭调用的方法</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"> <span class="meta">@OnClose</span></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">onClose</span><span class="params">()</span> {</span><br><span class="line"> webSocketSet.remove(<span class="built_in">this</span>); <span class="comment">//从set中删除</span></span><br><span class="line"> subOnlineCount(); <span class="comment">//在线数减1</span></span><br><span class="line"> log.info(<span class="string">"有一连接关闭!当前在线人数为"</span> + getOnlineCount());</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 收到客户端消息后调用的方法</span></span><br><span class="line"><span class="comment"> *</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param</span> message 客户端发送过来的消息</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"> <span class="meta">@OnMessage</span></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">onMessage</span><span class="params">(String message, Session session)</span> {</span><br><span class="line"> log.info(<span class="string">"来自客户端的消息 sessionId = {} ,data :{}"</span>, session.getId(), message);</span><br><span class="line"> <span class="comment">//群发消息</span></span><br><span class="line"> <span class="comment">// for (WebSocketServer item : webSocketSet) {</span></span><br><span class="line"> <span class="comment">// try {</span></span><br><span class="line"> <span class="comment">// item.sendMessage(message);</span></span><br><span class="line"> <span class="comment">// } catch (IOException e) {</span></span><br><span class="line"> <span class="comment">// e.printStackTrace();</span></span><br><span class="line"> <span class="comment">// }</span></span><br><span class="line"><span class="comment">// }</span></span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param</span> session</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param</span> error</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"> <span class="meta">@OnError</span></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">onError</span><span class="params">(Session session, Throwable error)</span> {</span><br><span class="line"> log.error(<span class="string">"发生错误"</span>);</span><br><span class="line"> error.printStackTrace();</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">sendMessage</span><span class="params">(String message)</span> <span class="keyword">throws</span> IOException {</span><br><span class="line"> <span class="built_in">this</span>.session.getBasicRemote().sendText(message);</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 群发自定义消息</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">sendInfo</span><span class="params">(BodyEntity message)</span> {</span><br><span class="line"> log.info(<span class="string">"SEND MESSAGE:{}"</span>, message);</span><br><span class="line"></span><br><span class="line"> <span class="keyword">for</span> (WebSocketServer item : webSocketSet) {</span><br><span class="line"> <span class="keyword">try</span> {</span><br><span class="line"> <span class="keyword">if</span> (item.session.getId().equals(message.getSessionId())) {</span><br><span class="line"> <span class="type">JSONObject</span> <span class="variable">sa</span> <span class="operator">=</span> JSONObject.parseObject(message.getMessage());</span><br><span class="line"> item.sendMessage(sa.toString());</span><br><span class="line"> }</span><br><span class="line"> } <span class="keyword">catch</span> (IOException ignored) {</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">synchronized</span> <span class="type">int</span> <span class="title function_">getOnlineCount</span><span class="params">()</span> {</span><br><span class="line"> <span class="keyword">return</span> onlineCount;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">synchronized</span> <span class="keyword">void</span> <span class="title function_">addOnlineCount</span><span class="params">()</span> {</span><br><span class="line"> WebSocketServer.onlineCount++;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">synchronized</span> <span class="keyword">void</span> <span class="title function_">subOnlineCount</span><span class="params">()</span> {</span><br><span class="line"> WebSocketServer.onlineCount--;</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"></span><br></pre></td></tr></tbody></table></figure><p>// WebSocketConfig 相关配置</p><figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.cloudkd.websocket;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> org.springframework.context.annotation.Bean;</span><br><span class="line"><span class="keyword">import</span> org.springframework.context.annotation.Configuration;</span><br><span class="line"><span class="keyword">import</span> org.springframework.web.socket.server.standard.ServerEndpointExporter;</span><br><span class="line"></span><br><span class="line"><span class="meta">@Configuration</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">WebSocketConfig</span> {</span><br><span class="line"> <span class="meta">@Bean</span></span><br><span class="line"> <span class="keyword">public</span> ServerEndpointExporter <span class="title function_">serverEndpointExporter</span><span class="params">()</span> {</span><br><span class="line"> <span class="keyword">return</span> <span class="keyword">new</span> <span class="title class_">ServerEndpointExporter</span>();</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure><p>// 管理api,可往对应连接发送消息</p><figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.cloudkd.websocket;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> org.slf4j.Logger;</span><br><span class="line"><span class="keyword">import</span> org.slf4j.LoggerFactory;</span><br><span class="line"><span class="keyword">import</span> org.springframework.web.bind.annotation.*;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.util.HashMap;</span><br><span class="line"><span class="keyword">import</span> java.util.Map;</span><br><span class="line"></span><br><span class="line"><span class="meta">@RestController</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">ManageController</span> {</span><br><span class="line"> <span class="keyword">private</span> <span class="keyword">final</span> <span class="type">Logger</span> <span class="variable">logger</span> <span class="operator">=</span> LoggerFactory.getLogger(<span class="built_in">this</span>.getClass());</span><br><span class="line"></span><br><span class="line"> <span class="meta">@PostMapping(value = "/pushData")</span></span><br><span class="line"> <span class="keyword">public</span> Map<String, Object> <span class="title function_">pushVideoListToWeb</span><span class="params">(<span class="meta">@RequestBody</span> BodyEntity message)</span> {</span><br><span class="line"> Map<String, Object> result = <span class="keyword">new</span> <span class="title class_">HashMap</span><String, Object>();</span><br><span class="line"> <span class="keyword">try</span> {</span><br><span class="line"> WebSocketServer.sendInfo(message);</span><br><span class="line"> result.put(<span class="string">"operationResult"</span>, <span class="literal">true</span>);</span><br><span class="line"> } <span class="keyword">catch</span> (Exception e) {</span><br><span class="line"> result.put(<span class="string">"operationResult"</span>, <span class="literal">true</span>);</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> result;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="meta">@GetMapping(value = "/kill")</span></span><br><span class="line"> <span class="keyword">public</span> Map<String, Object> <span class="title function_">pushVideoListToWeb</span><span class="params">(String id)</span> {</span><br><span class="line"> WebSocketServer.kill(id);</span><br><span class="line"> <span class="keyword">return</span> <span class="keyword">new</span> <span class="title class_">HashMap</span><>();</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="meta">@GetMapping(value = "/getAll")</span></span><br><span class="line"> <span class="keyword">public</span> Map<String, Object> <span class="title function_">getAll</span><span class="params">()</span> {</span><br><span class="line"> <span class="keyword">return</span> WebSocketServer.getAllSessionIds();</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">package</span> com.cloudkd.websocket;</span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">MessageEntity</span> {</span><br><span class="line"> <span class="keyword">private</span> String message;</span><br><span class="line"> <span class="keyword">private</span> String sessionId;</span><br><span class="line"></span><br><span class="line"> <span class="keyword">public</span> String <span class="title function_">getMessage</span><span class="params">()</span> {</span><br><span class="line"> <span class="keyword">return</span> message;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">setMessage</span><span class="params">(String message)</span> {</span><br><span class="line"> <span class="built_in">this</span>.message = message;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">public</span> String <span class="title function_">getSessionId</span><span class="params">()</span> {</span><br><span class="line"> <span class="keyword">return</span> sessionId;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">setSessionId</span><span class="params">(String sessionId)</span> {</span><br><span class="line"> <span class="built_in">this</span>.sessionId = sessionId;</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"></span><br></pre></td></tr></tbody></table></figure><p>// 测试页面</p><figure class="highlight html"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta"><!DOCTYPE <span class="keyword">html</span>></span></span><br><span class="line"><span class="tag"><<span class="name">html</span> <span class="attr">lang</span>=<span class="string">"en"</span>></span></span><br><span class="line"><span class="tag"><<span class="name">head</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">"UTF-8"</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">title</span>></span>Title<span class="tag"></<span class="name">title</span>></span></span><br><span class="line"> <span class="tag"></<span class="name">head</span>></span></span><br><span class="line"><span class="tag"><<span class="name">body</span>></span></span><br><span class="line"><span class="tag"><<span class="name">h3</span>></span>server地址 :<span class="tag"></<span class="name">h3</span>></span> <span class="tag"><<span class="name">input</span> <span class="attr">id</span>=<span class="string">"serveraddress"</span> <span class="attr">type</span>=<span class="string">"text"</span> <span class="attr">value</span>=<span class="string">"ws://192.168.102.17:28080/elevator/realData"</span> <span class="attr">style</span>=<span class="string">"width: 500px;%"</span>/></span><span class="tag"><<span class="name">br</span>/></span></span><br><span class="line"><span class="tag"><<span class="name">h3</span>></span>您的用户id :<span class="tag"></<span class="name">h3</span>></span> <span class="tag"><<span class="name">input</span> <span class="attr">id</span>=<span class="string">"userId"</span> <span class="attr">type</span>=<span class="string">"text"</span>/></span><span class="tag"><<span class="name">br</span>/></span></span><br><span class="line"><span class="tag"><<span class="name">button</span> <span class="attr">onclick</span>=<span class="string">"initSocket()"</span>></span>连接<span class="tag"></<span class="name">button</span>></span></span><br><span class="line"><span class="tag"><<span class="name">br</span>/></span></span><br><span class="line"></span><br><span class="line">=====================================================<span class="tag"><<span class="name">br</span>/></span></span><br><span class="line">消息 : <span class="tag"><<span class="name">input</span> <span class="attr">id</span>=<span class="string">"message"</span> <span class="attr">type</span>=<span class="string">"text"</span>/></span><span class="tag"><<span class="name">br</span>/></span></span><br><span class="line"><span class="tag"><<span class="name">button</span> <span class="attr">onclick</span>=<span class="string">"send()"</span>></span>发送<span class="tag"></<span class="name">button</span>></span></span><br><span class="line"><span class="tag"><<span class="name">br</span>/></span></span><br><span class="line">=====================================================<span class="tag"><<span class="name">br</span>/></span></span><br><span class="line">连接状态 :</span><br><span class="line"><span class="tag"><<span class="name">button</span> <span class="attr">onclick</span>=<span class="string">"clearConnectStatu()"</span>></span>清空<span class="tag"></<span class="name">button</span>></span></span><br><span class="line"><span class="tag"><<span class="name">br</span>/></span></span><br><span class="line"><span class="tag"><<span class="name">div</span> <span class="attr">id</span>=<span class="string">"connectStatu"</span>></span><span class="tag"></<span class="name">div</span>></span></span><br><span class="line"><span class="tag"><<span class="name">br</span>/></span></span><br><span class="line"></span><br><span class="line">=====================================================<span class="tag"><<span class="name">br</span>/></span></span><br><span class="line">收到消息 :<span class="tag"><<span class="name">br</span>/></span></span><br><span class="line"><span class="tag"><<span class="name">div</span> <span class="attr">id</span>=<span class="string">"receivedMessage"</span>></span><span class="tag"></<span class="name">div</span>></span></span><br><span class="line"><span class="tag"><<span class="name">br</span>/></span></span><br><span class="line">=====================================================<span class="tag"><<span class="name">br</span>/></span></span><br><span class="line">心跳 :<span class="tag"><<span class="name">br</span>/></span></span><br><span class="line"><span class="tag"><<span class="name">div</span> <span class="attr">id</span>=<span class="string">"heartdiv"</span>></span><span class="tag"></<span class="name">div</span>></span></span><br><span class="line"><span class="tag"><<span class="name">br</span>/></span></span><br><span class="line"></span><br><span class="line"><span class="tag"></<span class="name">body</span>></span></span><br><span class="line"></span><br><span class="line"><span class="tag"><<span class="name">script</span> <span class="attr">src</span>=<span class="string">"https://code.jquery.com/jquery-3.1.1.min.js"</span>></span><span class="tag"></<span class="name">script</span>></span></span><br><span class="line"><span class="tag"><<span class="name">script</span> <span class="attr">type</span>=<span class="string">"text/javascript"</span>></span><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript"> <span class="keyword">var</span> heartflag = <span class="literal">false</span>;</span></span><br><span class="line"><span class="language-javascript"> <span class="keyword">var</span> webSocket = <span class="literal">null</span>;</span></span><br><span class="line"><span class="language-javascript"> <span class="keyword">var</span> tryTime = <span class="number">0</span>;</span></span><br><span class="line"><span class="language-javascript"> $(<span class="keyword">function</span> (<span class="params"></span>) {</span></span><br><span class="line"><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript"><span class="comment">// initSocket();</span></span></span><br><span class="line"><span class="language-javascript"> <span class="variable language_">window</span>.<span class="property">onbeforeunload</span> = <span class="keyword">function</span> (<span class="params"></span>) {</span></span><br><span class="line"><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript"> };</span></span><br><span class="line"><span class="language-javascript"> });</span></span><br><span class="line"><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript"> <span class="comment">/**</span></span></span><br><span class="line"><span class="comment"><span class="language-javascript"> * 初始化websocket,建立连接</span></span></span><br><span class="line"><span class="comment"><span class="language-javascript"> */</span></span></span><br><span class="line"><span class="language-javascript"> <span class="keyword">function</span> <span class="title function_">initSocket</span>(<span class="params"></span>) {</span></span><br><span class="line"><span class="language-javascript"> <span class="keyword">var</span> serveraddress = $(<span class="string">"#serveraddress"</span>).<span class="title function_">val</span>();</span></span><br><span class="line"><span class="language-javascript"> <span class="keyword">var</span> userId = $(<span class="string">"#userId"</span>).<span class="title function_">val</span>();</span></span><br><span class="line"><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript"> <span class="keyword">if</span> (!<span class="variable language_">window</span>.<span class="property">WebSocket</span>) {</span></span><br><span class="line"><span class="language-javascript"> $(<span class="string">"#connectStatu"</span>).<span class="title function_">append</span>(<span class="title function_">getNowFormatDate</span>() + <span class="string">" 您的浏览器不支持ws<br/>"</span>);</span></span><br><span class="line"><span class="language-javascript"> <span class="keyword">return</span> <span class="literal">false</span>;</span></span><br><span class="line"><span class="language-javascript"> }</span></span><br><span class="line"><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript"> webSocket = <span class="keyword">new</span> <span class="title class_">WebSocket</span>(serveraddress<span class="comment">/* + "/" + userId*/</span>);</span></span><br><span class="line"><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript"> <span class="comment">// 收到服务端消息</span></span></span><br><span class="line"><span class="language-javascript"> webSocket.<span class="property">onmessage</span> = <span class="keyword">function</span> (<span class="params">msg</span>) {</span></span><br><span class="line"><span class="language-javascript"> <span class="keyword">if</span> (msg.<span class="property">data</span> !== <span class="string">"&"</span>) {</span></span><br><span class="line"><span class="language-javascript"> $(<span class="string">"#receivedMessage"</span>).<span class="title function_">append</span>(<span class="title function_">getNowFormatDate</span>() + <span class="string">" 收到消息 : "</span> + msg.<span class="property">data</span> + <span class="string">"<br/>"</span>);</span></span><br><span class="line"><span class="language-javascript"> }</span></span><br><span class="line"><span class="language-javascript"> };</span></span><br><span class="line"><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript"> <span class="comment">// 异常</span></span></span><br><span class="line"><span class="language-javascript"> webSocket.<span class="property">onerror</span> = <span class="keyword">function</span> (<span class="params">event</span>) {</span></span><br><span class="line"><span class="language-javascript"> heartflag = <span class="literal">false</span>;</span></span><br><span class="line"><span class="language-javascript"> $(<span class="string">"#connectStatu"</span>).<span class="title function_">append</span>(<span class="title function_">getNowFormatDate</span>() + <span class="string">" 异常<br/>"</span>);</span></span><br><span class="line"><span class="language-javascript"> };</span></span><br><span class="line"><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript"> <span class="comment">// 建立连接</span></span></span><br><span class="line"><span class="language-javascript"> webSocket.<span class="property">onopen</span> = <span class="keyword">function</span> (<span class="params">event</span>) {</span></span><br><span class="line"><span class="language-javascript"> heartflag = <span class="literal">true</span>;</span></span><br><span class="line"><span class="language-javascript"> <span class="title function_">heart</span>();</span></span><br><span class="line"><span class="language-javascript"> $(<span class="string">"#connectStatu"</span>).<span class="title function_">append</span>(<span class="title function_">getNowFormatDate</span>() + <span class="string">" 建立连接成功<br/>"</span>);</span></span><br><span class="line"><span class="language-javascript"> tryTime = <span class="number">0</span>;</span></span><br><span class="line"><span class="language-javascript"> };</span></span><br><span class="line"><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript"> <span class="comment">// 断线重连</span></span></span><br><span class="line"><span class="language-javascript"> webSocket.<span class="property">onclose</span> = <span class="keyword">function</span> (<span class="params"></span>) {</span></span><br><span class="line"><span class="language-javascript"> heartflag = <span class="literal">false</span>;</span></span><br><span class="line"><span class="language-javascript"> <span class="comment">// 重试10次,每次之间间隔10秒</span></span></span><br><span class="line"><span class="language-javascript"> <span class="keyword">if</span> (tryTime < <span class="number">10</span>) {</span></span><br><span class="line"><span class="language-javascript"> <span class="built_in">setTimeout</span>(<span class="keyword">function</span> (<span class="params"></span>) {</span></span><br><span class="line"><span class="language-javascript"> webSocket = <span class="literal">null</span>;</span></span><br><span class="line"><span class="language-javascript"> tryTime++;</span></span><br><span class="line"><span class="language-javascript"> <span class="title function_">initSocket</span>();</span></span><br><span class="line"><span class="language-javascript"> $(<span class="string">"#connectStatu"</span>).<span class="title function_">append</span>(<span class="title function_">getNowFormatDate</span>() + <span class="string">" 第"</span> + tryTime + <span class="string">"次重连<br/>"</span>);</span></span><br><span class="line"><span class="language-javascript"> }, <span class="number">3</span> * <span class="number">1000</span>);</span></span><br><span class="line"><span class="language-javascript"> } <span class="keyword">else</span> {</span></span><br><span class="line"><span class="language-javascript"> <span class="title function_">alert</span>(<span class="string">"重连失败."</span>);</span></span><br><span class="line"><span class="language-javascript"> }</span></span><br><span class="line"><span class="language-javascript"> };</span></span><br><span class="line"><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript"> }</span></span><br><span class="line"><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript"> <span class="keyword">function</span> <span class="title function_">send</span>(<span class="params"></span>) {</span></span><br><span class="line"><span class="language-javascript"> <span class="keyword">var</span> message = $(<span class="string">"#message"</span>).<span class="title function_">val</span>();</span></span><br><span class="line"><span class="language-javascript"> webSocket.<span class="title function_">send</span>(message);</span></span><br><span class="line"><span class="language-javascript"> }</span></span><br><span class="line"><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript"> <span class="keyword">function</span> <span class="title function_">clearConnectStatu</span>(<span class="params"></span>) {</span></span><br><span class="line"><span class="language-javascript"> $(<span class="string">"#connectStatu"</span>).<span class="title function_">empty</span>();</span></span><br><span class="line"><span class="language-javascript"> }</span></span><br><span class="line"><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript"> <span class="keyword">function</span> <span class="title function_">getNowFormatDate</span>(<span class="params"></span>) {</span></span><br><span class="line"><span class="language-javascript"> <span class="keyword">var</span> date = <span class="keyword">new</span> <span class="title class_">Date</span>();</span></span><br><span class="line"><span class="language-javascript"> <span class="keyword">var</span> seperator1 = <span class="string">"-"</span>;</span></span><br><span class="line"><span class="language-javascript"> <span class="keyword">var</span> seperator2 = <span class="string">":"</span>;</span></span><br><span class="line"><span class="language-javascript"> <span class="keyword">var</span> month = date.<span class="title function_">getMonth</span>() + <span class="number">1</span>;</span></span><br><span class="line"><span class="language-javascript"> <span class="keyword">var</span> strDate = date.<span class="title function_">getDate</span>();</span></span><br><span class="line"><span class="language-javascript"> <span class="keyword">if</span> (month >= <span class="number">1</span> && month <= <span class="number">9</span>) {</span></span><br><span class="line"><span class="language-javascript"> month = <span class="string">"0"</span> + month;</span></span><br><span class="line"><span class="language-javascript"> }</span></span><br><span class="line"><span class="language-javascript"> <span class="keyword">if</span> (strDate >= <span class="number">0</span> && strDate <= <span class="number">9</span>) {</span></span><br><span class="line"><span class="language-javascript"> strDate = <span class="string">"0"</span> + strDate;</span></span><br><span class="line"><span class="language-javascript"> }</span></span><br><span class="line"><span class="language-javascript"> <span class="keyword">var</span> currentdate = date.<span class="title function_">getFullYear</span>() + seperator1 + month + seperator1 + strDate</span></span><br><span class="line"><span class="language-javascript"> + <span class="string">" "</span> + date.<span class="title function_">getHours</span>() + seperator2 + date.<span class="title function_">getMinutes</span>()</span></span><br><span class="line"><span class="language-javascript"> + seperator2 + date.<span class="title function_">getSeconds</span>();</span></span><br><span class="line"><span class="language-javascript"> <span class="keyword">return</span> currentdate;</span></span><br><span class="line"><span class="language-javascript"> }</span></span><br><span class="line"><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript"> <span class="keyword">function</span> <span class="title function_">heart</span>(<span class="params"></span>) {</span></span><br><span class="line"><span class="language-javascript"> <span class="keyword">if</span> (heartflag) {</span></span><br><span class="line"><span class="language-javascript"> webSocket.<span class="title function_">send</span>(<span class="string">"&"</span>);</span></span><br><span class="line"><span class="language-javascript"> $(<span class="string">"#heartdiv"</span>).<span class="title function_">append</span>(<span class="title function_">getNowFormatDate</span>() + <span class="string">" 心跳 <br/>"</span>);</span></span><br><span class="line"><span class="language-javascript"> }</span></span><br><span class="line"><span class="language-javascript"> <span class="built_in">setTimeout</span>(<span class="string">"heart()"</span>, <span class="number">10</span> * <span class="number">60</span> * <span class="number">1000</span>);</span></span><br><span class="line"><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript"> }</span></span><br><span class="line"><span class="language-javascript"></span><span class="tag"></<span class="name">script</span>></span></span><br><span class="line"><span class="tag"></<span class="name">html</span>></span></span><br></pre></td></tr></tbody></table></figure><p>// 配置文件</p><figure class="highlight properties"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">server.port</span>=<span class="string">8081</span></span><br></pre></td></tr></tbody></table></figure><p>// 启动Main</p><figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@SpringBootApplication</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">WebsocketApplication</span> {</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> {</span><br><span class="line">SpringApplication.run(WebsocketApplication.class, args);</span><br><span class="line">}</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure><p>启动后默认,返回 http://{ip}:8081 ,进入测试页面</p>]]></content>
<summary type="html"><p>后端java springboot 项目</p>
<p>简单websocket server 端代码</p></summary>
<category term="java" scheme="https://removeif.github.io/categories/java/"/>
<category term="框架" scheme="https://removeif.github.io/categories/java/%E6%A1%86%E6%9E%B6/"/>
<category term="java" scheme="https://removeif.github.io/tags/java/"/>
<category term="springboot" scheme="https://removeif.github.io/tags/springboot/"/>
<category term="websocket" scheme="https://removeif.github.io/tags/websocket/"/>
<category term="websocket-server" scheme="https://removeif.github.io/tags/websocket-server/"/>
</entry>
<entry>
<title>Github-Action自动部署Hexo博客</title>
<link href="https://removeif.github.io/theme/Github-Action%E8%87%AA%E5%8A%A8%E9%83%A8%E7%BD%B2Hexo%E5%8D%9A%E5%AE%A2.html"/>
<id>https://removeif.github.io/theme/Github-Action%E8%87%AA%E5%8A%A8%E9%83%A8%E7%BD%B2Hexo%E5%8D%9A%E5%AE%A2.html</id>
<published>2024-12-22T08:46:08.000Z</published>
<updated>2025-01-06T09:42:34.426Z</updated>
<content type="html"><![CDATA[<p>写好文件,提交到GitHub<br>将会自动部署Hexo 博客</p><span id="more"></span><p>仓库目录中增加以下文件: .github\workflows\autodeploy.yml<br>内容如下</p><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 当有改动推送到master分支时,启动Action</span></span><br><span class="line">name: 自动部署</span><br><span class="line"></span><br><span class="line">on:</span><br><span class="line"> push:</span><br><span class="line"> branches:</span><br><span class="line"> - main <span class="comment">#2020年10月后github新建仓库默认分支改为main,注意更改</span></span><br><span class="line"></span><br><span class="line"> release:</span><br><span class="line"> types:</span><br><span class="line"> - published</span><br><span class="line"></span><br><span class="line"><span class="built_in">jobs</span>:</span><br><span class="line"> deploy:</span><br><span class="line"> runs-on: ubuntu-latest</span><br><span class="line"> steps:</span><br><span class="line"> - name: 检查分支</span><br><span class="line"> uses: actions/checkout@v2</span><br><span class="line"> with:</span><br><span class="line"> ref: main <span class="comment">#2020年10月后github新建仓库默认分支改为main,注意更改</span></span><br><span class="line"></span><br><span class="line"> - name: 安装 Node</span><br><span class="line"> uses: actions/setup-node@v1</span><br><span class="line"> with:</span><br><span class="line"> node-version: <span class="string">"14.x"</span> <span class="comment">#action使用的node版本,建议大版本和本地保持一致。可以在本地用node -v查询版本号。</span></span><br><span class="line"></span><br><span class="line"> - name: 安装 Hexo</span><br><span class="line"> run: |</span><br><span class="line"> <span class="built_in">export</span> TZ=<span class="string">'Asia/Shanghai'</span></span><br><span class="line"> npm install hexo-cli -g</span><br><span class="line"></span><br><span class="line"> - name: 缓存 Hexo</span><br><span class="line"> uses: actions/cache@v1</span><br><span class="line"> <span class="built_in">id</span>: cache</span><br><span class="line"> with:</span><br><span class="line"> path: node_modules</span><br><span class="line"> key: <span class="variable">${{runner.OS}</span>}-<span class="variable">${{hashFiles('**/package-lock.json')}</span>}</span><br><span class="line"></span><br><span class="line"> - name: 安装依赖</span><br><span class="line"> run: |</span><br><span class="line"> npm -v</span><br><span class="line"> npm install --save</span><br><span class="line"> <span class="built_in">echo</span> <span class="string">"'use strict';const pagination=require('hexo-pagination');module.exports=function(locals){var config=this.config;var posts=locals.posts;posts.data=posts.data.sort(function(a,b){if(a.top==undefined){a.top=0;}if(b.top==undefined){b.top=0;}if(a.top==b.top){return b.date-a.date;}else{return b.top-a.top;}});var paginationDir=config.pagination_dir||'page';return pagination('',posts,{perPage:config.index_generator.per_page,layout:['index','archive'],format:paginationDir+'/%d/',data:{__index:true}});};"</span> > ./node_modules/hexo-generator-index/lib/generator.js <span class="comment"># 可执行任何脚本,此处增加排序的逻辑</span></span><br><span class="line"></span><br><span class="line"> - name: 生成静态文件</span><br><span class="line"> run: |</span><br><span class="line"> hexo clean</span><br><span class="line"> hexo generate</span><br><span class="line"></span><br><span class="line"> - name: 部署 <span class="comment">#此处master:master 指从本地的master分支提交到远程仓库的master分支,若远程仓库没有对应分支则新建一个。如有其他需要,可以根据自己的需求更改。</span></span><br><span class="line"> run: |</span><br><span class="line"> <span class="built_in">cd</span> ./public</span><br><span class="line"> git init</span><br><span class="line"> git config --global user.name <span class="string">'${{ secrets.GITHUBUSERNAME }}'</span></span><br><span class="line"> git config --global user.email <span class="string">'${{ secrets.GITHUBEMAIL }}'</span></span><br><span class="line"> git add .</span><br><span class="line"> git commit -m <span class="string">"<span class="variable">${{ github.event.head_commit.message }</span>} <span class="subst">$(date +<span class="string">"%Z %Y-%m-%d %A %H:%M:%S"</span>)</span> Updated By Github Actions"</span></span><br><span class="line"> git push --force --quiet <span class="string">"https://<span class="variable">${{ secrets.GITHUBUSERNAME }</span>}:<span class="variable">${{ secrets.GITHUBTOKEN }</span>}@github.com/<span class="variable">${{ secrets.GITHUBUSERNAME }</span>}/<span class="variable">${{ secrets.GITHUBREPO }</span>}.git"</span> master:main</span><br></pre></td></tr></tbody></table></figure><p>代码中有相应的变量$,需要自行添加到仓库的配置中。</p>]]></content>
<summary type="html"><p>写好文件,提交到GitHub<br>将会自动部署Hexo 博客</p></summary>
<category term="自动部署Hexo博客,Github Action" scheme="https://removeif.github.io/categories/%E8%87%AA%E5%8A%A8%E9%83%A8%E7%BD%B2Hexo%E5%8D%9A%E5%AE%A2%EF%BC%8CGithub-Action/"/>
<category term="自动部署Hexo博客" scheme="https://removeif.github.io/tags/%E8%87%AA%E5%8A%A8%E9%83%A8%E7%BD%B2Hexo%E5%8D%9A%E5%AE%A2/"/>
</entry>
<entry>
<title>后续计划</title>
<link href="https://removeif.github.io/think/%E5%90%8E%E7%BB%AD%E8%AE%A1%E5%88%92.html"/>
<id>https://removeif.github.io/think/%E5%90%8E%E7%BB%AD%E8%AE%A1%E5%88%92.html</id>
<published>2023-04-28T12:44:10.000Z</published>
<updated>2025-01-06T09:42:34.426Z</updated>
<content type="html"><![CDATA[<h3 id="TODO"><a href="#TODO" class="headerlink" title="TODO"></a>TODO</h3><ul><li>重构博客</li><li>优化代码</li><li>坚持写优质博文</li></ul>]]></content>
<summary type="html"><h3 id="TODO"><a href="#TODO" class="headerlink" title="TODO"></a>TODO</h3><ul>
<li>重构博客</li>
<li>优化代码</li>
<li>坚持写优质博文</li>
</ul>
</summary>
<category term="think" scheme="https://removeif.github.io/categories/think/"/>
<category term="think" scheme="https://removeif.github.io/tags/think/"/>
</entry>
<entry>
<title>springboot接入dubbo-nacos注册中心</title>
<link href="https://removeif.github.io/java/frame/springboot-dubbo-nacos-example.html"/>
<id>https://removeif.github.io/java/frame/springboot-dubbo-nacos-example.html</id>
<published>2020-12-19T11:58:23.000Z</published>
<updated>2025-01-06T09:42:34.426Z</updated>
<content type="html"><![CDATA[<p>springboot接入dubbo-nacos注册中心</p><h3 id="项目结构:"><a href="#项目结构:" class="headerlink" title="项目结构:"></a>项目结构:</h3><span id="more"></span><p><img src="https://cdn.jsdelivr.net/gh/removeif/blog_image/img/2021/20201219113951.png"></p><h3 id="pro-parent"><a href="#pro-parent" class="headerlink" title="pro-parent"></a>pro-parent</h3><p>parent.pom</p><figure class="highlight xml"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta"><?xml version=<span class="string">"1.0"</span> encoding=<span class="string">"UTF-8"</span>?></span></span><br><span class="line"><span class="tag"><<span class="name">project</span> <span class="attr">xmlns</span>=<span class="string">"http://maven.apache.org/POM/4.0.0"</span></span></span><br><span class="line"><span class="tag"> <span class="attr">xmlns:xsi</span>=<span class="string">"http://www.w3.org/2001/XMLSchema-instance"</span></span></span><br><span class="line"><span class="tag"> <span class="attr">xsi:schemaLocation</span>=<span class="string">"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">artifactId</span>></span>pro-parent<span class="tag"></<span class="name">artifactId</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">groupId</span>></span>removeif.io.java<span class="tag"></<span class="name">groupId</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">version</span>></span>1.0-SNAPSHOT<span class="tag"></<span class="name">version</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">modelVersion</span>></span>4.0.0<span class="tag"></<span class="name">modelVersion</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">packaging</span>></span>pom<span class="tag"></<span class="name">packaging</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">modules</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">module</span>></span>service-api<span class="tag"></<span class="name">module</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">module</span>></span>service-provider<span class="tag"></<span class="name">module</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">module</span>></span>service-consumer<span class="tag"></<span class="name">module</span>></span></span><br><span class="line"> <span class="tag"></<span class="name">modules</span>></span></span><br><span class="line"><span class="tag"></<span class="name">project</span>></span></span><br><span class="line"></span><br></pre></td></tr></tbody></table></figure><h3 id="暴露服务接口api"><a href="#暴露服务接口api" class="headerlink" title="暴露服务接口api"></a>暴露服务接口api</h3><p>service-api.pom</p><figure class="highlight xml"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta"><?xml version=<span class="string">"1.0"</span> encoding=<span class="string">"UTF-8"</span>?></span></span><br><span class="line"><span class="tag"><<span class="name">project</span> <span class="attr">xmlns</span>=<span class="string">"http://maven.apache.org/POM/4.0.0"</span></span></span><br><span class="line"><span class="tag"> <span class="attr">xmlns:xsi</span>=<span class="string">"http://www.w3.org/2001/XMLSchema-instance"</span></span></span><br><span class="line"><span class="tag"> <span class="attr">xsi:schemaLocation</span>=<span class="string">"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">parent</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">artifactId</span>></span>pro-parent<span class="tag"></<span class="name">artifactId</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">groupId</span>></span>removeif.io.java<span class="tag"></<span class="name">groupId</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">version</span>></span>1.0-SNAPSHOT<span class="tag"></<span class="name">version</span>></span></span><br><span class="line"> <span class="tag"></<span class="name">parent</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">modelVersion</span>></span>4.0.0<span class="tag"></<span class="name">modelVersion</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">artifactId</span>></span>service-api<span class="tag"></<span class="name">artifactId</span>></span></span><br><span class="line"><span class="tag"></<span class="name">project</span>></span></span><br><span class="line"></span><br></pre></td></tr></tbody></table></figure><p>service-api.class</p><figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> io.github.removeif.springboot.api;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> io.github.removeif.springboot.dto.UserDTO;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 用户服务 RPC Service 接口</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">interface</span> <span class="title class_">UserRpcService</span> {</span><br><span class="line"></span><br><span class="line"> <span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 根据指定用户编号,获得用户信息</span></span><br><span class="line"><span class="comment"> *</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param</span> id 用户编号</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@return</span> 用户信息</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"> UserDTO <span class="title function_">get</span><span class="params">(Integer id)</span>;</span><br><span class="line"></span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="keyword">package</span> io.github.removeif.springboot.dto;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.io.Serializable;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 用户信息 DTO</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">UserDTO</span> <span class="keyword">implements</span> <span class="title class_">Serializable</span> {</span><br><span class="line"></span><br><span class="line"> <span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 用户编号</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"> <span class="keyword">private</span> Integer id;</span><br><span class="line"> <span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 昵称</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"> <span class="keyword">private</span> String name;</span><br><span class="line"> <span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 性别</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"> <span class="keyword">private</span> Integer gender;</span><br><span class="line"></span><br><span class="line"> <span class="keyword">public</span> Integer <span class="title function_">getId</span><span class="params">()</span> {</span><br><span class="line"> <span class="keyword">return</span> id;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">public</span> UserDTO <span class="title function_">setId</span><span class="params">(Integer id)</span> {</span><br><span class="line"> <span class="built_in">this</span>.id = id;</span><br><span class="line"> <span class="keyword">return</span> <span class="built_in">this</span>;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">public</span> String <span class="title function_">getName</span><span class="params">()</span> {</span><br><span class="line"> <span class="keyword">return</span> name;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">public</span> UserDTO <span class="title function_">setName</span><span class="params">(String name)</span> {</span><br><span class="line"> <span class="built_in">this</span>.name = name;</span><br><span class="line"> <span class="keyword">return</span> <span class="built_in">this</span>;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">public</span> Integer <span class="title function_">getGender</span><span class="params">()</span> {</span><br><span class="line"> <span class="keyword">return</span> gender;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">public</span> UserDTO <span class="title function_">setGender</span><span class="params">(Integer gender)</span> {</span><br><span class="line"> <span class="built_in">this</span>.gender = gender;</span><br><span class="line"> <span class="keyword">return</span> <span class="built_in">this</span>;</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></tbody></table></figure><h3 id="服务提供方service-provider"><a href="#服务提供方service-provider" class="headerlink" title="服务提供方service-provider"></a>服务提供方service-provider</h3><p>service-provider.pom</p><figure class="highlight xml"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta"><?xml version=<span class="string">"1.0"</span> encoding=<span class="string">"UTF-8"</span>?></span></span><br><span class="line"><span class="tag"><<span class="name">project</span> <span class="attr">xmlns</span>=<span class="string">"http://maven.apache.org/POM/4.0.0"</span></span></span><br><span class="line"><span class="tag"> <span class="attr">xmlns:xsi</span>=<span class="string">"http://www.w3.org/2001/XMLSchema-instance"</span></span></span><br><span class="line"><span class="tag"> <span class="attr">xsi:schemaLocation</span>=<span class="string">"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">parent</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">groupId</span>></span>org.springframework.boot<span class="tag"></<span class="name">groupId</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">artifactId</span>></span>spring-boot-starter-parent<span class="tag"></<span class="name">artifactId</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">version</span>></span>2.2.1.RELEASE<span class="tag"></<span class="name">version</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">relativePath</span>/></span> <span class="comment"><!-- lookup parent from repository --></span></span><br><span class="line"> <span class="tag"></<span class="name">parent</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">modelVersion</span>></span>4.0.0<span class="tag"></<span class="name">modelVersion</span>></span></span><br><span class="line"></span><br><span class="line"> <span class="tag"><<span class="name">artifactId</span>></span>service-provider<span class="tag"></<span class="name">artifactId</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">version</span>></span>1.0-SNAPSHOT<span class="tag"></<span class="name">version</span>></span></span><br><span class="line"></span><br><span class="line"> <span class="tag"><<span class="name">dependencies</span>></span></span><br><span class="line"> <span class="comment"><!-- 引入定义的 Dubbo API 接口 --></span></span><br><span class="line"> <span class="tag"><<span class="name">dependency</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">artifactId</span>></span>service-api<span class="tag"></<span class="name">artifactId</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">groupId</span>></span>removeif.io.java<span class="tag"></<span class="name">groupId</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">version</span>></span>1.0-SNAPSHOT<span class="tag"></<span class="name">version</span>></span></span><br><span class="line"> <span class="tag"></<span class="name">dependency</span>></span></span><br><span class="line"></span><br><span class="line"> <span class="comment"><!-- 引入 Spring Boot 依赖 --></span></span><br><span class="line"> <span class="tag"><<span class="name">dependency</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">groupId</span>></span>org.springframework.boot<span class="tag"></<span class="name">groupId</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">artifactId</span>></span>spring-boot-starter<span class="tag"></<span class="name">artifactId</span>></span></span><br><span class="line"> <span class="tag"></<span class="name">dependency</span>></span></span><br><span class="line"></span><br><span class="line"> <span class="comment"><!-- Dubbo Spring Cloud Starter --></span></span><br><span class="line"> <span class="tag"><<span class="name">dependency</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">groupId</span>></span>com.alibaba.cloud<span class="tag"></<span class="name">groupId</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">artifactId</span>></span>spring-cloud-starter-dubbo<span class="tag"></<span class="name">artifactId</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">version</span>></span>2.2.3.RELEASE<span class="tag"></<span class="name">version</span>></span></span><br><span class="line"> <span class="tag"></<span class="name">dependency</span>></span></span><br><span class="line"> <span class="comment"><!-- Spring Cloud Nacos Service Discovery --></span></span><br><span class="line"> <span class="tag"><<span class="name">dependency</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">groupId</span>></span>com.alibaba.cloud<span class="tag"></<span class="name">groupId</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">artifactId</span>></span>spring-cloud-starter-alibaba-nacos-discovery<span class="tag"></<span class="name">artifactId</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">version</span>></span>2.2.3.RELEASE<span class="tag"></<span class="name">version</span>></span></span><br><span class="line"> <span class="tag"></<span class="name">dependency</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">dependency</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">groupId</span>></span>com.alibaba.cloud<span class="tag"></<span class="name">groupId</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">artifactId</span>></span>spring-cloud-starter-alibaba-nacos-config<span class="tag"></<span class="name">artifactId</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">version</span>></span>2.2.3.RELEASE<span class="tag"></<span class="name">version</span>></span></span><br><span class="line"> <span class="tag"></<span class="name">dependency</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">dependency</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">groupId</span>></span>com.alibaba.cloud<span class="tag"></<span class="name">groupId</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">artifactId</span>></span>spring-cloud-starter-alibaba-sentinel<span class="tag"></<span class="name">artifactId</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">version</span>></span>2.2.3.RELEASE<span class="tag"></<span class="name">version</span>></span></span><br><span class="line"> <span class="tag"></<span class="name">dependency</span>></span></span><br><span class="line"></span><br><span class="line"> <span class="tag"></<span class="name">dependencies</span>></span></span><br><span class="line"></span><br><span class="line"><span class="tag"></<span class="name">project</span>></span></span><br><span class="line"></span><br></pre></td></tr></tbody></table></figure><p>service-provider.yaml</p><figure class="highlight yaml"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line"> <span class="attr">application:</span></span><br><span class="line"> <span class="attr">name:</span> <span class="string">user-service-provider</span></span><br><span class="line"><span class="comment"># dubbo 配置项,对应 DubboConfigurationProperties 配置类</span></span><br><span class="line"><span class="attr">dubbo:</span></span><br><span class="line"> <span class="comment"># Dubbo 应用配置</span></span><br><span class="line"> <span class="attr">application:</span></span><br><span class="line"> <span class="attr">name:</span> <span class="string">user-service-provider</span> <span class="comment"># 应用名</span></span><br><span class="line"> <span class="comment"># Dubbo 注册中心配</span></span><br><span class="line"> <span class="attr">registry:</span></span><br><span class="line"> <span class="attr">address:</span> <span class="string">nacos://127.0.0.1:8848</span> <span class="comment"># 注册中心地址。可以配置多注册中心,可见 http://dubbo.apache.org/zh-cn/docs/user/references/registry/introduction.html 文档。</span></span><br><span class="line"> <span class="attr">group:</span> <span class="string">dev</span> <span class="comment">#分组 可用于环境隔离,不同分组不能调用</span></span><br><span class="line"> <span class="string">parameters[namespace]:</span> <span class="string">dev</span> <span class="comment"># 空间管理</span></span><br><span class="line"> <span class="comment"># Dubbo 服务提供者协议配置</span></span><br><span class="line"> <span class="attr">protocol:</span></span><br><span class="line"> <span class="attr">port:</span> <span class="number">-1</span> <span class="comment"># 协议端口。使用 -1 表示随机端口。</span></span><br><span class="line"> <span class="attr">name:</span> <span class="string">dubbo</span> <span class="comment"># 使用 `dubbo://` 协议。更多协议,可见 http://dubbo.apache.org/zh-cn/docs/user/references/protocol/introduction.html 文档</span></span><br><span class="line"> <span class="comment"># Dubbo 服务提供者配置</span></span><br><span class="line"> <span class="attr">provider:</span></span><br><span class="line"> <span class="attr">timeout:</span> <span class="number">1000</span> <span class="comment"># 【重要】远程服务调用超时时间,单位:毫秒。默认为 1000 毫秒,可以根据自己业务修改</span></span><br><span class="line"> <span class="attr">UserRpcService:</span></span><br><span class="line"> <span class="attr">version:</span> <span class="number">1.0</span><span class="number">.0</span></span><br><span class="line"> <span class="comment"># 配置扫描 Dubbo 自定义的 @Service 注解,暴露成 Dubbo 服务提供者</span></span><br><span class="line"> <span class="attr">scan:</span></span><br><span class="line"> <span class="attr">base-packages:</span> <span class="string">io.github.removeif.springboot.service</span></span><br><span class="line"></span><br></pre></td></tr></tbody></table></figure><p>group以及namespace对应nacos中结构:</p><p><img src="https://cdn.jsdelivr.net/gh/removeif/blog_image/img/2021/20201219114730.png"></p><p>service-provider.class</p><figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> io.github.removeif.springboot.service;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> io.github.removeif.springboot.api.UserRpcService;</span><br><span class="line"><span class="keyword">import</span> io.github.removeif.springboot.dto.UserDTO;</span><br><span class="line"><span class="keyword">import</span> org.apache.dubbo.config.annotation.DubboService;</span><br><span class="line"></span><br><span class="line"><span class="meta">@DubboService(version = "${dubbo.provider.UserRpcService.version}")</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">UserRpcServiceImpl</span> <span class="keyword">implements</span> <span class="title class_">UserRpcService</span> {</span><br><span class="line"></span><br><span class="line"> <span class="meta">@Override</span></span><br><span class="line"> <span class="keyword">public</span> UserDTO <span class="title function_">get</span><span class="params">(Integer id)</span> {</span><br><span class="line"> <span class="keyword">return</span> <span class="keyword">new</span> <span class="title class_">UserDTO</span>().setId(id)</span><br><span class="line"> .setName(<span class="string">"没有昵称:"</span> + id)</span><br><span class="line"> .setGender(id % <span class="number">2</span> + <span class="number">1</span>); <span class="comment">// 1 - 男;2 - 女</span></span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">package</span> io.github.removeif.springboot;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> org.apache.dubbo.config.spring.context.annotation.EnableDubbo;</span><br><span class="line"><span class="keyword">import</span> org.springframework.boot.SpringApplication;</span><br><span class="line"><span class="keyword">import</span> org.springframework.boot.autoconfigure.SpringBootApplication;</span><br><span class="line"></span><br><span class="line"><span class="meta">@SpringBootApplication</span></span><br><span class="line"><span class="meta">@EnableDubbo</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">ProviderApplication</span> {</span><br><span class="line"></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> {</span><br><span class="line"> <span class="comment">// 启动 Spring Boot 应用</span></span><br><span class="line"> SpringApplication.run(ProviderApplication.class, args);</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure><h3 id="消费方service-consumer"><a href="#消费方service-consumer" class="headerlink" title="消费方service-consumer"></a>消费方service-consumer</h3><p>service-consumer.pom</p><figure class="highlight xml"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta"><?xml version=<span class="string">"1.0"</span> encoding=<span class="string">"UTF-8"</span>?></span></span><br><span class="line"><span class="tag"><<span class="name">project</span> <span class="attr">xmlns</span>=<span class="string">"http://maven.apache.org/POM/4.0.0"</span></span></span><br><span class="line"><span class="tag"> <span class="attr">xmlns:xsi</span>=<span class="string">"http://www.w3.org/2001/XMLSchema-instance"</span></span></span><br><span class="line"><span class="tag"> <span class="attr">xsi:schemaLocation</span>=<span class="string">"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">parent</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">groupId</span>></span>org.springframework.boot<span class="tag"></<span class="name">groupId</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">artifactId</span>></span>spring-boot-starter-parent<span class="tag"></<span class="name">artifactId</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">version</span>></span>2.2.1.RELEASE<span class="tag"></<span class="name">version</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">relativePath</span>/></span> <span class="comment"><!-- lookup parent from repository --></span></span><br><span class="line"> <span class="tag"></<span class="name">parent</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">modelVersion</span>></span>4.0.0<span class="tag"></<span class="name">modelVersion</span>></span></span><br><span class="line"></span><br><span class="line"> <span class="tag"><<span class="name">artifactId</span>></span>service-consumer<span class="tag"></<span class="name">artifactId</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">version</span>></span>1.0-SNAPSHOT<span class="tag"></<span class="name">version</span>></span></span><br><span class="line"></span><br><span class="line"> <span class="tag"><<span class="name">dependencies</span>></span></span><br><span class="line"> <span class="comment"><!-- 引入定义的 Dubbo API 接口 --></span></span><br><span class="line"> <span class="tag"><<span class="name">dependency</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">artifactId</span>></span>service-api<span class="tag"></<span class="name">artifactId</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">groupId</span>></span>removeif.io.java<span class="tag"></<span class="name">groupId</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">version</span>></span>1.0-SNAPSHOT<span class="tag"></<span class="name">version</span>></span></span><br><span class="line"> <span class="tag"></<span class="name">dependency</span>></span></span><br><span class="line"></span><br><span class="line"> <span class="comment"><!-- Dubbo Spring Cloud Starter --></span></span><br><span class="line"> <span class="tag"><<span class="name">dependency</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">groupId</span>></span>com.alibaba.cloud<span class="tag"></<span class="name">groupId</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">artifactId</span>></span>spring-cloud-starter-dubbo<span class="tag"></<span class="name">artifactId</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">version</span>></span>2.2.3.RELEASE<span class="tag"></<span class="name">version</span>></span></span><br><span class="line"> <span class="tag"></<span class="name">dependency</span>></span></span><br><span class="line"></span><br><span class="line"> <span class="comment"><!-- 引入 Spring Boot 依赖 --></span></span><br><span class="line"> <span class="tag"><<span class="name">dependency</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">groupId</span>></span>org.springframework.boot<span class="tag"></<span class="name">groupId</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">artifactId</span>></span>spring-boot-starter<span class="tag"></<span class="name">artifactId</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">version</span>></span>2.2.3.RELEASE<span class="tag"></<span class="name">version</span>></span></span><br><span class="line"> <span class="tag"></<span class="name">dependency</span>></span></span><br><span class="line"></span><br><span class="line"> <span class="comment"><!-- Spring Cloud Nacos Service Discovery --></span></span><br><span class="line"> <span class="tag"><<span class="name">dependency</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">groupId</span>></span>com.alibaba.cloud<span class="tag"></<span class="name">groupId</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">artifactId</span>></span>spring-cloud-starter-alibaba-nacos-discovery<span class="tag"></<span class="name">artifactId</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">version</span>></span>2.2.3.RELEASE<span class="tag"></<span class="name">version</span>></span></span><br><span class="line"> <span class="tag"></<span class="name">dependency</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">dependency</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">groupId</span>></span>com.alibaba.cloud<span class="tag"></<span class="name">groupId</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">artifactId</span>></span>spring-cloud-starter-alibaba-nacos-config<span class="tag"></<span class="name">artifactId</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">version</span>></span>2.2.3.RELEASE<span class="tag"></<span class="name">version</span>></span></span><br><span class="line"> <span class="tag"></<span class="name">dependency</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">dependency</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">groupId</span>></span>com.alibaba.cloud<span class="tag"></<span class="name">groupId</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">artifactId</span>></span>spring-cloud-starter-alibaba-sentinel<span class="tag"></<span class="name">artifactId</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">version</span>></span>2.2.3.RELEASE<span class="tag"></<span class="name">version</span>></span></span><br><span class="line"> <span class="tag"></<span class="name">dependency</span>></span></span><br><span class="line"> <span class="tag"></<span class="name">dependencies</span>></span></span><br><span class="line"></span><br><span class="line"><span class="tag"></<span class="name">project</span>></span></span><br><span class="line"></span><br></pre></td></tr></tbody></table></figure><p>service-consumer.ymal</p><figure class="highlight yaml"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line"> <span class="attr">application:</span></span><br><span class="line"> <span class="attr">name:</span> <span class="string">user-service-consumer</span></span><br><span class="line"><span class="comment"># dubbo 配置项,对应 DubboConfigurationProperties 配置类</span></span><br><span class="line"><span class="attr">dubbo:</span></span><br><span class="line"> <span class="comment"># Dubbo 应用配置</span></span><br><span class="line"> <span class="attr">application:</span></span><br><span class="line"> <span class="attr">name:</span> <span class="string">user-service-consumer</span> <span class="comment"># 应用名</span></span><br><span class="line"> <span class="comment"># Dubbo 注册中心配置</span></span><br><span class="line"> <span class="attr">registry:</span></span><br><span class="line"> <span class="attr">address:</span> <span class="string">nacos://127.0.0.1:8848</span> <span class="comment"># 注册中心地址。可以配置多注册中心,可见 http://dubbo.apache.org/zh-cn/docs/user/references/registry/introduction.html 文档。</span></span><br><span class="line"> <span class="attr">group:</span> <span class="string">dev</span> <span class="comment">#分组</span></span><br><span class="line"> <span class="string">parameters[namespace]:</span> <span class="string">dev</span> <span class="comment"># 空间管理</span></span><br><span class="line"> <span class="comment"># Dubbo 消费者配置</span></span><br><span class="line"> <span class="attr">consumer:</span></span><br><span class="line"> <span class="attr">timeout:</span> <span class="number">1000</span> <span class="comment"># 【重要】远程服务调用超时时间,单位:毫秒。默认为 1000 毫秒,可以根据自己业务修改</span></span><br><span class="line"> <span class="attr">UserRpcService:</span></span><br><span class="line"> <span class="attr">version:</span> <span class="number">1.0</span><span class="number">.0</span></span><br><span class="line"> <span class="attr">protocol:</span></span><br><span class="line"> <span class="attr">port:</span> <span class="number">-1</span></span><br><span class="line"> <span class="attr">name:</span> <span class="string">dubbo</span></span><br><span class="line"></span><br></pre></td></tr></tbody></table></figure><p>service-consumer.class</p><figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> io.github.removeif.springboot;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> io.github.removeif.springboot.api.UserRpcService;</span><br><span class="line"><span class="keyword">import</span> io.github.removeif.springboot.dto.UserDTO;</span><br><span class="line"><span class="keyword">import</span> org.apache.dubbo.config.annotation.DubboReference;</span><br><span class="line"><span class="keyword">import</span> org.apache.dubbo.config.spring.context.annotation.EnableDubbo;</span><br><span class="line"><span class="keyword">import</span> org.slf4j.Logger;</span><br><span class="line"><span class="keyword">import</span> org.slf4j.LoggerFactory;</span><br><span class="line"><span class="keyword">import</span> org.springframework.boot.CommandLineRunner;</span><br><span class="line"><span class="keyword">import</span> org.springframework.boot.SpringApplication;</span><br><span class="line"><span class="keyword">import</span> org.springframework.boot.autoconfigure.SpringBootApplication;</span><br><span class="line"><span class="keyword">import</span> org.springframework.context.ConfigurableApplicationContext;</span><br><span class="line"><span class="keyword">import</span> org.springframework.stereotype.Component;</span><br><span class="line"></span><br><span class="line"><span class="meta">@SpringBootApplication</span></span><br><span class="line"><span class="meta">@EnableDubbo</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">ConsumerApplication</span> {</span><br><span class="line"></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> {</span><br><span class="line"> <span class="comment">// 启动 Spring Boot 应用</span></span><br><span class="line"> <span class="type">ConfigurableApplicationContext</span> <span class="variable">context</span> <span class="operator">=</span> SpringApplication.run(ConsumerApplication.class, args);</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="meta">@Component</span></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">UserRpcServiceTest</span> <span class="keyword">implements</span> <span class="title class_">CommandLineRunner</span> {</span><br><span class="line"></span><br><span class="line"> <span class="keyword">private</span> <span class="keyword">final</span> <span class="type">Logger</span> <span class="variable">logger</span> <span class="operator">=</span> LoggerFactory.getLogger(getClass());</span><br><span class="line"></span><br><span class="line"> <span class="meta">@DubboReference(version = "${dubbo.consumer.UserRpcService.version}")</span></span><br><span class="line"> <span class="keyword">private</span> UserRpcService userRpcService;</span><br><span class="line"></span><br><span class="line"> <span class="meta">@Override</span></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">run</span><span class="params">(String... args)</span> <span class="keyword">throws</span> Exception {</span><br><span class="line"> <span class="type">UserDTO</span> <span class="variable">user</span> <span class="operator">=</span> userRpcService.get(<span class="number">1</span>);</span><br><span class="line"> logger.info(<span class="string">"[run][发起一次 Dubbo RPC 请求,获得用户为({})"</span>, user);</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"></span><br></pre></td></tr></tbody></table></figure><p>启动provider,在启动consumer后可以看到控制台</p><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">2020-12-19 11:36:49.219 INFO 16272 --- [ main] c.a.c.n.registry.NacosServiceRegistry : nacos registry, DEFAULT_GROUP user-service-consumer 192.168.88.1:20881 register finished</span><br><span class="line">2020-12-19 11:36:49.228 INFO 16272 --- [ main] s.ConsumerApplication<span class="variable">$UserRpcServiceTest</span> : [run][发起一次 Dubbo RPC 请求,获得用户为(io.github.removeif.springboot.dto.UserDTO@79696332)</span><br><span class="line">2020-12-19 11:36:49.231 INFO 16272 --- [ main] c.a.n.client.config.impl.ClientWorker : [fixed-localhost_8848] [subscribe] user-service-consumer+DEFAULT_GROUP</span><br><span class="line">2020-12-19 11:36:49.231 INFO 16272 --- [ main] c.a.nacos.client.config.impl.CacheData : [fixed-localhost_8848] [add-listener] ok, tenant=, dataId=user-service-consumer, group=DEFAULT_GROUP, cnt=1</span><br><span class="line"></span><br></pre></td></tr></tbody></table></figure>]]></content>
<summary type="html"><p>springboot接入dubbo-nacos注册中心</p>
<h3 id="项目结构:"><a href="#项目结构:" class="headerlink" title="项目结构:"></a>项目结构:</h3></summary>
<category term="java" scheme="https://removeif.github.io/categories/java/"/>
<category term="springboot" scheme="https://removeif.github.io/categories/java/springboot/"/>
<category term="springboot" scheme="https://removeif.github.io/tags/springboot/"/>
<category term="nacos" scheme="https://removeif.github.io/tags/nacos/"/>
<category term="dubbo" scheme="https://removeif.github.io/tags/dubbo/"/>
</entry>
<entry>
<title>Java-策略模式</title>
<link href="https://removeif.github.io/java/design-mode/java-strategy-pattern.html"/>
<id>https://removeif.github.io/java/design-mode/java-strategy-pattern.html</id>
<published>2020-07-02T17:42:48.000Z</published>
<updated>2025-01-06T09:42:34.422Z</updated>
<content type="html"><![CDATA[<p>策略模式遵循开闭原则,实现代码的解耦合。扩展新的方法时也比较方便,只需要继承策略接口就好了上面列出的这两点算是策略模式的优点了,但是不是说他就是完美的,有很多缺点仍然需要我们去掌握和理解。<br>策略模式把对象本身和运算规则区分开来,因此我们整个模式也分为三个部分。</p><ul><li>环境类(Context):用来操作策略的上下文环境,也就是我们游客。</li><li>抽象策略类(Strategy):策略的抽象,出行方式的抽象</li><li>具体策略类(ConcreteStrategy):具体的策略实现,每一种出行方式的具体实现。<span id="more"></span></li></ul><h3 id="一、策略模式定义"><a href="#一、策略模式定义" class="headerlink" title="一、策略模式定义"></a>一、策略模式定义</h3><p>举个列子</p><p>我们出去旅游的时候可能有很多种出行方式,比如说我们可以坐火车、坐高铁、坐飞机等等。不管我们使用哪一种出行方式,最终的目的地都是一样的。也就是选择不同的方式产生的结果都是一样的。</p><p><strong>定义一系列的算法,把每一个算法封装起来, 并且使它们可相互替换</strong></p><h3 id="二、实现策略模式"><a href="#二、实现策略模式" class="headerlink" title="二、实现策略模式"></a>二、实现策略模式</h3><p>策略模式把对象本身和运算规则区分开来,因此我们整个模式也分为三个部分。</p><ul><li>环境类(Context):用来操作策略的上下文环境,也就是我们游客。</li><li>抽象策略类(Strategy):策略的抽象,出行方式的抽象</li><li>具体策略类(ConcreteStrategy):具体的策略实现,每一种出行方式的具体实现。</li></ul><h4 id="第一步:定义抽象策略接口"><a href="#第一步:定义抽象策略接口" class="headerlink" title="第一步:定义抽象策略接口"></a>第一步:定义抽象策略接口</h4><figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">interface</span> <span class="title class_">TravelStrategy</span>{</span><br><span class="line"> <span class="keyword">void</span> <span class="title function_">travelStyle</span><span class="params">()</span>;</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure><h4 id="第二步:具体策略类"><a href="#第二步:具体策略类" class="headerlink" title="第二步:具体策略类"></a>第二步:具体策略类</h4><figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">TrainStrategy</span> <span class="keyword">implements</span> <span class="title class_">TravelStrategy</span>{</span><br><span class="line"> <span class="meta">@Override</span></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">travelStyle</span><span class="params">()</span>{</span><br><span class="line"> System.out.println(<span class="string">"火车"</span>);</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">HighTrainStrategy</span> <span class="keyword">implements</span> <span class="title class_">TravelStrategy</span>{</span><br><span class="line"> <span class="meta">@Override</span></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">travelStyle</span><span class="params">()</span>{</span><br><span class="line"> System.out.println(<span class="string">"高铁"</span>);</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">AirplaneStrategy</span> <span class="keyword">implements</span> <span class="title class_">TravelStrategy</span>{</span><br><span class="line"> <span class="meta">@Override</span></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">travelStyle</span><span class="params">()</span>{</span><br><span class="line"> System.out.println(<span class="string">"飞机"</span>);</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure><h4 id="第三步:环境类实现"><a href="#第三步:环境类实现" class="headerlink" title="第三步:环境类实现"></a>第三步:环境类实现</h4><figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">Traveler</span>{</span><br><span class="line"> <span class="keyword">private</span> TravelStrategy travelStrategy;</span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">setTravelStrategy</span><span class="params">(TravelStrategy travelStrategy)</span>{</span><br><span class="line"> <span class="built_in">this</span>.travelStrategy = travelStrategy;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">travelStyle</span><span class="params">()</span>{</span><br><span class="line"> travelStrategy.travelStyle();</span><br><span class="line"> }</span><br><span class="line"> </span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span>{</span><br><span class="line"> </span><br><span class="line"> <span class="type">Traveler</span> <span class="variable">traveler</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">Traveler</span>();</span><br><span class="line"> traveler.setTravelStrategy(<span class="keyword">new</span> <span class="title class_">AirplaneStrategy</span>())</span><br><span class="line"> <span class="comment">// 飞机出行</span></span><br><span class="line"> traveler.travelStyle()</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure><h3 id="三、分析策略模式"><a href="#三、分析策略模式" class="headerlink" title="三、分析策略模式"></a>三、分析策略模式</h3><h4 id="策略模式的优点:"><a href="#策略模式的优点:" class="headerlink" title="策略模式的优点:"></a>策略模式的优点:</h4><ul><li>我们之前在选择出行方式的时候,往往会使用if-else语句,也就是用户不选择A那么就选择B这样的一种情况。这种情况耦合性太高了,而且代码臃肿,有了策略模式我们就可以避免这种现象。</li><li>策略模式遵循开闭原则,实现代码的解耦合。扩展新的方法时也比较方便,只需要继承策略接口就好了上面列出的这两点算是策略模式的优点了,但是不是说他就是完美的,有很多缺点仍然需要我们去掌握和理解。</li></ul><h4 id="策略模式的优点:-1"><a href="#策略模式的优点:-1" class="headerlink" title="策略模式的优点:"></a>策略模式的优点:</h4><ul><li><p>客户端必须知道所有的策略类,并自行决定使用哪一个策略类。</p></li><li><p>策略模式会出现很多的策略类。</p></li><li><p>context在使用这些策略类的时候,这些策略类由于继承了策略接口,所以有些数据可能用不到,但是依然初始化了。</p></li></ul><p>参考文章:<br><a href="https://baijiahao.baidu.com/s?id=1638224488060180625&wfr=spider&for=pc">参考链接</a></p>]]></content>
<summary type="html"><p>策略模式遵循开闭原则,实现代码的解耦合。扩展新的方法时也比较方便,只需要继承策略接口就好了上面列出的这两点算是策略模式的优点了,但是不是说他就是完美的,有很多缺点仍然需要我们去掌握和理解。<br>策略模式把对象本身和运算规则区分开来,因此我们整个模式也分为三个部分。</p>
<ul>
<li>环境类(Context):用来操作策略的上下文环境,也就是我们游客。</li>
<li>抽象策略类(Strategy):策略的抽象,出行方式的抽象</li>
<li>具体策略类(ConcreteStrategy):具体的策略实现,每一种出行方式的具体实现。</li></ul></summary>
<category term="java" scheme="https://removeif.github.io/categories/java/"/>
<category term="设计模式" scheme="https://removeif.github.io/categories/java/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F/"/>
<category term="java" scheme="https://removeif.github.io/tags/java/"/>
<category term="设计模式" scheme="https://removeif.github.io/tags/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F/"/>
<category term="strategy" scheme="https://removeif.github.io/tags/strategy/"/>
</entry>
<entry>
<title>mysql允许最大sql语句长度配置</title>
<link href="https://removeif.github.io/database/mysql/mysql%E5%85%81%E8%AE%B8%E6%9C%80%E5%A4%A7sql%E8%AF%AD%E5%8F%A5%E9%95%BF%E5%BA%A6%E9%85%8D%E7%BD%AE.html"/>
<id>https://removeif.github.io/database/mysql/mysql%E5%85%81%E8%AE%B8%E6%9C%80%E5%A4%A7sql%E8%AF%AD%E5%8F%A5%E9%95%BF%E5%BA%A6%E9%85%8D%E7%BD%AE.html</id>
<published>2020-03-25T17:46:12.000Z</published>
<updated>2025-01-06T09:42:34.418Z</updated>
<content type="html"><![CDATA[<p>MySQL对于每个客户端连接都会分配连接buffer和结果集发送的buffer,连接buffer主要就是来接受客户端发送过来的sql语句,并且初始分配大小都是 <code>net_buffer_length</code>,可以动态增长,最多可以达到 <code>max_allow_packet</code>大小。这个参数是会话只读的,言外之意就是只能全局修改,新建连接才生效。<code>max_allow_packet</code>是MySQL控制网络包大小的参数,默认是4M。有次可控制一条mysql查询语句大大小,实现mysql慢sql相关优化。<span id="more"></span></p><h2 id="一、前言"><a href="#一、前言" class="headerlink" title="一、前言"></a>一、前言</h2><p>前几天在生产环境抓到一条慢SQL,内容大致如下:</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">select xxx from table where conditions and id in (in_list);</span><br></pre></td></tr></tbody></table></figure><p>这个SQL看起来貌似没有什么问题,但是 <code>in_list</code>的元素个数多达3000多个,然后我尝试统计了这个表的总数据量,刚好跟这个 <code>in_list</code>吻合,用大腿猜了下,应该是用了框架,先查出表里所有的数据放入list,再进行拼接生成的SQL,这尼玛不是蠢么。</p><h2 id="二、问题"><a href="#二、问题" class="headerlink" title="二、问题"></a>二、问题</h2><p>抛开这个蠢不蠢的问题,我比较关心的是在MySQL里面,这个 <code>in_list</code>的元素个数能不能控制。咨询了下叶师傅,加上自己搜索了一圈文档,很遗憾,MySQL没法限制这个 <code>in_list</code>的元素个数。那么既然没法控制 <code>in_list</code>,那我们是不是可以控制sql语句的长度呢?</p><p><strong>net_buffer_length</strong></p><p>MySQL有一个参数叫做 <code>net_buffer_length</code>,它是做什么用的呢?</p><figure class="highlight text"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">Each client thread is associated with a connection buffer and result buffer. Both begin with a size given by net_buffer_length but are dynamically enlarged up to max_allowed_packet bytes as needed. The result buffer shrinks to net_buffer_length after each SQL statement.This variable should not normally be changed, but if you have very little memory, you can set it to the expected length of statements sent by clients. If statements exceed this length, the connection buffer is automatically enlarged. The maximum value to which net_buffer_length can be set is 1MB.The session value of this variable is read only.</span><br></pre></td></tr></tbody></table></figure><p>简单翻译一下的意思就是,MySQL对于每个客户端连接都会分配连接buffer和结果集发送的buffer,连接buffer主要就是来接受客户端发送过来的sql语句,并且初始分配大小都是 <code>net_buffer_length</code>,可以动态增长,最多可以达到 <code>max_allow_packet</code>大小。这个参数是会话只读的,言外之意就是只能全局修改,新建连接才生效。<code>max_allow_packet</code>是MySQL控制网络包大小的参数,默认是4M。</p><h2 id="三、测试"><a href="#三、测试" class="headerlink" title="三、测试"></a>三、测试</h2><p>既然是这样的话,我们就来测试一把,下面是我的测试过程。</p><p><strong>参数设置</strong></p><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">root@mysqldb 16:58: [(none)]> show global variables like <span class="string">'net_buffer_length'</span>;</span><br><span class="line">+-------------------+-------+</span><br><span class="line">| Variable_name | Value |</span><br><span class="line">+-------------------+-------+</span><br><span class="line">| net_buffer_length | 16384 |</span><br><span class="line">+-------------------+-------+</span><br><span class="line">1 row <span class="keyword">in</span> <span class="built_in">set</span> (0.00 sec)</span><br><span class="line"></span><br><span class="line">root@mysqldb 17:00: [(none)]> show global variables like <span class="string">'max_allowed_packet'</span>;</span><br><span class="line">+--------------------+--------+</span><br><span class="line">| Variable_name | Value |</span><br><span class="line">+--------------------+--------+</span><br><span class="line">| max_allowed_packet | 131072 |</span><br><span class="line">+--------------------+--------+</span><br></pre></td></tr></tbody></table></figure><p>这里我设置 <code>net_buffer_length</code>为16K, <code>max_allowed_packet</code>为128K</p><p><strong>测试脚本</strong></p><figure class="highlight python"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#!/bin/env python</span></span><br><span class="line"><span class="comment">#coding:utf-8</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> pymysql</span><br><span class="line"></span><br><span class="line"><span class="keyword">def</span> <span class="title function_">get_in_list</span>(<span class="params">i</span>):</span><br><span class="line"> in_list = <span class="string">''</span></span><br><span class="line"> <span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">1</span>,i):</span><br><span class="line"> in_list = <span class="built_in">str</span>(i) + <span class="string">','</span> + in_list</span><br><span class="line"></span><br><span class="line"> in_list = in_list + <span class="built_in">str</span>(i+<span class="number">1</span>)</span><br><span class="line"> <span class="keyword">return</span> in_list</span><br><span class="line"></span><br><span class="line"><span class="keyword">def</span> <span class="title function_">exec_mysql</span>(<span class="params">sql</span>):</span><br><span class="line"> conn = pymysql.connect(host=<span class="string">'127.0.0.1'</span>, user=<span class="string">'xucl'</span>,</span><br><span class="line"> password=<span class="string">'xuclxucl123'</span>, database=<span class="string">'sbtest'</span>, charset=<span class="string">'utf8'</span>)</span><br><span class="line"> cursor = conn.cursor()</span><br><span class="line"> cursor.execute(sql)</span><br><span class="line"> results = cursor.fetchall()</span><br><span class="line"> <span class="keyword">if</span> results:</span><br><span class="line"> <span class="built_in">print</span>(<span class="string">"get results"</span>)</span><br><span class="line"> conn.close()</span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">"__main__"</span>:</span><br><span class="line"> in_list = get_in_list(<span class="number">100</span>)</span><br><span class="line"> sql = <span class="string">"select * from sbtest1 where id in ({})"</span>.<span class="built_in">format</span>(in_list)</span><br><span class="line"> <span class="comment"># 打印出sql占用的字节数</span></span><br><span class="line"> <span class="built_in">print</span>(<span class="built_in">len</span>(in_list.encode()))</span><br><span class="line"> exec_mysql(sql)</span><br></pre></td></tr></tbody></table></figure><p><strong>测试结果</strong></p><p>当i为4200时,sql大小为19892字节(大于 <code>net_buffer_length</code>),MySQL能正常返回数据,结果如下</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">[root@izbp13wpxafsmeraypddyvz python_scripts]# python test.py 19892get results</span><br></pre></td></tr></tbody></table></figure><p>当i为23690时,sql大小为131033字节(小于 <code>max_allowed_packet</code>),也能正常输出,结果如下,此时sql的字节数为131033</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">[root@izbp13wpxafsmeraypddyvz python_scripts]# python test.py 131033get results</span><br></pre></td></tr></tbody></table></figure><p>当i为23691时,sql大小为131039字节(仍然小于 <code>max_allowed_packet</code>),抛出异常</p><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line">[root@izbp13wpxafsmeraypddyvz python_scripts]# python test.py </span><br><span class="line">131039</span><br><span class="line">Traceback (most recent call last):</span><br><span class="line"> File <span class="string">"test.py"</span>, line 29, <span class="keyword">in</span> <module></span><br><span class="line"> exec_mysql(sql)</span><br><span class="line"> File <span class="string">"test.py"</span>, line 19, <span class="keyword">in</span> exec_mysql</span><br><span class="line"> cursor.execute(sql)</span><br><span class="line"> File <span class="string">"/usr/lib64/python2.7/site-packages/pymysql/cursors.py"</span>, line 170, <span class="keyword">in</span> execute</span><br><span class="line"> result = self._query(query)</span><br><span class="line"> File <span class="string">"/usr/lib64/python2.7/site-packages/pymysql/cursors.py"</span>, line 328, <span class="keyword">in</span> _query</span><br><span class="line"> conn.query(q)</span><br><span class="line"> File <span class="string">"/usr/lib64/python2.7/site-packages/pymysql/connections.py"</span>, line 517, <span class="keyword">in</span> query</span><br><span class="line"> self._affected_rows = self._read_query_result(unbuffered=unbuffered)</span><br><span class="line"> File <span class="string">"/usr/lib64/python2.7/site-packages/pymysql/connections.py"</span>, line 732, <span class="keyword">in</span> _read_query_result</span><br><span class="line"> result.read()</span><br><span class="line"> File <span class="string">"/usr/lib64/python2.7/site-packages/pymysql/connections.py"</span>, line 1075, <span class="keyword">in</span> <span class="built_in">read</span></span><br><span class="line"> first_packet = self.connection._read_packet()</span><br><span class="line"> File <span class="string">"/usr/lib64/python2.7/site-packages/pymysql/connections.py"</span>, line 684, <span class="keyword">in</span> _read_packet</span><br><span class="line"> packet.check_error()</span><br><span class="line"> File <span class="string">"/usr/lib64/python2.7/site-packages/pymysql/protocol.py"</span>, line 220, <span class="keyword">in</span> check_error</span><br><span class="line"> err.raise_mysql_exception(self._data)</span><br><span class="line"> File <span class="string">"/usr/lib64/python2.7/site-packages/pymysql/err.py"</span>, line 109, <span class="keyword">in</span> raise_mysql_exception</span><br><span class="line"> raise errorclass(errno, errval)</span><br><span class="line">pymysql.err.InternalError: (1153, u<span class="string">"Got a packet bigger than 'max_allowed_packet' bytes"</span>)</span><br></pre></td></tr></tbody></table></figure><p>MySQL错误日志如下:</p><figure class="highlight text"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">2020-03-10T09:07:46.992043Z 32 [Note] Aborted connection 32 to db: 'sbtest' user: 'xucl' host: '127.0.0.1' (Got a packet bigger than 'max_allowed_packet' bytes)</span><br></pre></td></tr></tbody></table></figure><p><strong>释惑</strong></p><p>为什么sql字节数为131039<131072( <code>max_allowed_packet</code>大小),MySQL还是报错了呢?因为这里还需要加上MySQL的包头大小,这个包头的大小是多少呢?还是用i=23690的例子,在MySQL服务器上抓包</p><p><img src="https://cdn.jsdelivr.net/gh/removeif/blog_image/img/2020/20200325174658.png"></p><p>看到MySQL接收到的包大小是131070字节,那么这个包头大小就为37字节了(未深入研究,留到以后研究),而上述实验中i=23691的例子中,sql大小为131039字节,加上包头的大小37字节,总大小为131076字节,大于 <code>max_allowed_packet</code>的131072,所以MySQL报错,符合逻辑。</p><h2 id="四、结论"><a href="#四、结论" class="headerlink" title="四、结论"></a>四、结论</h2><p>经过这次测试,得出了以下节点结论</p><ul><li>虽然MySQL没有限制子查询内元素个数,但是还是不建议元素太多,会影响执行计划同时也会影响SQL解析的效率和内存占用</li><li>适当调大 <code>net_buffer_length</code>,最好能够一次性缓存sql,无需再分配内存,并且这是一个全局性参数</li><li>适当调大 <code>max_allowed_packet</code>大小,但是也不要分配过大,这是一个会话级变量,生产建议调为32M为佳</li><li>学会利用抓包解决”网络”相关的问题</li></ul><p>参考文章:<br><a href="https://mp.weixin.qq.com/s/amzI5bhbkqiYt4BeVdQl0A">参考链接</a></p>]]></content>
<summary type="html"><p>MySQL对于每个客户端连接都会分配连接buffer和结果集发送的buffer,连接buffer主要就是来接受客户端发送过来的sql语句,并且初始分配大小都是 <code>net_buffer_length</code>,可以动态增长,最多可以达到 <code>max_allow_packet</code>大小。这个参数是会话只读的,言外之意就是只能全局修改,新建连接才生效。<code>max_allow_packet</code>是MySQL控制网络包大小的参数,默认是4M。有次可控制一条mysql查询语句大大小,实现mysql慢sql相关优化。</p></summary>
<category term="数据库" scheme="https://removeif.github.io/categories/%E6%95%B0%E6%8D%AE%E5%BA%93/"/>
<category term="mysql" scheme="https://removeif.github.io/categories/%E6%95%B0%E6%8D%AE%E5%BA%93/mysql/"/>
<category term="mysql" scheme="https://removeif.github.io/tags/mysql/"/>
<category term="慢sql" scheme="https://removeif.github.io/tags/%E6%85%A2sql/"/>
</entry>
<entry>
<title>github gpg failed to sign the data</title>
<link href="https://removeif.github.io/develop/github-gpg-failed-to-sign-the-data.html"/>
<id>https://removeif.github.io/develop/github-gpg-failed-to-sign-the-data.html</id>
<published>2020-03-20T19:05:03.000Z</published>
<updated>2025-01-06T09:42:34.418Z</updated>
<content type="html"><![CDATA[<p>git gpg commit sign error:<br>gpg failed to sign the data<br>fatal: failed to write commit object <span id="more"></span></p><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">brew uninstall gpg</span><br><span class="line">brew install gpg2</span><br><span class="line">brew install pinentry-mac (<span class="keyword">if</span> needed)</span><br><span class="line">gpg --full-generate-key <span class="comment">#Create a key by using an algorithm.</span></span><br><span class="line"><span class="comment">#Get generated key by executing: </span></span><br><span class="line">gpg --list-keys</span><br><span class="line"><span class="comment">#detail list</span></span><br><span class="line">gpg --list-secret-keys --keyid-format LONG</span><br><span class="line">sec rsa2048/F9F78B768Fxxxxx 2020-03-13 [SC] [有效至:2022-03-13]</span><br><span class="line"> 79418A9275A4D98B86FF39F6xxxxxxxxxxx</span><br><span class="line"><span class="comment">#Set the key here </span></span><br><span class="line">git config --global user.signingkey F9F78B768Fxxxxx</span><br><span class="line">git config --global gpg.program /usr/local/bin/gpg</span><br><span class="line">git config --global commit.gpgsign <span class="literal">true</span></span><br></pre></td></tr></tbody></table></figure><p>If you want to export your Key to GitHub then:<br><code>gpg --armor --export F9F78B768Fxxxxx </code>and add this key to GitHub at GPG keys: <a href="https://github.com/settings/keys">https://github.com/settings/keys</a> (with START and END line included)</p><p>If the issue still exists:</p><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">test</span> -r ~/.bash_profile && <span class="built_in">echo</span> <span class="string">'export GPG_TTY=$(tty)'</span> >> ~/.bash_profile</span><br><span class="line"></span><br><span class="line"><span class="built_in">echo</span> <span class="string">'export GPG_TTY=$(tty)'</span> >> ~/.profile</span><br></pre></td></tr></tbody></table></figure><p>If the issue still exists:</p><p>Install <a href="https://gpgtools.org/">https://gpgtools.org</a> and sign the key that you used by pressing Sign from the menu bar: Key->Sign</p><p>If the issue still exists:</p><p>Go to: your global .gitconfig file which in my case is at: <code>/Users/gent/.gitconfig</code> And modify the .gitconfig file (please make sure Email and Name are the same with the one that you have created while generating the Key):</p><figure class="highlight yaml"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">[<span class="string">user</span>]</span><br><span class="line"><span class="string">email</span> <span class="string">=</span> <span class="string">gent@youremail.com</span></span><br><span class="line"><span class="string">name</span> <span class="string">=</span> <span class="string">Gent</span></span><br><span class="line"><span class="string">signingkey</span> <span class="string">=</span> <span class="string"><YOURKEY></span></span><br><span class="line">[<span class="string">gpg</span>]</span><br><span class="line"><span class="string">program</span> <span class="string">=</span> <span class="string">/usr/local/bin/gpg</span></span><br><span class="line">[<span class="string">commit</span>]</span><br><span class="line"><span class="string">gpsign</span> <span class="string">=</span> <span class="literal">true</span></span><br><span class="line"><span class="string">gpgsign</span> <span class="string">=</span> <span class="literal">true</span></span><br><span class="line">[<span class="string">filter</span> <span class="string">"lfs"</span>]</span><br><span class="line"><span class="string">process</span> <span class="string">=</span> <span class="string">git-lfs</span> <span class="string">filter-process</span></span><br><span class="line"><span class="string">required</span> <span class="string">=</span> <span class="literal">true</span></span><br><span class="line"><span class="string">clean</span> <span class="string">=</span> <span class="string">git-lfs</span> <span class="string">clean</span> <span class="string">--</span> <span class="string">%f</span></span><br><span class="line"><span class="string">smudge</span> <span class="string">=</span> <span class="string">git-lfs</span> <span class="string">smudge</span> <span class="string">--</span> <span class="string">%f</span></span><br><span class="line">[<span class="string">credential</span>]</span><br><span class="line"><span class="string">helper</span> <span class="string">=</span> <span class="string">osxkeychain</span></span><br><span class="line"></span><br></pre></td></tr></tbody></table></figure><p>When you create and add a key to gpg-agent you define something called passphrase. Now that passphrase at some point expires, and gpg needs you to enter it again to unlock your key so that you can start signing again.</p><p>When you use any other program that interfaces with gpg, gpg’s prompt to you to enter your passphrase does not appear (basically gpg-agent when daemonized cannot possibly show you the input dialog in stdin).</p><p>One of the solutions is <code>gpg --sign a_file.txt</code> (<strong>this is very import!!!</strong>) then enter the passphrase that you have entered when you created your key and then everything should be fine (gpg-agent should automatically sign)</p><p>See this answer on how to set longer timeouts for your passphrase so that you do not have to do this all the time.</p><p>Or you can completely remove the passphrase with ssh-keygen -p</p><p>Edit: Do a man gpg-agent to read some stuff on how to have the above happen automatically and add the lines:</p><p>GPG_TTY=$(tty)<br>export GPG_TTY<br>on your .bashrc if you are using bash(this is the correct answer but I am keeping my train of thought above as well)</p><p>my environment</p><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">gpg --version</span><br><span class="line">gpg (GnuPG) 2.2.19</span><br><span class="line">libgcrypt 1.8.5</span><br><span class="line">Copyright (C) 2019 Free Software Foundation, Inc.</span><br><span class="line">License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html></span><br><span class="line">This is free software: you are free to change and redistribute it.</span><br><span class="line">There is NO WARRANTY, to the extent permitted by law.</span><br></pre></td></tr></tbody></table></figure><p>reference:<br><a href="https://stackoverflow.com/questions/39494631/gpg-failed-to-sign-the-data-fatal-failed-to-write-commit-object-git-2-10-0">reference</a></p>]]></content>
<summary type="html"><p>git gpg commit sign error:<br>gpg failed to sign the data<br>fatal: failed to write commit object</p></summary>
<category term="develop" scheme="https://removeif.github.io/categories/develop/"/>
<category term="git" scheme="https://removeif.github.io/categories/develop/git/"/>
<category term="git" scheme="https://removeif.github.io/tags/git/"/>
<category term="gpg sign" scheme="https://removeif.github.io/tags/gpg-sign/"/>
</entry>
<entry>
<title>mysql-like模糊查询优化</title>
<link href="https://removeif.github.io/database/mysql/mysql-like%E6%A8%A1%E7%B3%8A%E6%9F%A5%E8%AF%A2%E4%BC%98%E5%8C%96.html"/>
<id>https://removeif.github.io/database/mysql/mysql-like%E6%A8%A1%E7%B3%8A%E6%9F%A5%E8%AF%A2%E4%BC%98%E5%8C%96.html</id>
<published>2020-03-17T22:25:24.000Z</published>
<updated>2025-01-06T09:42:34.418Z</updated>
<content type="html"><![CDATA[<h3 id="sql语句写法"><a href="#sql语句写法" class="headerlink" title="sql语句写法"></a>sql语句写法</h3><p>一张表大概40万左右的数据,用<strong>like模糊查询title</strong>字段,很慢,title字段已经建立了索引,mysql 对 <code>someTitle%</code> 这样的模糊查询在有索引的前提下是很快的。<br>所以下面这两台sql语句差别就很大了<br>$sql1 = “… title like someTitle%” (0.001秒)</p><p>$sql2 = “…… title like %someTitle%” (0.8秒) <span id="more"></span></p><p>这两句的效率相差了800倍,这很可观啊。<br>所以我有个想法:在不用分词的方法的前提下,把存储的title字段,加一个特别的前缀,比如”im_prefix”,比如一条记录的title=”我是标题党”,那么存储的时候就存储为”im_prefix我是标题党”。<br>这样一来,我们要模糊查找”标题党”这个关键词的时候,就把sql写成这样:<br>$sql1 = “…… title like im_prefix%标题党%” (花费0.001秒),前台显示数据的时候,自然把取到的title过滤掉”im_prefix”这个前缀了。</p><p>在使用msyql进行模糊查询的时候,很自然的会用到like语句,通常情况下,在数据量小的时候,不容易看出查询的效率,但在数据量达到百万级,千万级的时候,查询的效率就很容易显现出来。这个时候查询的效率就显得很重要! </p><p>一般情况下like模糊查询的写法为(field已建立索引): </p><p>SELECT<code>column</code>FROM<code>table</code>WHERE<code>field</code>like’%keyword%’;</p><p>上面的语句用explain解释来看,SQL语句并未用到索引,而且是全表搜索,如果在数据量超大的时候,可想而知最后的效率会是这样</p><p>对比下面的写法:</p><p>SELECT<code>column</code>FROM<code>table</code>WHERE<code>field</code>like’keyword%’;</p><p>这样的写法用explain解释看到,SQL语句使用了索引,搜索的效率大大的提高了!</p><p>但是有的时候,我们在做模糊查询的时候,并非要想查询的关键词都在开头,所以如果不是特别的要求,”keywork%”并不合适所有的模糊查询</p><p>我在网上搜索时发现很多mysql函数用来解决这个问题,我测试出来的结果是跟like相比并没有任何优势。</p><p>1.LOCATE(’substr’,str,pos)方法</p><p>SELECT<code>column</code>FROM<code>table</code>WHERELOCATE(‘keyword’, <code>field</code>)>0</p><p>2.POSITION(‘substr’ IN <code>field</code>)方法</p><p>SELECT<code>column</code>FROM<code>table</code>WHEREPOSITION(‘keyword’IN<code>filed</code>)</p><p>3.INSTR(<code>str</code>,’substr’)方法</p><p>SELECT<code>column</code>FROM<code>table</code>WHEREINSTR(<code>field</code>,’keyword’)>0</p><p>这几种方法都试过后,发现百万级别数据以上,时间是跟like差不多,并没有解决问题,因为都没走到索引。</p><p>这种情况下想要实现后几位模糊查询并且速度要快,在此我想了两个办法,一个是不需要mysql版本支持,一个需要mysql5.7版本以上</p><h3 id="第一种方法:新增一列字段"><a href="#第一种方法:新增一列字段" class="headerlink" title="第一种方法:新增一列字段"></a>第一种方法:新增一列字段</h3><p>新增一列字段,那个字段是你需要实现模糊查询的倒序,也就是原本是ABCD,那列字段就是DCBA</p><p>然后在那个字段添上索引</p><p>UPDATE tbl_ser_apply a set order_no_desc = REVERSE (SUBSTRING(a.order_no, -6))</p><p>ALTER TABLE <code>tbl_ser_apply</code> ADD INDEX order_no_desc ( <code>order_no_desc</code> )</p><p>我这边设的是后六位 也就是我把之前字段的后6位倒序后存入新的字段,也可以整个字段倒序后存入新的字段</p><figure class="highlight sql"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> a.<span class="operator">*</span>,a1.id <span class="keyword">as</span> id2,a1.order_no <span class="keyword">as</span> orderNo2,a1.tran_amt <span class="keyword">as</span> tranAmt2,a1.fee_amt <span class="keyword">as</span> feeAmt2,a1.repayment_date_req <span class="keyword">as</span> repaymentDateReq2</span><br><span class="line"></span><br><span class="line"> ,a1.status <span class="keyword">as</span> status2,a1.create_time <span class="keyword">as</span> createTime2,a1.update_time <span class="keyword">as</span> updateTime2</span><br><span class="line"></span><br><span class="line"> <span class="keyword">from</span> (</span><br><span class="line"></span><br><span class="line"> <span class="keyword">select</span> tsa.id,tsa.order_no <span class="keyword">as</span> orderNo,tsa.repayment_date_req <span class="keyword">as</span> repaymentDateReq,tsa.status,tsa.fee_state <span class="keyword">as</span> feeState,tsa.repayment_flag <span class="keyword">as</span> repaymentFlag,</span><br><span class="line"></span><br><span class="line"> tsa.capital_return_flag <span class="keyword">as</span> capitalReturnFlag,tsa.tran_amt <span class="keyword">as</span> tranAmt,tsa.fee_amt <span class="keyword">as</span> feeAmt,tsa.capital_returned_amont <span class="keyword">as</span> capitalReturnedAmont,</span><br><span class="line"></span><br><span class="line"> tsa.wait_amt <span class="keyword">as</span> waitAmt,tsa.back_charge_amt <span class="keyword">as</span> backChargeAmt,tsa.create_time <span class="keyword">as</span> createTime,tui.real_name <span class="keyword">as</span> realName,tui.mobile_no <span class="keyword">as</span> mobileNo,</span><br><span class="line"></span><br><span class="line"> tc.bank_card_no <span class="keyword">as</span> bankCardNo,tmi.merchant_name <span class="keyword">as</span> merchantName,tui.mer_no <span class="keyword">as</span> merNo,tsa.reserved1 <span class="keyword">as</span> reserved1,tsa.parent_id <span class="keyword">as</span> parentId,tc.bank_name <span class="keyword">as</span> bankName,tc.holder_name <span class="keyword">as</span> holderName,</span><br><span class="line"></span><br><span class="line"> tc.certificate_no <span class="keyword">as</span> certificateNo</span><br><span class="line"></span><br><span class="line"> <span class="keyword">from</span> tbl_ser_apply <span class="keyword">as</span> tsa <span class="keyword">LEFT</span> <span class="keyword">JOIN</span> tbl_user_info <span class="keyword">as</span> tui <span class="keyword">on</span> tsa.userid<span class="operator">=</span>tui.id <span class="keyword">LEFT</span> <span class="keyword">JOIN</span> tbl_merchant_inf <span class="keyword">as</span> tmi <span class="keyword">on</span></span><br><span class="line"></span><br><span class="line"> tmi.merchant_no<span class="operator">=</span>tui.mer_no <span class="keyword">LEFT</span> <span class="keyword">JOIN</span> tbl_cusinfo tc <span class="keyword">on</span> tc.id<span class="operator">=</span>tsa.cusInf_id <span class="keyword">where</span> tsa.order_no_desc <span class="keyword">like</span> REVERSE(<span class="string">'%372191'</span>)</span><br><span class="line"></span><br><span class="line"> <span class="keyword">ORDER</span> <span class="keyword">BY</span> tsa.create_time <span class="keyword">desc</span> ) a <span class="keyword">LEFT</span> <span class="keyword">JOIN</span> tbl_ser_apply a1 <span class="keyword">on</span> a.parentId<span class="operator">=</span>a1.id</span><br><span class="line"></span><br></pre></td></tr></tbody></table></figure><p>我的整个sql是这样的</p><p>实际上最后查询的时候是这样</p><p>where tsa.order_no_desc like REVERSE(‘%372191’) </p><p>需要修改sql和java代码,查询的是新增反向字段,而不是原来的字段</p><p>这样就能实现走索引</p><p>原来的sql不走索引的情况下查询出来需要20S,优化后只需要0.049S</p><p><strong>这种方法适合mysql5.7以下版本,这样能大大加快模糊查询速度,而且能到1000W以上应该都是没问题的</strong></p><h3 id="第二种方法:虚拟列"><a href="#第二种方法:虚拟列" class="headerlink" title="第二种方法:虚拟列"></a>第二种方法:虚拟列</h3><p>需要mysql5.7以上版本支持,用到虚拟列的方法,原理跟上述方法一样</p><p>alter table tbl_ser_apply add column virtual_col varchar(20) as (REVERSE (SUBSTRING(tbl_ser_apply.order_no, -6)));</p><p>ALTER TABLE <code>tbl_ser_apply</code> ADD INDEX virtual_col ( <code> virtual_col</code> )</p><p>在MySQL 5.7中,支持两种Generated Column,即Virtual Generated Column和Stored Generated Column,前者只将Generated Column保存在数据字典中(表的元数据),并不会将这一列数据持久化到磁盘上;后者会将Generated Column持久化到磁盘上,而不是每次读取的时候计算所得。很明显,后者存放了可以通过已有数据计算而得的数据,需要更多的磁盘空间,与Virtual Column相比并没有优势,因此,MySQL 5.7中,不指定Generated Column的类型,默认是Virtual Column。 </p><p>如果需要Stored Generated Golumn的话,可能在Virtual Generated Column上建立索引更加合适</p><p>综上,一般情况下,都使用Virtual Generated Column,这也是MySQL默认的方式</p><p>语法:</p><p> [ GENERATED ALWAYS ] AS ( ) [ VIRTUAL|STORED ]</p><p>[ UNIQUE [KEY] ] [ [PRIMARY] KEY ] [ NOT NULL ] [ COMMENT ]</p><p>这样做比上一个方法好的地方是,不需要修改java代码,只需要修改很小一部分的sql语句即可,上一个方法其实实现后要修改的java代码要不少,而且每次新增修改删除时,都要加上这个字段的代码,而新增虚拟列的话,那一列的字段是自动添加修改,通过计算得出的,所以代码完全不需要修改,只需要修改操作原来字段的sql即可。</p><figure class="highlight sql"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> a.<span class="operator">*</span>,a1.id <span class="keyword">as</span> id2,a1.order_no <span class="keyword">as</span> orderNo2,a1.tran_amt <span class="keyword">as</span> tranAmt2,a1.fee_amt <span class="keyword">as</span> feeAmt2,a1.repayment_date_req <span class="keyword">as</span> repaymentDateReq2</span><br><span class="line"></span><br><span class="line"> ,a1.status <span class="keyword">as</span> status2,a1.create_time <span class="keyword">as</span> createTime2,a1.update_time <span class="keyword">as</span> updateTime2</span><br><span class="line"></span><br><span class="line"> <span class="keyword">from</span> (</span><br><span class="line"></span><br><span class="line"> <span class="keyword">select</span> tsa.id,tsa.order_no <span class="keyword">as</span> orderNo,tsa.repayment_date_req <span class="keyword">as</span> repaymentDateReq,tsa.status,tsa.fee_state <span class="keyword">as</span> feeState,tsa.repayment_flag <span class="keyword">as</span> repaymentFlag,</span><br><span class="line"></span><br><span class="line"> tsa.capital_return_flag <span class="keyword">as</span> capitalReturnFlag,tsa.tran_amt <span class="keyword">as</span> tranAmt,tsa.fee_amt <span class="keyword">as</span> feeAmt,tsa.capital_returned_amont <span class="keyword">as</span> capitalReturnedAmont,</span><br><span class="line"></span><br><span class="line"> tsa.wait_amt <span class="keyword">as</span> waitAmt,tsa.back_charge_amt <span class="keyword">as</span> backChargeAmt,tsa.create_time <span class="keyword">as</span> createTime,tui.real_name <span class="keyword">as</span> realName,tui.mobile_no <span class="keyword">as</span> mobileNo,</span><br><span class="line"></span><br><span class="line"> tc.bank_card_no <span class="keyword">as</span> bankCardNo,tmi.merchant_name <span class="keyword">as</span> merchantName,tui.mer_no <span class="keyword">as</span> merNo,tsa.reserved1 <span class="keyword">as</span> reserved1,tsa.parent_id <span class="keyword">as</span> parentId,tc.bank_name <span class="keyword">as</span> bankName,tc.holder_name <span class="keyword">as</span> holderName,</span><br><span class="line"></span><br><span class="line"> tc.certificate_no <span class="keyword">as</span> certificateNo</span><br><span class="line"></span><br><span class="line"> <span class="keyword">from</span> tbl_ser_apply <span class="keyword">as</span> tsa <span class="keyword">LEFT</span> <span class="keyword">JOIN</span> tbl_user_info <span class="keyword">as</span> tui <span class="keyword">on</span> tsa.userid<span class="operator">=</span>tui.id <span class="keyword">LEFT</span> <span class="keyword">JOIN</span> tbl_merchant_inf <span class="keyword">as</span> tmi <span class="keyword">on</span></span><br><span class="line"></span><br><span class="line"> tmi.merchant_no<span class="operator">=</span>tui.mer_no <span class="keyword">LEFT</span> <span class="keyword">JOIN</span> tbl_cusinfo tc <span class="keyword">on</span> tc.id<span class="operator">=</span>tsa.cusInf_id <span class="keyword">where</span> tsa.virtual_col <span class="keyword">like</span> <span class="string">'372191%'</span></span><br><span class="line"></span><br><span class="line"> <span class="keyword">ORDER</span> <span class="keyword">BY</span> tsa.create_time <span class="keyword">desc</span> ) a <span class="keyword">LEFT</span> <span class="keyword">JOIN</span> tbl_ser_apply a1 <span class="keyword">on</span> a.parentId<span class="operator">=</span>a1.id</span><br><span class="line"></span><br></pre></td></tr></tbody></table></figure><p>经过我的测试后,原来不走索引是20S 用上一个方法是0.049s 用第二个方法的话是0.1S 虽然慢了0.05S 那是计算数据的时间,但这样的方案已经大大缩短了模糊查询时间,而且不需要修改java代码,个人推荐使用第二种!</p><p>参考文章:<br><a href="https://www.jianshu.com/p/9f83eebc8606">参考链接1</a><br><a href="https://www.cnblogs.com/whyat/p/10512797.html">参考链接2</a></p>]]></content>
<summary type="html"><h3 id="sql语句写法"><a href="#sql语句写法" class="headerlink" title="sql语句写法"></a>sql语句写法</h3><p>一张表大概40万左右的数据,用<strong>like模糊查询title</strong>字段,很慢,title字段已经建立了索引,mysql 对 <code>someTitle%</code> 这样的模糊查询在有索引的前提下是很快的。<br>所以下面这两台sql语句差别就很大了<br>$sql1 = “… title like someTitle%” (0.001秒)</p>
<p>$sql2 = “…… title like %someTitle%” (0.8秒)</p></summary>
<category term="数据库" scheme="https://removeif.github.io/categories/%E6%95%B0%E6%8D%AE%E5%BA%93/"/>
<category term="mysql" scheme="https://removeif.github.io/categories/%E6%95%B0%E6%8D%AE%E5%BA%93/mysql/"/>
<category term="mysql" scheme="https://removeif.github.io/tags/mysql/"/>
<category term="like" scheme="https://removeif.github.io/tags/like/"/>
<category term="模糊查询" scheme="https://removeif.github.io/tags/%E6%A8%A1%E7%B3%8A%E6%9F%A5%E8%AF%A2/"/>
<category term="like优化" scheme="https://removeif.github.io/tags/like%E4%BC%98%E5%8C%96/"/>
</entry>
<entry>
<title>英语语法-基本语法</title>
<link href="https://removeif.github.io/english-learn/%E8%8B%B1%E8%AF%AD%E8%AF%AD%E6%B3%95-%E5%9F%BA%E6%9C%AC%E8%AF%AD%E6%B3%95.html"/>
<id>https://removeif.github.io/english-learn/%E8%8B%B1%E8%AF%AD%E8%AF%AD%E6%B3%95-%E5%9F%BA%E6%9C%AC%E8%AF%AD%E6%B3%95.html</id>
<published>2020-03-11T19:44:04.000Z</published>
<updated>2025-01-06T09:42:34.422Z</updated>
<content type="html"><![CDATA[<h4 id="五种句型"><a href="#五种句型" class="headerlink" title="五种句型"></a>五种句型</h4><p><strong>学习语法:分析句子=>理清句子成分=>理清句子关系</strong></p><p><strong>句子基本结构:主语部分+谓语部分(名词+动词)</strong></p><h5 id="五种句型:"><a href="#五种句型:" class="headerlink" title="五种句型:"></a>五种句型:</h5><ul><li><p>主 谓 表 I am a Webaholic <span id="more"></span></p></li><li><p>主 谓 Internet dating hurts</p></li><li><p>主 谓 宾 I like chatting online</p></li><li><p>主 谓 间宾 主宾 Chatting on the internet brings me a lot of fun</p></li><li><p>主 谓 宾 宾补 We can call Internet addicts a Webaholic</p><p> <strong>关键在于谓语动词:动词构成了一个句子的骨架</strong></p></li></ul><h5 id="1-主语-系动词-主语补足语(表语)"><a href="#1-主语-系动词-主语补足语(表语)" class="headerlink" title="1 主语+系动词+主语补足语(表语)"></a>1 主语+系动词+主语补足语(表语)</h5><p> <strong>系动词(Linking Verb)</strong></p><p> 作用:无具体动作,仅起连接作用; </p><p> 后面所接成分:说明主语特点性质特征</p><p> <strong>种类:be动词(am is are)</strong></p><p> look sound smell taste feel seem appear become turn</p><p> <strong>表语:名词 or 形容词</strong></p><h5 id="2-主语-谓语(-状语)"><a href="#2-主语-谓语(-状语)" class="headerlink" title="2 主语+谓语(+状语)"></a>2 主语+谓语(+状语)</h5><p> <strong>不及物动词(Intransitive Verb)vi</strong></p><p> 特点:主语自身可以完成,不需要作用对象</p><p> 习惯:带状语(修饰动作的成分)</p><h5 id="3-主语-谓语-宾语"><a href="#3-主语-谓语-宾语" class="headerlink" title="3 主语+谓语+宾语"></a>3 主语+谓语+宾语</h5><p> <strong>及物动词(Transitive Verb)vt</strong></p><p> 作用;:说明主语动作作用对象(宾语:主语动作承受对象)</p><h5 id="4-主语-谓语-间宾-直宾"><a href="#4-主语-谓语-间宾-直宾" class="headerlink" title="4 主语+谓语+间宾+直宾"></a>4 主语+谓语+间宾+直宾</h5><p> <strong>双宾动词(Dative Verb)</strong></p><p> 特点:后面成分有人(间接宾语[接受者])又有物(直接宾语[承受者])</p><h5 id="5-主语-谓语-宾语-宾语补足语"><a href="#5-主语-谓语-宾语-宾语补足语" class="headerlink" title="5 主语+谓语+宾语+宾语补足语"></a>5 主语+谓语+宾语+宾语补足语</h5><p> <strong>宾补动词(Factitive Verb)</strong></p><h5 id="6-区分双宾语和复合宾语"><a href="#6-区分双宾语和复合宾语" class="headerlink" title="6 区分双宾语和复合宾语"></a>6 区分双宾语和复合宾语</h5><p> <strong>在间接宾语后加上be动词,若能成句,则是补足语。</strong></p><table><thead><tr><th>动词种类</th><th>句型</th></tr></thead><tbody><tr><td>Linking verb</td><td>主+系+表</td></tr><tr><td>Intransitive Verb</td><td>主+谓</td></tr><tr><td>Transitive Verb</td><td>主+谓+宾</td></tr><tr><td>Transitive Verb with direct object and indirect object</td><td>主+谓+间宾+直宾</td></tr><tr><td>Transitive Verb with direct object and object complement</td><td>主+谓+宾+宾补</td></tr></tbody></table><h4 id="动词分类"><a href="#动词分类" class="headerlink" title="动词分类"></a>动词分类</h4><h5 id="1-实义动词(Notional-Verb)"><a href="#1-实义动词(Notional-Verb)" class="headerlink" title="1 实义动词(Notional Verb)"></a>1 实义动词(Notional Verb)</h5><p> <strong>特点:</strong></p><p> 词义:完整</p><p> 作用:能独立充当谓语</p><p> 分类:助动词和情态动词以外的动词</p><h5 id="2-助动词(Auxiliary-Verb)"><a href="#2-助动词(Auxiliary-Verb)" class="headerlink" title="2 助动词(Auxiliary Verb)"></a>2 助动词(Auxiliary Verb)</h5><p> <strong>特点:</strong></p><p> 词义:不完整</p><p> 作用:无法独立充当谓语</p><p> 必须和实义动词连用,构成各种时态、语态、语气、否定、疑问</p><p> <strong>分类:</strong></p><p> Be: am, is, are, was, were, been, being</p><p> Do: does, did</p><p> Have: has, had, having</p><table><thead><tr><th>助动词</th><th>变化形式</th><th>功能</th><th>例句</th></tr></thead><tbody><tr><td>Be</td><td>am, is, are, was, were, been, being</td><td>帮助构成进行时态</td><td>I am studying grammar.He is playing football.</td></tr><tr><td>帮助构成被动语态</td><td></td><td></td><td></td></tr><tr><td>I was cheated.</td><td></td><td></td><td></td></tr><tr><td>Do</td><td>Does, did</td><td>帮助实义动词构成否定</td><td>I do not like English.</td></tr><tr><td>帮助实义动词构成疑问</td><td>Do you like English?</td><td></td><td></td></tr><tr><td>Have</td><td>Has, had, having</td><td>帮助构成完成时态</td><td>I have studied English for 3 years</td></tr></tbody></table><p><strong>be do have可作实义动词又可作助动词</strong></p><table><thead><tr><th></th><th>例句</th><th>词义</th><th>词性及作用</th></tr></thead><tbody><tr><td>be</td><td>I am a student</td><td>“是”</td><td>系动词, 作谓语</td></tr><tr><td></td><td>I am studying grammar</td><td>无词义</td><td>助动词, 构成进行时</td></tr><tr><td>have</td><td>I have two brothers</td><td>“有”</td><td>实义动词, 作谓语</td></tr><tr><td></td><td>I have studied English for 3 years</td><td>无词义</td><td>助动词, 构成完成时</td></tr><tr><td>do</td><td>I often do my homework at home</td><td>“做”</td><td>实义动词, 作谓语</td></tr><tr><td></td><td>I do not like English</td><td>无词义</td><td>助动词, 构成否定</td></tr></tbody></table><h5 id="3-情态动词-Modal-Verb"><a href="#3-情态动词-Modal-Verb" class="headerlink" title="3 情态动词(Modal Verb)"></a>3 情态动词(Modal Verb)</h5><p> <strong>特点:</strong></p><p> 词义:有词义,表示可能、建议、愿望、必要、允许、能力、怀疑、表示说话者对某种行为或状态的看法或态度</p><p> 作用:无法独立充当谓语,必须和实义动词一起构成复合谓语</p><p> 常见: can/could may/might must shall/should will/would have to ought to used to need/dare</p><h4 id="句子的变化"><a href="#句子的变化" class="headerlink" title="句子的变化"></a>句子的变化</h4><h5 id="1-陈述句否定"><a href="#1-陈述句否定" class="headerlink" title="1 陈述句否定"></a>1 陈述句否定</h5><p> <strong>谓语动词含有助动词或情态动词</strong></p><p> <strong>变形:助动词或情态动词后 + not</strong></p><p> 例:He is a teacher. He is not a teacher.</p><p> I can swim. I cannot swim.</p><p> He will come to the party he will not come to the party</p><p> <strong>谓语动词是实义动词</strong></p><p> 变形:借助助动词do not来构成,第三人称用does + not + 动词原形,过去式did + not</p><p> 例:I like English. I do not like English.</p><p> He likes English.. He does not like English.</p><p> There are some dogs. There aren’t any dogs.</p><p> <strong>否定的缩写</strong></p><table><thead><tr><th>I am</th><th>Am not</th><th>Null</th></tr></thead><tbody><tr><td>We/You/They are</td><td>Are not</td><td>Aren’t</td></tr><tr><td>She/He/It is</td><td>Is not</td><td>Isn’t</td></tr><tr><td>I/He/She/It was</td><td>Was not</td><td>Wasn’t</td></tr><tr><td>We/You/They were</td><td>Were not</td><td>Weren’t</td></tr><tr><td>I/You/We/They do</td><td>Do not</td><td>Don’t</td></tr><tr><td>He/She/It does</td><td>Does not</td><td>Doesn’t</td></tr><tr><td>Did</td><td>Did not</td><td>Didn’t</td></tr><tr><td>I/You/We/They have</td><td>Have not</td><td>Haven’t</td></tr><tr><td>He/She/It has</td><td>Has not</td><td>Hasn’</td></tr><tr><td>Had</td><td>Had not</td><td>Hadn’t</td></tr><tr><td>情态动词</td><td></td><td></td></tr><tr><td>Will</td><td>Will not</td><td>Won’t</td></tr><tr><td>Would</td><td>Would not</td><td>Wouldn’t</td></tr><tr><td>Shall</td><td>Shall not</td><td>Shan’t</td></tr><tr><td>Should</td><td>Should not</td><td>Shouldn’t</td></tr><tr><td>Can</td><td>Cannot</td><td>Can’t</td></tr><tr><td>Could</td><td>Could not</td><td>Couldn’t</td></tr><tr><td>May</td><td>May not</td><td>Null</td></tr><tr><td>Might</td><td>Might not</td><td>Mightn’t</td></tr><tr><td>Must</td><td>Must not</td><td>Mustn’t</td></tr></tbody></table><p> 其他词变化:and->or already->yet both->either some->any</p><p> 祈使句: 祈使句前+don’t Don’t open the door.</p><p> 不定式: 不定式前+not She asks the boy not to play in the street.</p><h5 id="2-一般疑问句"><a href="#2-一般疑问句" class="headerlink" title="2 一般疑问句"></a>2 一般疑问句</h5><p> <strong>谓语动词含有助动词或情态动词</strong></p><p> 变形:助动词 or 情态动词移至句首</p><p> 例:He is a teacher. Is he a teacher? Yes, he is/No, he isn’t</p><p> <strong>谓语动词是实义动词</strong></p><p> 变形:加do does did于句首,实义动词变原形</p><p> 例:He likes English. Does he like English? Yes, he does/No, he doesn’t.</p><p> I like English. Do you like English? Yes, I do/No, I don’t.</p><h5 id="3-特殊疑问句"><a href="#3-特殊疑问句" class="headerlink" title="3 特殊疑问句"></a>3 特殊疑问句</h5><p> <strong>不接名词连用的疑问句</strong></p><p> <strong>对人提问:who</strong></p><p> He can sing in English. Who can sing in English.</p><p> I saw him at the party last night. Who did you see at the party last night?</p><p> <strong>对事或物:what</strong></p><p> I like English. What do you like?</p><p> I am studying English grammar. What are you doing?</p><p> I am studying English grammar. What are you studying?</p><p> I’d like to go swimming tomorrow. What would you like to do tomorrow?</p><p> <strong>对时间提问:when</strong></p><p> I was born in 1980. When were you born?</p><p> <strong>对地点提问:where</strong></p><p> He lives in Beijing. Where does he live?</p><p> <strong>对方式提问:how</strong></p><p> He goes to school by bus. How does he go to school?</p><p> <strong>对原因提问:why</strong></p><p> I often study at the library because it’s quiet. Why do you often study at the library?</p><p> <strong>接名词连用的疑问词</strong></p><p> <strong>Which:</strong></p><p> Could you lend me your pen?</p><p> Sure. I have two pens. This pen has black ink. That pen has red ink. </p><p> Which pen/Which one/Which do you want?</p><p> That red one. Thanks.</p><p> Which也可不接名词。这时which用作代词。</p><p> <strong>Whose:</strong></p><p> 必须接名词</p><p> This is his book. Whose book is this?</p><p> I borrowed Jack’s car last night. Whose car did you borrow last night?</p><p> <strong>How用法详解</strong></p><p> <strong>单独使用:对动作方式的提问</strong></p><p> How do you go to work?</p><p> I drive/ By car/I take a taxi/I take a bus/By bus.</p><p> How did he break his leg?</p><p> He fell off the ladder.</p><p> <strong>和形容词 or 副词连用</strong></p><p> How old are you?</p><p> How tall is he?</p><p> How big is your new house?</p><p> How far is it from your home to school?</p><p> How well does he speak English?</p><p> How quickly can you get here?</p><p><strong>对频率提问:how often/how many times?</strong></p><p> I write to my parents once a month. How often do you write to your parents?</p><p> I go shopping twice a week. How often do you go shopping?/How many times a week do you go shopping?</p><p><strong>其他频率短语</strong></p><p> Every</p><p> Once a —> day/week/month/year</p><p> Twice a </p><p> Three times </p><h4 id="一般时态和现在时态"><a href="#一般时态和现在时态" class="headerlink" title="一般时态和现在时态"></a>一般时态和现在时态</h4><p><strong>The present simple tense</strong></p><p>is used to express a general truth or fact, or an action that occurs regularly or habitually. Generally, the present simple tense verb conveys a sense of permanence.</p><p>Truth or fact</p><p> The sun rises in the east and sets in the west.</p><p> The earth moves around the sun.</p><p>An action that occurs regularly or habitually</p><p> I often spend two hours reading English in the morning.</p><p> Classes begin at nine in the morning</p><p><strong>1.事实</strong></p><p> The world is round.</p><p><strong>2.经常性,习惯性动作或状态</strong></p><p> He doesn’t work hard.</p><p> (1)常连用频率副词(助动词后,实义动词前)</p><p> always frequently usually sometimes generally occasionally often</p><p> never seldom rarely</p><p><strong>3.以there或here开头句子中,表正在发生的短暂动作</strong></p><p> Here comes your wife= your wife is coming.</p><p> There goes our bus; we’ll have to wait for the next one.</p><p><strong>4.条件状语(if unless),时间状语(when as soon as before after )从句中,表示将来动作</strong></p><p> Please let me know when he comes back.</p><p> What are you going to do when you leave school?</p><p> I’ll be glad if she comes over to visit me.</p><p><strong>The past simple tense</strong></p><p> is used to express a completed action which took place eat a specified time in the past.</p><p> The specified time is either stated or implied.</p><p>A completed action</p><p> I saw him in the library yesterday morning.</p><p> I began to learn English ten years ago.</p><p>A past action that occurred regularly or habitually</p><p> I slept for eight hours last night.</p><p> She lived in our town for three years,but now she is living in Beijing.</p><p><strong>1.过去动作或状态</strong></p><p> He was late for school this morning.</p><p> I bought this computer three years ago.</p><p><strong>2.过去一段时间一直持续或反复发生的动作</strong></p><p> I lived in the country for ten years.</p><p> He used to do morning exercises.</p><p> He took a walk after supper when he was alive.</p><p>The future simple tense</p><p> is used to express an action that will occur at some time in the future.</p><p>Will or Be Going To can be used to express sort of certainty.</p><p> According to the weather report, it will be windy tomorrow.说话人认为将要发生</p><p> According to the weather report, it is going to be windy tomorrow.根据明显迹象判断</p><p>Be Going To is used to express a definite plan.</p><p> I have bought a computer and I’m going to learn the computer science.</p><p>Will is used to express a willingness.</p><p> The telephone is ringing; I will answer it.</p><p><strong>Will(说话时做出的决定)</strong></p><p><strong>Be Going To(对话前做出的决定)</strong></p><h4 id="进行时态"><a href="#进行时态" class="headerlink" title="进行时态"></a>进行时态</h4><p><strong>时态构成</strong></p><p> 助动词+进行分词 be+doing</p><p><strong>意义</strong></p><p> 该时刻(具体时间,另一个具体活动背景下),活动正在进行</p><p><strong>现在进行时</strong></p><h5 id="1-说话此刻正在进行"><a href="#1-说话此刻正在进行" class="headerlink" title="1.说话此刻正在进行"></a>1.说话此刻正在进行</h5><p> What program are you watching?</p><p> He is not available now. He is talking on another phone.</p><h5 id="2-现阶段正在持续的动作"><a href="#2-现阶段正在持续的动作" class="headerlink" title="2.现阶段正在持续的动作"></a>2.现阶段正在持续的动作</h5><p> what are you doing these days?</p><p> I am learning the usage of verb tenses.</p><h5 id="3-最近的将来已定的安排-计划-安排做"><a href="#3-最近的将来已定的安排-计划-安排做" class="headerlink" title="3.最近的将来已定的安排(计划 安排做)"></a>3.最近的将来已定的安排(计划 安排做)</h5><p> What are you doing on Saturday night?</p><p> I’m doing some shopping with Jane. I am taking a makeup test tomorrow.</p><h5 id="4-与always-forever-continually-constantly等连用,表示抱怨,厌烦"><a href="#4-与always-forever-continually-constantly等连用,表示抱怨,厌烦" class="headerlink" title="4.与always forever continually constantly等连用,表示抱怨,厌烦"></a>4.与always forever continually constantly等连用,表示抱怨,厌烦</h5><p> Jack is always borrowing money and forgetting to pay you back.</p><p> He’s continually asking me for money.</p><h4 id="过去进行时"><a href="#过去进行时" class="headerlink" title="过去进行时"></a>过去进行时</h4><h5 id="1-过去特定时刻发生的事情"><a href="#1-过去特定时刻发生的事情" class="headerlink" title="1.过去特定时刻发生的事情"></a>1.过去特定时刻发生的事情</h5><p> I was discussing my thesis with my director at this time last night.</p><p> What were you doing at 10 o’clock last night? I was having dinner with my friends </p><h5 id="2-过去进行时-背景-一般过去时-背景下发生的短暂动作或状态"><a href="#2-过去进行时-背景-一般过去时-背景下发生的短暂动作或状态" class="headerlink" title="2.过去进行时(背景)+一般过去时(背景下发生的短暂动作或状态)"></a>2.过去进行时(背景)+一般过去时(背景下发生的短暂动作或状态)</h5><p> The phone rang while I was having my bath, as usual.</p><p> I was watching TV when the phone rang. </p><h4 id="将来进行时-will-be-doing"><a href="#将来进行时-will-be-doing" class="headerlink" title="将来进行时(will be doing)"></a>将来进行时(will be doing)</h4><h5 id="1-将来某特定时刻活动正在进行"><a href="#1-将来某特定时刻活动正在进行" class="headerlink" title="1.将来某特定时刻活动正在进行"></a>1.将来某特定时刻活动正在进行</h5><p> I’ll be lying on a beach in Sanya this time tomorrow.</p><p> Don’t telephone after eight tomorrow. I’ll be having a meeting.</p><h4 id="名词"><a href="#名词" class="headerlink" title="名词"></a>名词</h4><p><strong>名词短语(名词与它前面的修饰语)</strong></p><p> These red roses are for you.</p><p> I have three close friends.</p><p> I really need a new computer.</p><p> <strong>1.功能</strong></p><p> 主语 宾语(介词不能单独使用,后面所接宾语) 表语</p><p> <strong>2.修饰语</strong></p><p> 限定词: 泛指,特指,定量,不定量(these three a the my that),冠 词(a an the)</p><p> 形容词: red close new best small </p><p> <strong>3.位置</strong></p><p> 限定词在形容词前: 限定词+形容词+名词: three red roses.</p><h4 id="名词可数与不可数"><a href="#名词可数与不可数" class="headerlink" title="名词可数与不可数"></a>名词可数与不可数</h4><p><strong>名词分类</strong></p><p> 专有名词 Paris, the United States, Bill Gates</p><h5 id="普通名词"><a href="#普通名词" class="headerlink" title="普通名词"></a>普通名词</h5><p> <strong>可数名词</strong></p><p> 个体名词 student tree hospital house piano</p><p> 集体名词 team committee police group family</p><p> <strong>不可数名词</strong> </p><p> 物质名词 paper water cotton air</p><p> 抽象名词 birth happiness evolution technology hope</p><p> 简单名词 story student teacher</p><p> 复合名词 girlfriend roommate mother-in-law</p><h5 id="相对性"><a href="#相对性" class="headerlink" title="相对性"></a>相对性</h5><p> <strong>paper</strong></p><p> I need some paper to write a letter(纸 不可数)</p><p> I have a term paper to write on weekends(论文 可数)</p><p> I bought a paper(报纸 可数)</p><p> room(空间 不可数; 房间 可数)</p><h5 id="可数名词与不可数名词比较"><a href="#可数名词与不可数名词比较" class="headerlink" title="可数名词与不可数名词比较"></a>可数名词与不可数名词比较</h5><p> <strong>可数名词:</strong> 前面可以+ a or an or 数词(two)</p><p> <strong>不可数名词:</strong> 不可+</p><h5 id="变形及读音"><a href="#变形及读音" class="headerlink" title="变形及读音"></a>变形及读音</h5><p> <strong>1.末尾+s(清辅音s 浊辅音z)</strong></p><p> <strong>2.-s -x -ch -sh结尾+es读[iz] 若ch发音为[k]时+s (stomach/stomachs)</strong></p><p> <strong>3.辅音字母+y: 变y->ies 读[iz]; 元音字母+y: 直接+s 读[z]</strong></p><p> <strong>4.特殊变化</strong></p><p> <strong>1)o结尾 读[z]</strong></p><p> potato/potatoes tomato/tomatoes hero/heroes piano/pianos photo/photos radio/radios</p><p> <strong>2)f或fe结尾 f, fe->ves 读[s] or 直接+读[s]</strong></p><p> half/halves knife/knives leaf/leaves life/lives</p><p> belief/beliefs chief/chiefs cliff/cliffs proof/proofs roof/roofs</p><p> <strong>3)单复数同形</strong></p><p> aircraft deer giraffe sheep </p><p> <strong>4)man/woman 构成的复合名词(都变)</strong></p><p> man teacher/men teachers woman pilot/women pilots</p><p> <strong>5)名词+介词或介词短语构成的复合名词(名词变)</strong></p><p> passer-by/passers-by looker-on/lookers-on</p><h4 id="不可数名词"><a href="#不可数名词" class="headerlink" title="不可数名词"></a>不可数名词</h4><h5 id="1-物质名词不可数"><a href="#1-物质名词不可数" class="headerlink" title="1.物质名词不可数"></a>1.物质名词不可数</h5><p> beer blood coffee cream gasoline honey juice milk oil tea water wine</p><p> bread butter cheese ice ice-cream meat beef chicken fish chalk copper cotton glass gold iron</p><p> air fog oxygen smoke</p><h5 id="2-抽象名词"><a href="#2-抽象名词" class="headerlink" title="2.抽象名词"></a>2.抽象名词</h5><p> advice anger beauty confidence fun happiness health honesty informaation love luch peace</p><h5 id="3-总称名词不可数"><a href="#3-总称名词不可数" class="headerlink" title="3.总称名词不可数"></a>3.总称名词不可数</h5><p> furniture fruit jewelry luggage equipment poetry machinery</p><h5 id="不可数名词的度量"><a href="#不可数名词的度量" class="headerlink" title="不可数名词的度量"></a>不可数名词的度量</h5><p> <strong>1.piece</strong></p><p> advice bread baggage chalk equipment furniture information jewelry luggage music news</p><p> <strong>2.bottle cup drop glass</strong></p><p> beer blood coffee milk tea water wine </p><p> <strong>3.else</strong></p><p> a loaf of bread a tube of toothpaste a pack of cigarette a slice of meat</p><h4 id="名词所有格"><a href="#名词所有格" class="headerlink" title="名词所有格"></a>名词所有格</h4><p> <strong>1.单数名词后+’s</strong></p><p> <strong>2.复数名词后+s’ ;复数型名词后+’s</strong></p><p> her friends’ money</p><p> the children’s Day</p><p> <strong>3.复合名词后+’s</strong></p><p> my father-in-law’ s company</p><p> everyone else’ s viewpoints</p><p> Henry the Eighth’ s wives</p><p> the President of America’ s secretary</p><p> <strong>4.and连接的并列名词: 共有情况: 最后+’s ; 各自所有情况: 每个名词后+’s</strong></p><p> <strong>5.重量 度量 价值</strong></p><p> two pounds’ weight a ton’s weight a ton’ s steel two dollars’ worth of sugar</p><p> <strong>6.省略</strong></p><p> <strong>1)前文以出现,避免重复</strong></p><p> This bike is mine, not Michael’s</p><p> <strong>2)表示店铺或教堂(要加the)</strong></p><p> at the baker’s at the butcher’s at the chemist’s at the doctor’s</p><p> <strong>3)人名后的所有格省去名词表示住宅</strong></p><p> go to my sister’s I called at my uncle’s yesterday.</p><p> <strong>7.of所有格的其他关系</strong></p><p> <strong>1)主谓关系</strong></p><p> the visitor’s departure the teacher’s request the growth of agriculture</p><p> <strong>2)动宾关系</strong></p><p> the children’s education the boy’s punishment the discussion of the plan</p><p>英语学习-<a href="https://github.com/removeif/english-learn">语法系列github仓库</a>,欢迎收藏star </p><p>参考文章:<br><a href="https://github.com/yizutianya/English_Grammar_Learning">参考链接</a></p>]]></content>
<summary type="html"><h4 id="五种句型"><a href="#五种句型" class="headerlink" title="五种句型"></a>五种句型</h4><p><strong>学习语法:分析句子=&gt;理清句子成分=&gt;理清句子关系</strong></p>
<p><strong>句子基本结构:主语部分+谓语部分(名词+动词)</strong></p>
<h5 id="五种句型:"><a href="#五种句型:" class="headerlink" title="五种句型:"></a>五种句型:</h5><ul>
<li><p>主 谓 表 I am a Webaholic</p></li></ul></summary>
<category term="English" scheme="https://removeif.github.io/categories/English/"/>
<category term="grammar" scheme="https://removeif.github.io/categories/English/grammar/"/>
<category term="English" scheme="https://removeif.github.io/tags/English/"/>
<category term="grammar" scheme="https://removeif.github.io/tags/grammar/"/>
</entry>
<entry>
<title>英语语法-句子类型</title>
<link href="https://removeif.github.io/english-learn/%E8%8B%B1%E8%AF%AD%E8%AF%AD%E6%B3%95-%E5%8F%A5%E5%AD%90%E7%B1%BB%E5%9E%8B.html"/>
<id>https://removeif.github.io/english-learn/%E8%8B%B1%E8%AF%AD%E8%AF%AD%E6%B3%95-%E5%8F%A5%E5%AD%90%E7%B1%BB%E5%9E%8B.html</id>
<published>2020-03-11T19:43:10.000Z</published>
<updated>2025-01-06T09:42:34.422Z</updated>
<content type="html"><![CDATA[<h4 id="特殊疑问句:疑问词-一般疑问句"><a href="#特殊疑问句:疑问词-一般疑问句" class="headerlink" title="特殊疑问句:疑问词+一般疑问句"></a>特殊疑问句:疑问词+一般疑问句</h4><p> What time i convenient for you</p><p> How late are you open</p><p> Where were we</p><p> What was I just going to say<span id="more"></span></p><p> What’s in your mind</p><p> What’s going on</p><p> When did you begin to study English</p><h4 id="一般疑问句:助动词-主语-谓语(yes-or-no-回答)"><a href="#一般疑问句:助动词-主语-谓语(yes-or-no-回答)" class="headerlink" title="一般疑问句:助动词+主语+谓语(yes or no 回答)"></a>一般疑问句:助动词+主语+谓语(yes or no 回答)</h4><h4 id="选择疑问句:提供两种或两种以上情形提对方选择"><a href="#选择疑问句:提供两种或两种以上情形提对方选择" class="headerlink" title="选择疑问句:提供两种或两种以上情形提对方选择"></a>选择疑问句:提供两种或两种以上情形提对方选择</h4><p> Do you like tea or coffee</p><p> Did you speak to them, or did the manager</p><p> Which ice cream would you like, chocolate, vanilla or strawberry.</p><h4 id="反意疑问句:"><a href="#反意疑问句:" class="headerlink" title="反意疑问句:"></a>反意疑问句:</h4><p> I am going to look like a lemon, aren’t I?</p><p> You have completed that job,haven’t you?</p><p> You have not completed that job, have you?</p><h4 id="祈使句:表示请求,命令,劝告,建议等"><a href="#祈使句:表示请求,命令,劝告,建议等" class="headerlink" title="祈使句:表示请求,命令,劝告,建议等"></a>祈使句:表示请求,命令,劝告,建议等</h4><p> <strong>主语you省略</strong></p><p> <strong>动词原型,没有时态,不用情态动词</strong></p><p> Stop bugging me</p><p> Don’t judge a book by its cover</p><p> Don’t get me wrong</p><p> Let’s just have a rest</p><p> Let’s hope for the best</p><p> Let’s talk over dinner</p><p> Let bygones be bygones</p><p> Strike while the iron is hot</p><p> Make hay while the sun shines</p><h4 id="感叹句:what"><a href="#感叹句:what" class="headerlink" title="感叹句:what"></a>感叹句:what</h4><h5 id="1-what-a-n-形容词-可数名词单数-谓语部分"><a href="#1-what-a-n-形容词-可数名词单数-谓语部分" class="headerlink" title="1.what + a(n) + 形容词 + 可数名词单数 + 谓语部分"></a>1.what + a(n) + 形容词 + 可数名词单数 + 谓语部分</h5><p> what a lovely boy he is.</p><h5 id="2-what-形容词-不可数名词或可数名词复数-谓语部分"><a href="#2-what-形容词-不可数名词或可数名词复数-谓语部分" class="headerlink" title="2.what + 形容词 +不可数名词或可数名词复数 + 谓语部分"></a>2.what + 形容词 +不可数名词或可数名词复数 + 谓语部分</h5><p> what foolish mistakes you have made</p><p> what nice weather(it is)</p><h5 id="3-what-a-n-可数名词单数:是"><a href="#3-what-a-n-可数名词单数:是" class="headerlink" title="3.what + a(n) +可数名词单数:是"></a>3.what + a(n) +可数名词单数:是</h5><p> <strong>没有感情色彩的普通名词时: 有两种理解</strong></p><p> what a day: 可以是今天天气多好,也可以是天气很糟糕</p><p> <strong>有感情色彩的名词</strong></p><p> what a mess</p><h4 id="感叹句:-how"><a href="#感叹句:-how" class="headerlink" title="感叹句: how"></a>感叹句: how</h4><h5 id="1-how-形容词-or-副词-谓语部分"><a href="#1-how-形容词-or-副词-谓语部分" class="headerlink" title="1.how + 形容词 or 副词 + 谓语部分"></a>1.how + 形容词 or 副词 + 谓语部分</h5><p> How lovely the boy is</p><p> How fast time flies</p><h5 id="2-How-主谓部分"><a href="#2-How-主谓部分" class="headerlink" title="2.How + 主谓部分"></a>2.How + 主谓部分</h5><p> How he ssnores!</p><p> How I hate exams!</p><h5 id="3-How-形容词-a-n-可数名词单数-主谓部分"><a href="#3-How-形容词-a-n-可数名词单数-主谓部分" class="headerlink" title="3.How + 形容词 + a(n) +可数名词单数 + 主谓部分"></a>3.How + 形容词 + a(n) +可数名词单数 + 主谓部分</h5><p> How lovely a boy he is.</p><p>英语学习-<a href="https://github.com/removeif/english-learn">语法系列github仓库</a>,欢迎收藏star </p><p>参考文章:<br><a href="https://github.com/yizutianya/English_Grammar_Learning">参考链接</a></p>]]></content>
<summary type="html"><h4 id="特殊疑问句:疑问词-一般疑问句"><a href="#特殊疑问句:疑问词-一般疑问句" class="headerlink" title="特殊疑问句:疑问词+一般疑问句"></a>特殊疑问句:疑问词+一般疑问句</h4><p> What time i convenient for you</p>
<p> How late are you open</p>
<p> Where were we</p>
<p> What was I just going to say</p></summary>
<category term="English" scheme="https://removeif.github.io/categories/English/"/>
<category term="grammar" scheme="https://removeif.github.io/categories/English/grammar/"/>
<category term="English" scheme="https://removeif.github.io/tags/English/"/>
<category term="grammar" scheme="https://removeif.github.io/tags/grammar/"/>
</entry>
<entry>
<title>英语语法-状语从句</title>
<link href="https://removeif.github.io/english-learn/%E8%8B%B1%E8%AF%AD%E8%AF%AD%E6%B3%95-%E7%8A%B6%E8%AF%AD%E4%BB%8E%E5%8F%A5.html"/>
<id>https://removeif.github.io/english-learn/%E8%8B%B1%E8%AF%AD%E8%AF%AD%E6%B3%95-%E7%8A%B6%E8%AF%AD%E4%BB%8E%E5%8F%A5.html</id>
<published>2020-03-11T19:27:54.000Z</published>
<updated>2025-01-06T09:42:34.422Z</updated>
<content type="html"><![CDATA[<p><strong>本质:</strong>连接词(关键)表达分句之间逻辑关系</p><p><strong>种类:</strong>时间,地点,原因,目的,结果,条件,让步,比较,方式</p><p><strong>时间状语:</strong>说明两个从句的时间</p><p><strong>when:</strong>调节两个时间点【起始点&结束点(完成时)】来说明主从句发生顺序 <span id="more"></span></p><h5 id="三要点:"><a href="#三要点:" class="headerlink" title="三要点:"></a><strong>三要点:</strong></h5><ul><li><p>同 时 态:从句先发生</p></li><li><p>有完成时:强调已完成的时间点</p></li><li><p>从 句 中:现在表将来</p></li></ul><table><thead><tr><th>(主句/从句)时态</th><th>例句</th></tr></thead><tbody><tr><td>将来/现在</td><td>I’ll speak to him when he arrives.</td></tr><tr><td>将来/现在完成</td><td>I’ll give you a call when I have finished the work.</td></tr><tr><td>过去/过去</td><td>I started my dinner when he left.</td></tr><tr><td>过去/过去完成</td><td>He left when I had got there.</td></tr><tr><td>过去完成/过去</td><td>I had started my dinner when he left.</td></tr></tbody></table><p><strong>whenever:强调无论何时(每次)</strong></p><p>Smile whenever you pick up the phone, for the caller will be able to notice it.</p><p><strong>while + 延续动词:从句发生期间发生</strong></p><p>The doorbell rang while we were watching TV.</p><p><strong>until:主句持续到从句的时间点保持同一状态</strong></p><p><strong>肯定形式:持续发生状态</strong></p><p>We’ll stay here till it stops raining.</p><p><strong>否定形式:持续未发生状态</strong></p><p>I did not realize I would need English in the future until I came to Japan.</p><h5 id="三种特殊结构"><a href="#三种特殊结构" class="headerlink" title="三种特殊结构"></a>三种特殊结构</h5><table><thead><tr><th>until句首</th><th>Until he saw his mother, the little boy didn’t smile.</th></tr></thead><tbody><tr><td>主句倒装</td><td>Not until he saw his mother did the little boy smile.</td></tr><tr><td>强调</td><td>It was not until he saw his mother that the little boy smiled.</td></tr></tbody></table><p><strong>一…就:</strong>as soon as, once, the minute, the moment, the instant, immediately, directly, instantly.</p><p><strong>说明:强调主从句说明的两个时间点同时发生;时态一般一致</strong></p><p>It began to rain as soon as/immediately/the moment I arrived home.</p><p><strong>特殊:倒装比较方式,主句动作刚结束(过去完成),从句动作就开始(过去)</strong></p><ol><li>No sooner had I arrived home than it began to rain.</li></ol><p> 2. Hardly/Scarcely had I arrived home when it began to rain.</p><p> 3. No sooner had we begun having dinner than the doorbell rang.</p><p><strong>时间短语引导:</strong></p><p>next time, by the time, every time, each time, the day, the week.</p><p>a. The day he returned, his father was already dead.</p><p> b. Next time you come, remember to bring along your sister.</p><p> c. Every time I listen to your advice, I get into trouble.</p><p><strong>在…之前:by the time</strong></p><p><strong>强调:主句动作(完成时)在从句动作之前已经完成</strong></p><p>a. By the time they arrived, we had already left.</p><p> b. By the time they arrive, we will have already left. </p><h5 id="地点状语"><a href="#地点状语" class="headerlink" title="地点状语"></a>地点状语</h5><p><strong>主句后边:一般</strong></p><p>Generally, air will be heavily polluted where there are factories.</p><p><strong>主句前边:需要灵活翻译</strong></p><p>wherever there is love, there is also wealth and success.</p><p><strong>wherever, anywhere, everywhere引导</strong></p><p>wherever I happens to be, I can make myself at home.</p><h5 id="原因状语"><a href="#原因状语" class="headerlink" title="原因状语"></a>原因状语</h5><p><strong>Because</strong></p><p><strong>语气最强,只有它能回答why问句。听话人未知原因</strong></p><p>You want to know why I am leaving?</p><p> I am leaving because I’m fed up with the job and boss.</p><p><strong>强调词:only,just</strong></p><p> You shouldn’t get angry just because some people speak ill of you.</p><p><strong>Since:已知道的原因,既然</strong></p><p>Since Monday is Bob’s birthday, let’s throw him a party.</p><p><strong>As:和since差不多</strong></p><p>She didn’t hear us come in as she was asleep.</p><p><strong>For:推断理由</strong></p><p>Pay attention to your enemies, for they are the first to discover your mistakes.</p><p><strong>介词短语表原因:because of,due to(非句首),owing to(句首):只接名词</strong></p><p>Owing to his carelessness we had an accident.</p><p><strong>because否定转移:从句的否定转移到主句</strong></p><p>I didn’t attend the meeting because he was present.</p><p><strong>复合连词表原因:seeing (that),now (that),considering (that),given (that) = since</strong></p><p>Now that the semester is finished, I’m going to rest a few days and then take a trip.</p><p><strong>In that:原因就在于</strong></p><p>The girl is like her mother in that she also has very delicate feeling.</p><h5 id="目的状语"><a href="#目的状语" class="headerlink" title="目的状语"></a>目的状语</h5><p><strong>常用连词:so that,in order that,that;从句:有表能力的情态动词</strong></p><p>I spoke slowly and clearly so that/ in order that the audience could understand me.</p><p><strong>不定式简化</strong></p><p><strong>In order for sb to do sth</strong></p><p>I spoke slowly and clearly in order for the audience to understand me.</p><p><strong>In order to(可句首)/so as to do:主从句主语一致</strong></p><p>All the key words in the article are printed in bold type so as to attract attention.</p><p><strong>以免连词:lest,for fear (that),in case:以免,生怕</strong></p><p>Take an umbrella with you lest it would rain.</p><p><strong>其他连词:in the hope that,on purpose that,for the pupose that,to the end that</strong></p><p>The teacher raised his voice on purpose that the students could hear more clearly.</p><h5 id="结果状语"><a href="#结果状语" class="headerlink" title="结果状语"></a>结果状语</h5><p><strong>常用连词:so…that,such…that,such that(such = so+adj.)</strong></p><p>His anger was so explosive that he lost control of himself.</p><p><strong>主句倒装</strong></p><p>a. So fast does light travel that it is difficult for us to imagine its speed.</p><p> b. Such a fool was he that he believed him.</p><p><strong>不定式简化</strong></p><p><strong>such…as to do sth,such as to do sth,so…as to do sth (as不能省略)</strong></p><p>Her voice was such as to make everyone stare.</p><p><strong>其他短语:to the degree/extent (that),to such a degree/extent (that)(句首时倒装)</strong></p><p>a. To such an extent did his health deteriorate that he was forced to retire.</p><p> b. The bereaved mother was grieved to the deggree that she couldn’t eat for 3 days.</p><p><strong>so和such区别</strong></p><p><strong>1.a. so + 形容词 or 副词 b. such + 名词</strong> </p><p>a. This is so expensive a house that I can’t afford to buy it.</p><p> b. This is such an expensive house that I can’t afford to buy it.</p><p><strong>2. a. so + 形容词 + a(n) + 名词 b. so + many/much/few/little + 名词</strong> </p><p>a. This is so expensive a house that I can’t afford to buy it.</p><p><strong>3. 数量词/限定词 + such + 名词</strong></p><p>one such man; no such man; every such man; five hundred such men </p><h5 id="让步状语"><a href="#让步状语" class="headerlink" title="让步状语"></a>让步状语</h5><p><strong>常用连词:though, although, even though, even if. (主句前不用but,可用yet/still)</strong></p><p>Though he tried hard, yet he failed.</p><p><strong>介词让步:despite, in spite of, for all, notwithstanding后只接名词(短语)</strong></p><p>Although it was dangerous, … = Despite the danger, …</p><p><strong>句首while:表示尽管</strong></p><p>While I sympathize with your point of view, I can not accept it.</p><p><strong>No matter 特殊疑问词 = 特殊疑问词 + ever</strong></p><p>Whoever may trouble you, I will help you to the last.</p><p><strong>as倒装:(adj/ adv/ 分词/ 名词/ 短语) + as + 主语 + 谓语</strong></p><p>a. Young as he is, he is knowledgeable.</p><p> b. Much as I respect him, I can not agree with him.</p><p> c. Child as he is, he is knowledgeable.</p><p> d. Lazy a boy as he is, he is kind to help others.</p><p> f. Praised as he was, he remained modest.</p><p><strong>(as/so) + 形容词 + as + 主谓,放在句首</strong></p><p>As amusing and perceptive as graffiti may sometimes be, it has by no means won universal approval.</p><p><strong>be倒装</strong></p><p>Be it ever so humble, there is no place like home.</p><p> = However humble it may be, there is no place like home. </p><h5 id="比较状语"><a href="#比较状语" class="headerlink" title="比较状语"></a>比较状语</h5><p><strong>as</strong></p><p><strong>结构1: as 形容词/副词 + as</strong></p><p>The work is not as difficult as you think.</p><p><strong>结构2: as + 形容词 +a(n) + 可数名词 + as</strong></p><p>Americans tend to think from small to large. Let us take as simple an example as the addressing of envelopes.</p><p><strong>结构3: 否定句中so代替as</strong></p><p>He is not so/as clever as you.</p><p><strong>than: 必须同类比较,必有比较级</strong></p><p>He is taller than me.</p><p><strong>三种倍数</strong></p><p>a. A is … times bigger than B.</p><p>b. A is … times as big as B.</p><p>c. A is … times the size of B.</p><p><strong>The more … , the more: 先翻译从句,后翻译主句</strong></p><p>a. The more she practiced, the worse she sang.</p><p> b. The less you open your heart to others, the more your heart suffers.</p><p> c. The nearer it is drawn to the surface of the earth, the more a body weighs. </p><p><strong>(just)as … , so …:类比</strong></p><p>a. Just as dark clouds cannot long hide the sun, so no lies can cover up the fact.</p><p> b. As it is the mark of great minds to say many things in a few words, so it is the mark of little minds to use many words to say nothing.</p><p><strong>A is to B (what/as) C is to D</strong></p><p>Air is to man what/as water is to fish = What/As water is to fish, so is air to man.</p><p><strong>No more … than或not … any more than:同 … 一样不能(than后面肯定式,否定意思)</strong></p><p>You are no more clever than he. = You are as stupid as he.</p><p><strong>Not more … than …:平起平坐</strong></p><p>You are not more clever than he = You both are clever, not stupid.</p><p><strong>Not A so much as B/ not so much A as B:</strong></p><p>1. 与其说A,不如说B(A,B是平行结构[同介词短语,动词不定时])</p><p>a. The great use of a school education is not so much to teach you things as to teach you the art of learning.</p><p> b. The trumpet player was certainly loud, but I was not bothered by this loudness so much as by his lack of talent.</p><h5 id="方式状语"><a href="#方式状语" class="headerlink" title="方式状语"></a>方式状语</h5><p><strong>常用连词:as, like, as if, as though, the way</strong></p><p> a. When in Rome, do as the Romans do.</p><p> b. Work like you don’t need money, love like you’ve never been hurt, dance like nobody’s watching.</p><p> c. Do it the way you were taught.</p><p> d. He looks (as though/as if) he is an actor.</p><p> e. Do as I say, not as I do.</p><p>英语学习-<a href="https://github.com/removeif/english-learn">语法系列github仓库</a>,欢迎收藏star </p><p>参考文章:<br><a href="https://github.com/yizutianya/English_Grammar_Learning">参考链接</a> </p>]]></content>
<summary type="html"><p><strong>本质:</strong>连接词(关键)表达分句之间逻辑关系</p>
<p><strong>种类:</strong>时间,地点,原因,目的,结果,条件,让步,比较,方式</p>
<p><strong>时间状语:</strong>说明两个从句的时间</p>
<p><strong>when:</strong>调节两个时间点【起始点&amp;结束点(完成时)】来说明主从句发生顺序</p></summary>
<category term="English" scheme="https://removeif.github.io/categories/English/"/>
<category term="grammar" scheme="https://removeif.github.io/categories/English/grammar/"/>
<category term="English" scheme="https://removeif.github.io/tags/English/"/>
<category term="grammar" scheme="https://removeif.github.io/tags/grammar/"/>
</entry>
<entry>
<title>英语语法-形容词adjective</title>
<link href="https://removeif.github.io/english-learn/%E8%8B%B1%E8%AF%AD%E8%AF%AD%E6%B3%95-%E5%BD%A2%E5%AE%B9%E8%AF%8Dadjective.html"/>
<id>https://removeif.github.io/english-learn/%E8%8B%B1%E8%AF%AD%E8%AF%AD%E6%B3%95-%E5%BD%A2%E5%AE%B9%E8%AF%8Dadjective.html</id>
<published>2020-03-11T19:27:40.000Z</published>
<updated>2025-01-06T09:42:34.422Z</updated>
<content type="html"><![CDATA[<h4 id="两种形容词的区别"><a href="#两种形容词的区别" class="headerlink" title="两种形容词的区别"></a>两种形容词的区别</h4><p> <strong>ing:</strong>描述引起人某种感觉的事物(主语通常是事物)</p><p> <strong>ed:</strong>描述人对事物的感觉(主语通常是人)</p><p> The interesting children can make other people feel interested in them.<span id="more"></span></p><h4 id="位置"><a href="#位置" class="headerlink" title="位置"></a>位置</h4><p> <strong>1.限定词+形容词+名词</strong></p><p> I am reading an interesting book.</p><p> <strong>2.不定代词+形容词</strong></p><p> There is something(某事) wrong with my computer.</p><h4 id="形容词顺序"><a href="#形容词顺序" class="headerlink" title="形容词顺序"></a>形容词顺序</h4><p> <strong>观点形容词(opinion adjective)+描绘形容词(descriptive adjective)</strong></p><p> a beautiful white table</p><p> <strong>描绘形容词顺序</strong></p><p> size->shape->age->color->origin->material</p><p> This beautiful big round old red chinese wooden table was mine.</p><h4 id="比较级和最高级"><a href="#比较级和最高级" class="headerlink" title="比较级和最高级"></a>比较级和最高级</h4><h5 id="单音节:-er-est"><a href="#单音节:-er-est" class="headerlink" title="单音节:-er -est"></a>单音节:-er -est</h5><p> <strong>-e结尾:</strong>-r -st</p><p> large->larger brave->braver</p><p> <strong>-y结尾:</strong>变y->i 加-er -est</p><p> shy->shier</p><p> <strong>元音+辅音:双写最后字母后加-er -est</strong></p><p> fat->fatter big->bigger sad->sadder</p><h5 id="双音节:前面-more-most"><a href="#双音节:前面-more-most" class="headerlink" title="双音节:前面+more most"></a>双音节:前面+more most</h5><p> <strong>特例:y结尾双音节词,变y->i 加-er -est</strong></p><p> happy->happier early->earlier</p><p> <strong>early和showly</strong></p><p> early是不可分割:故变earlier</p><p> slowly是组合词:故变more slowly</p><h5 id="多音节:前面-more-most"><a href="#多音节:前面-more-most" class="headerlink" title="多音节:前面+more most"></a>多音节:前面+more most</h5><p><strong>特殊:</strong></p><table><thead><tr><th>原级</th><th>比较级</th><th>最高级</th></tr></thead><tbody><tr><td>good/well</td><td>better</td><td>best</td></tr><tr><td>bad/ill</td><td>worse</td><td>worst</td></tr><tr><td>far</td><td>farther/further</td><td>farthest/furthest</td></tr><tr><td>old</td><td>older/elder</td><td>oldest/eldest</td></tr><tr><td>little</td><td>less</td><td>least</td></tr><tr><td>many/much</td><td>more</td><td>most</td></tr><tr><td>late</td><td>later/latter</td><td>latest/last</td></tr><tr><td>up</td><td>upper</td><td>uppermost/upmost</td></tr></tbody></table><p><strong>特别说明</strong></p><p> <strong>A:farther(多用实际距离) further(表示抽象,进一步)</strong></p><p> further discussion</p><p> <strong>B:older(大小,用于比较级中) elder(成员长幼关系,并非大小,不用比较级中)</strong></p><p> my elder brother his eldest son</p><p> I am seven years older than Rex</p><p> <strong>C:later, latter, latest, last</strong></p><p> later(时间上”较迟“):I am on the phone right, Could you call me later?</p><p> latter(顺序上”后者“):The latter point is the most important.</p><p> latest(最新的,最近的):the latest games the latest fashions.</p><p> last(1.上一次,最近一次;2.所有事物中的最后一个)</p><p> 1.The last game, I won. last week</p><p> 2.The last three pages of the chapter</p><h4 id="原级比较"><a href="#原级比较" class="headerlink" title="原级比较"></a>原级比较</h4><p> <strong>如同:A + as + 形容词 or 副词 + as + B</strong></p><p> You are as lazy as she.</p><p> The work is not as difficult as you think.</p><p> <strong>如同的否定句:可用so代替第一个as</strong></p><p> The work is not so difficult as you think.</p><p> <strong>表示几倍/几分之几:A + 几倍(three times)/几分之几(a third) + as + 形容词 or 副词 +as + B</strong></p><p> This book is twice as thick as that one.</p><p> The Earth has a mass nearly one hundred times as much as that of the Moon.</p><p> <strong>A + the same + 名词 + as + B</strong></p><p> I am as old as you</p><p> I am the same age as you. </p><h4 id="形容词比较级注意"><a href="#形容词比较级注意" class="headerlink" title="形容词比较级注意"></a>形容词比较级注意</h4><h5 id="1-than前面必须有比较级"><a href="#1-than前面必须有比较级" class="headerlink" title="1.than前面必须有比较级"></a>1.than前面必须有比较级</h5><h5 id="2-必须是同类事物比较"><a href="#2-必须是同类事物比较" class="headerlink" title="2.必须是同类事物比较"></a>2.必须是同类事物比较</h5><p> <strong>a.两个彼此独立的同类事物比较</strong></p><p> This question is less difficult than that question.</p><p> <strong>b.自身比较:A + 比较级 + 情形1 + than + 情形2</strong></p><p> He did much better in the finals this term than last term</p><p> <strong>c.前后有从属关系时,加other,else与整体区别开来,避免逻辑错误</strong></p><p> She works harder than any other student in her class.(不说other就把自身也比较了)</p><h5 id="3-比较级前-the的情况:有介词短语-of-the-two时"><a href="#3-比较级前-the的情况:有介词短语-of-the-two时" class="headerlink" title="3.比较级前+the的情况:有介词短语 of the two时."></a>3.比较级前+the的情况:有介词短语 of the two时.</h5><p> I think this painting is the more interesting of the two.</p><h4 id="越来越……"><a href="#越来越……" class="headerlink" title="越来越……"></a>越来越……</h4><p> <strong>单音节:比较级 + and + 比较级:</strong>That female singer is getting fatter and fatter.</p><p> <strong>多音节:more and more 形容词原级:</strong></p><p> As summer approaches, the sea seems more and more beautiful.</p><h4 id="可以修饰比较级的词"><a href="#可以修饰比较级的词" class="headerlink" title="可以修饰比较级的词"></a>可以修饰比较级的词</h4><p> a bit, a little bit, a little, a lot, a great deal, any, even, far, by far, much, very much, no, rather, still, slightly. 不用:very, many, quite, fairly.</p><p> Are you feeling any better?</p><p> Things are no better than before</p><p> He makes far fewer mistakes in spellings than before </p><h4 id="否定比较级可表示最高级:few,-nothing,-never,-not"><a href="#否定比较级可表示最高级:few,-nothing,-never,-not" class="headerlink" title="否定比较级可表示最高级:few, nothing, never, not"></a>否定比较级可表示最高级:few, nothing, never, not</h4><p> How have you been?</p><p> It couldn’t be worse</p><p> Few are better qualified for the job than he is.</p><p> I have never heard a better song(This is the best song that I have ever heard)</p><h4 id="最高级注意"><a href="#最高级注意" class="headerlink" title="最高级注意"></a>最高级注意</h4><h5 id="1-the-最高级-in-地方-不说:It-is-the-most-expensive-car-of-the-world"><a href="#1-the-最高级-in-地方-不说:It-is-the-most-expensive-car-of-the-world" class="headerlink" title="1.the + 最高级 + in +地方-不说:It is the most expensive car of the world-"></a>1.the + 最高级 + in +地方-不说:It is the most expensive car of the world-</h5><p> It is the most expensive car in the world.</p><h5 id="2-第几最高:-the-序数词-最高级-in-地方"><a href="#2-第几最高:-the-序数词-最高级-in-地方" class="headerlink" title="2.第几最高: the + 序数词 + 最高级 + in + 地方"></a>2.第几最高: the + 序数词 + 最高级 + in + 地方</h5><p> The Huanghe River is the second longset river in China.</p><p> THe Yangtze River is the longest river in China, but it is the third longset river in the world</p><h5 id="3-the-最高级-of-所属范围"><a href="#3-the-最高级-of-所属范围" class="headerlink" title="3.the + 最高级 + of + 所属范围"></a>3.the + 最高级 + of + 所属范围</h5><p> The youngest (one) of the family is most successful.(理解时+one,but实际应用时省去)</p><p> Gold is sthe least useful of all metals.</p><p> The Atlantic is not the largest of the world’s oceans.</p><p> Silk is the strongest of all natural fibers, ranking in strength with the synthetic fiber nylon.</p><p> A good book is the best of friends, the same today and forever.</p><p> 特别:of + 范围放置句首:Of all metals, gold is the least useful.</p><h5 id="4-最高级是否加the"><a href="#4-最高级是否加the" class="headerlink" title="4.最高级是否加the"></a>4.最高级是否加the</h5><p> a.形容词需要+the:This is the most interesting book of all.</p><p> b.副词可加可不加:He works hardest in his class.</p><p> c.most不加the的特殊用法=very much:The story is most interesting.</p><h4 id="无等级形容词:含绝对含义-可用nearly,almost,the-most-closely,more-nearly修饰"><a href="#无等级形容词:含绝对含义-可用nearly,almost,the-most-closely,more-nearly修饰" class="headerlink" title="无等级形容词:含绝对含义-可用nearly,almost,the most closely,more nearly修饰-"></a>无等级形容词:含绝对含义-可用nearly,almost,the most closely,more nearly修饰-</h4><p>absolute, alone, dead, empty, equal, eternal, final, harizontal, perfect, primary, pregnant, round, single, square, straight, supreme, unique, unanimous.</p><p>英语学习-<a href="https://github.com/removeif/english-learn">语法系列github仓库</a>,欢迎收藏star </p><p>参考文章:<br><a href="https://github.com/yizutianya/English_Grammar_Learning">参考链接</a></p>]]></content>
<summary type="html"><h4 id="两种形容词的区别"><a href="#两种形容词的区别" class="headerlink" title="两种形容词的区别"></a>两种形容词的区别</h4><p> <strong>ing:</strong>描述引起人某种感觉的事物(主语通常是事物)</p>
<p> <strong>ed:</strong>描述人对事物的感觉(主语通常是人)</p>
<p> The interesting children can make other people feel interested in them.</p></summary>
<category term="English" scheme="https://removeif.github.io/categories/English/"/>
<category term="grammar" scheme="https://removeif.github.io/categories/English/grammar/"/>
<category term="English" scheme="https://removeif.github.io/tags/English/"/>
<category term="grammar" scheme="https://removeif.github.io/tags/grammar/"/>
</entry>
<entry>
<title>英语语法-限定词2</title>
<link href="https://removeif.github.io/english-learn/%E8%8B%B1%E8%AF%AD%E8%AF%AD%E6%B3%95-%E9%99%90%E5%AE%9A%E8%AF%8D2.html"/>
<id>https://removeif.github.io/english-learn/%E8%8B%B1%E8%AF%AD%E8%AF%AD%E6%B3%95-%E9%99%90%E5%AE%9A%E8%AF%8D2.html</id>
<published>2020-03-10T18:49:05.000Z</published>
<updated>2025-01-06T09:42:34.422Z</updated>
<content type="html"><![CDATA[<h4 id="冠词"><a href="#冠词" class="headerlink" title="冠词"></a>冠词</h4><p> a 辅音因素开头的名词前, an 元音因素开头的名词前** </p><p> 单数可数名词:不能单独使用,必须用冠词或其他限定词</p><p> 复数可数名词 or 不可数名词:</p><p>**(1)不能同冠词连用** <span id="more"></span></p><p><strong>(2)复数名词 or 不可数名词</strong> </p><p> <strong>泛指:不用the</strong></p><p> Life is hard sometimes</p><p> <strong>特指:用the</strong></p><p> The writer is writing a book about the life of blacks in America.</p><p> I love music, poetry and art.</p><p> I don’t like the film, but I like the music(of the film)</p><p> <strong>表示特指的时候,一般会带有后置定语</strong></p><h5 id="第一次提到单数可数名词前用不定冠词a-or-an,再次出现要用定冠词the"><a href="#第一次提到单数可数名词前用不定冠词a-or-an,再次出现要用定冠词the" class="headerlink" title="第一次提到单数可数名词前用不定冠词a or an,再次出现要用定冠词the"></a>第一次提到单数可数名词前用不定冠词a or an,再次出现要用定冠词the</h5><h5 id="谈到对话双方都知道的事物要用the(比如自己房间里的东西)"><a href="#谈到对话双方都知道的事物要用the(比如自己房间里的东西)" class="headerlink" title="谈到对话双方都知道的事物要用the(比如自己房间里的东西)"></a>谈到对话双方都知道的事物要用the(比如自己房间里的东西)</h5><p> can you turn off the light, please?</p><h5 id="表示世界上独一无二的事物用the"><a href="#表示世界上独一无二的事物用the" class="headerlink" title="表示世界上独一无二的事物用the"></a>表示世界上独一无二的事物用the</h5><p> the earth, the sky, the equator, the moon, the world, the universe</p><h5 id="做形容词的only、最高级、序数词修饰的名词前-the"><a href="#做形容词的only、最高级、序数词修饰的名词前-the" class="headerlink" title="做形容词的only、最高级、序数词修饰的名词前+the"></a>做形容词的only、最高级、序数词修饰的名词前+the</h5><p> the only/best way to cope with the problem.</p><p> this is the first time I’ve come to Beijing.</p><h5 id="乐器、乐团-the(运动不-the)play-football-or-chess-or-tennis"><a href="#乐器、乐团-the(运动不-the)play-football-or-chess-or-tennis" class="headerlink" title="乐器、乐团+the(运动不+the)play football or chess or tennis"></a>乐器、乐团+the(运动不+the)play football or chess or tennis</h5><p> the Beatles</p><p> the Philaadelphia Orchestra</p><p> play/learn the guitar learn the piano</p><h5 id="独一无二的身份不-the"><a href="#独一无二的身份不-the" class="headerlink" title="独一无二的身份不+the"></a>独一无二的身份不+the</h5><p> Henry was elected chairman of the committee</p><p> For the first time I am king of myself</p><h5 id="限定词彼此互斥,不能同时出现在名词前面"><a href="#限定词彼此互斥,不能同时出现在名词前面" class="headerlink" title="限定词彼此互斥,不能同时出现在名词前面"></a>限定词彼此互斥,不能同时出现在名词前面</h5><p> (1)冠词:the an a</p><p> (2)物主形容词: my your his her our their</p><p> (3)指示形容词: this that these those</p><p> (4)名词属格: Tom’s John’s</p><h5 id="特殊名词前省略the"><a href="#特殊名词前省略the" class="headerlink" title="特殊名词前省略the"></a>特殊名词前省略the</h5><p> (1)nature : in nature (2)society: in society (3)space: in space</p><p> (4)man在泛指整个人类时,不加冠词</p><p> (5)history在泛指整个历史时,不加冠词</p><p> (6)三餐前不+冠词:have something for breakfast/lunch/supper/dinner</p><h5 id="交通工具"><a href="#交通工具" class="headerlink" title="交通工具"></a>交通工具</h5><p> 若用介词on:+冠词the(on foot 步行不加the)on the train/plane/boat</p><p> 若不用介词on,如用by时,不加the: by bicycle/boat/bus/car/plane/train/metro</p><h5 id="其他固定介词搭配"><a href="#其他固定介词搭配" class="headerlink" title="其他固定介词搭配"></a>其他固定介词搭配</h5><p> face to face , arm in arm , hand in hand , shoulder to shoulder , side by side</p><p> inch by inch , day after day , dentist after dentist</p><h5 id="school-or-the-school"><a href="#school-or-the-school" class="headerlink" title="school or the school"></a>school or the school</h5><p> bed, church, court, hospital, prison, school/college/unversity, sea, work, office</p><p> <strong>当人们去这些地方做在这些地方应该做的事情时,不加冠词,表示抽象概念</strong></p><p> <strong>当要去这些地方不是要做特定的事,而是由于其他原因,要用the</strong></p><p> his mother is in hospital and he has been in the hospital to take care of her.</p><p> Bill Blinton came into office in 1992./Bill Clinton came into the office and saw sth.</p><p> to church(to pray)</p><p> to hospital(as patients)</p><p> to/at sea(出海/在海上)</p><p> to/at/from(去上班/在上班/下班)</p><p> go to sea(as sailors) go to the sea(go to the seaside)</p><p> be at sea(as passengers or crew) be at the sea(be at the seaside)</p><p> by sea(by ship)</p><p> by the sea(by the seaside)</p><p> be in office(在任职) be in the office(在办公室里)</p><p> be out of office(离职) be out of the office(离开办公室)</p><h5 id="泛指的四种表达"><a href="#泛指的四种表达" class="headerlink" title="泛指的四种表达"></a>泛指的四种表达</h5><p> <strong>1.不带the的不可数名词</strong></p><p> I like music</p><p> <strong>2.不带the的复数可数名词</strong></p><p> bananas are yellow I am afraid of dogs</p><p> <strong>3.the+单数可数名词(也可表示特指)</strong></p><p> the whale is the largest mammal on earth</p><p> the whale is dead</p><p> <strong>4.a/an+单数可数名词(也可以表示一个)</strong></p><p> I ate a banana this morning</p><p> A banana is yellow</p><p> 英语学习-<a href="https://github.com/removeif/english-learn">语法系列github仓库</a>,欢迎收藏star </p><p>参考文章:<br><a href="https://github.com/yizutianya/English_Grammar_Learning">参考链接</a></p>]]></content>
<summary type="html"><h4 id="冠词"><a href="#冠词" class="headerlink" title="冠词"></a>冠词</h4><p> a 辅音因素开头的名词前, an 元音因素开头的名词前** </p>
<p> 单数可数名词:不能单独使用,必须用冠词或其他限定词</p>
<p> 复数可数名词 or 不可数名词:</p>
<p>**(1)不能同冠词连用**</p></summary>
<category term="English" scheme="https://removeif.github.io/categories/English/"/>
<category term="grammar" scheme="https://removeif.github.io/categories/English/grammar/"/>
<category term="English" scheme="https://removeif.github.io/tags/English/"/>
<category term="grammar" scheme="https://removeif.github.io/tags/grammar/"/>
</entry>
<entry>
<title>英语语法-限定词1</title>
<link href="https://removeif.github.io/english-learn/%E8%8B%B1%E8%AF%AD%E8%AF%AD%E6%B3%95-%E9%99%90%E5%AE%9A%E8%AF%8D1.html"/>
<id>https://removeif.github.io/english-learn/%E8%8B%B1%E8%AF%AD%E8%AF%AD%E6%B3%95-%E9%99%90%E5%AE%9A%E8%AF%8D1.html</id>
<published>2020-03-10T18:49:00.000Z</published>
<updated>2025-01-06T09:42:34.422Z</updated>
<content type="html"><![CDATA[<h4 id="数量限定词"><a href="#数量限定词" class="headerlink" title="数量限定词"></a>数量限定词</h4><h5 id="只与可数名词连用"><a href="#只与可数名词连用" class="headerlink" title="只与可数名词连用"></a>只与可数名词连用</h5><p> <strong>只接单数</strong> one each every</p><p> <strong>只接复数</strong> two(three) both a couple of a few several many a number of <span id="more"></span></p><h5 id="只与不可数名词连用"><a href="#只与不可数名词连用" class="headerlink" title="只与不可数名词连用"></a>只与不可数名词连用</h5><p> a little little much a great deal of a large amount of</p><h5 id="与可数名词复数或不可数名词连用均可"><a href="#与可数名词复数或不可数名词连用均可" class="headerlink" title="与可数名词复数或不可数名词连用均可"></a>与可数名词复数或不可数名词连用均可</h5><p> not any some a lot of lots of plenty of most all </p><h5 id="数量词与of连用"><a href="#数量词与of连用" class="headerlink" title="数量词与of连用"></a>数量词与of连用</h5><p>all/most/some/any of+特指限定词+复数可数或不可数名词</p><p>most books</p><p>most of books 不正确</p><p>most of my/these/the/john’s books </p><p>many/a few/few/several/both/two/three of +特指限定词+ 复数可数名词</p><p>many students</p><p>many of students 不正确</p><p>many of these students</p><p>much/a little/little of +特指限定词+ 不可数名词</p><p>much water</p><p>much of water 不正确</p><p>much of the water</p><h5 id="其他数量词-a-lot-of-lots-of-a-couple-of-plenty-of-a-number-of-a-great-deal-of-直接-名词"><a href="#其他数量词-a-lot-of-lots-of-a-couple-of-plenty-of-a-number-of-a-great-deal-of-直接-名词" class="headerlink" title="其他数量词 a lot of , lots of , a couple of , plenty of , a number of , a great deal of 直接+名词"></a>其他数量词 a lot of , lots of , a couple of , plenty of , a number of , a great deal of 直接+名词</h5><h5 id="all和both特殊用法"><a href="#all和both特殊用法" class="headerlink" title="all和both特殊用法"></a>all和both特殊用法</h5><p>all/both my students 可以不加of,其他much/many数量限定词不可这么用</p><p>all students</p><p>all of my students</p><p>all of students 不正确</p><h5 id="数量词a-few-few(只接可数)-a-little-little(只接不可数)"><a href="#数量词a-few-few(只接可数)-a-little-little(只接不可数)" class="headerlink" title="数量词a few, few(只接可数), a little, little(只接不可数)"></a>数量词a few, few(只接可数), a little, little(只接不可数)</h5><p><strong>a little,a few为肯定之意,等同于some,有一些</strong></p><p> His theory is rather difficult; few people understand it.=almost no people understand it.</p><p> I have little interest in English, so I am very poor at it.</p><p><strong>little,few为否定之意,等同于几乎没有</strong></p><p> His theory is rather difficult, but a few people understand it.</p><p> I have a little interest in English, so I like learning it.</p><p>only a little,only a few very few,very little</p><p>some and any</p><h5 id="陈述句:some-一般用肯定,any一般用否定,表示”一些“。可与可数或不可数名词连用。"><a href="#陈述句:some-一般用肯定,any一般用否定,表示”一些“。可与可数或不可数名词连用。" class="headerlink" title="陈述句:some 一般用肯定,any一般用否定,表示”一些“。可与可数或不可数名词连用。"></a>陈述句:some 一般用肯定,any一般用否定,表示”一些“。可与可数或不可数名词连用。</h5><p> I need some medicine to cure my cough.</p><p> I don’t have any friends here.</p><h5 id="疑问句:多用any;在期待对方回答”是“的时候,要用some"><a href="#疑问句:多用any;在期待对方回答”是“的时候,要用some" class="headerlink" title="疑问句:多用any;在期待对方回答”是“的时候,要用some"></a>疑问句:多用any;在期待对方回答”是“的时候,要用some</h5><p> Have you got any medicine to cure your cough?</p><p> Would you like to give me some advice? Can I have some more wine?</p><h5 id="any可以表示”任何一个,无论哪一个“,用于任何句型。"><a href="#any可以表示”任何一个,无论哪一个“,用于任何句型。" class="headerlink" title="any可以表示”任何一个,无论哪一个“,用于任何句型。"></a>any可以表示”任何一个,无论哪一个“,用于任何句型。</h5><p> You can catch any bus. They all go to the railway station.</p><p>英语学习-<a href="https://github.com/removeif/english-learn">语法系列github仓库</a>,欢迎收藏star </p><p>参考文章:<br><a href="https://github.com/yizutianya/English_Grammar_Learning">参考链接</a></p>]]></content>
<summary type="html"><h4 id="数量限定词"><a href="#数量限定词" class="headerlink" title="数量限定词"></a>数量限定词</h4><h5 id="只与可数名词连用"><a href="#只与可数名词连用" class="headerlink" title="只与可数名词连用"></a>只与可数名词连用</h5><p> <strong>只接单数</strong> one each every</p>
<p> <strong>只接复数</strong> two(three) both a couple of a few several many a number of</p></summary>
<category term="English" scheme="https://removeif.github.io/categories/English/"/>
<category term="grammar" scheme="https://removeif.github.io/categories/English/grammar/"/>
<category term="English" scheme="https://removeif.github.io/tags/English/"/>
<category term="grammar" scheme="https://removeif.github.io/tags/grammar/"/>
</entry>
<entry>
<title>英语语法-完成时</title>
<link href="https://removeif.github.io/english-learn/%E8%8B%B1%E8%AF%AD%E8%AF%AD%E6%B3%95-%E5%AE%8C%E6%88%90%E6%97%B6.html"/>
<id>https://removeif.github.io/english-learn/%E8%8B%B1%E8%AF%AD%E8%AF%AD%E6%B3%95-%E5%AE%8C%E6%88%90%E6%97%B6.html</id>
<published>2020-03-10T18:48:50.000Z</published>
<updated>2025-01-06T09:42:34.422Z</updated>
<content type="html"><![CDATA[<h4 id="现在完成时-一-:开始于过去的动作一直持续到现在,有可能继续持续。谓语动词为延续性动词"><a href="#现在完成时-一-:开始于过去的动作一直持续到现在,有可能继续持续。谓语动词为延续性动词" class="headerlink" title="现在完成时(一):开始于过去的动作一直持续到现在,有可能继续持续。谓语动词为延续性动词"></a>现在完成时(一):开始于过去的动作一直持续到现在,有可能继续持续。谓语动词为延续性动词</h4><p> I have lived here for 3 years. 我仍然住在这里,而且还可能继续住下去。</p><p> <strong>如果在搬家时说这句话,则live这件事只持续到目前为止。</strong></p><p> The teacher has taught in this school since I came here. <span id="more"></span></p><p> I’ve worked in this company since I left school.</p><p> <strong>since表明了动作开始的时间点。</strong></p><p> <strong>有上下问明确告知,动作只持续到说话的时刻为止。</strong></p><p> a. A: Have you waited long?</p><p> B: I’ve waited for three hours.</p><p> b. I’ve waited for him all day; I don’t want to wait any longer.</p><h5 id="特点:"><a href="#特点:" class="headerlink" title="特点:"></a>特点:</h5><ol><li><p>谓语动词为延续性动词</p></li><li><p>动作的发生时间是过去,持续到现在,还可能继续持续下去。</p></li><li><p>常常与表示一段时间的时间状语连用,是说明某个状态持续了多久。</p></li></ol><h5 id="与现在完成时搭配的时间状语"><a href="#与现在完成时搭配的时间状语" class="headerlink" title="与现在完成时搭配的时间状语"></a>与现在完成时搭配的时间状语</h5><p> <strong>1. since + 时间点</strong></p><p> a. I’ve worked in thiss company since 1980</p><p> b. I’ve worked in this company since I left school. (从句中一般过去时)</p><p> <strong>2. for + 时间段</strong></p><p> a. I’ve worked in this company for three years.</p><p> b. Great changes have taken place in Beijing for the past few years.</p><p> <strong>3. 到目前为止:</strong>until now, up until now, up to now, up till now, so far.</p><p> a. We have up until now failed to take any action to decide on a common language that would further communication between nations.</p><p> <strong>4. 在最近几世纪/年/月以来:</strong>in the past few years, over the past few years, during the last three months, for the last few centuries, through centuries, throughout history.</p><p> a. Throughout history man has had to accept the fact that all living things must die, for the very nature of life includes death.</p><p> b. Through centuries the bizarre anticss of sleepwalkers have puzzled police, perplexed scientists anad fascinated writers.</p><h4 id="现在完成时-二-:过去发生但与现在仍有联系的动作或状态"><a href="#现在完成时-二-:过去发生但与现在仍有联系的动作或状态" class="headerlink" title="现在完成时(二):过去发生但与现在仍有联系的动作或状态"></a>现在完成时(二):过去发生但与现在仍有联系的动作或状态</h4><p> a. He has broken his leg. 他现在还在医院,所以不能和同学一起郊游。</p><p> b. He broke this leg. 退摔断过,单纯表示一种过去的经历,但现在腿已经好了。</p><p> c. You should have put the milk into icebox; I expect it has become undrinkable by now.</p><p> <strong>牛奶变质是过去某一时刻的动作,但其影响延续到现在。现在牛奶已经不能喝了。</strong></p><h5 id="第二种现在完成时使用技巧。"><a href="#第二种现在完成时使用技巧。" class="headerlink" title="第二种现在完成时使用技巧。"></a>第二种现在完成时使用技巧。</h5><p> <strong>1. 不与一段时间的时间状语连用:</strong>常见 come, go, leave, kill, die, lose, buy, start, give, marry</p><p> <del>he has left his hometown for 3 years.</del> </p><p> <strong>改正:</strong></p><p> a. He left this hometown 3 years ago.</p><p> b. It’s 3 years since he left this home town.</p><p> c. He hasn’t come back since he left his hometown 3 years ago.</p><p> d. He has been away from his home town for 3 years.</p><p> <strong>2. 终止性动词的完成时句子若用否定,表示尚未发生的事情,则可以为一种状态,从而表示延续。</strong></p><p> a. I haven’t seen a film for weeks.</p><p> b. I haven’t heard form my girlfriends since I came to America</p><p> c. I haven’t bought a pair of shoes for a year.</p><p> <strong>3. 与不确定时间的时间状语连用</strong></p><p> <strong>这种完成时,可以同一些表示不确定的时间状语连用:</strong>already, yet, lately, often, just, never</p><p> a. A: would you like something to eat?</p><p> B: No, thanks. I’ve just had dinner.</p><p> b. The leading expert on sleep in America claims that he has never seen a sleepwalker.</p><p> c. Has it stopped raining yet?</p><p> d. He has already arrived.</p><p> f. I have often thought that it would be perfect if we could fly without any aid.</p><p> <strong>4. 具有新闻性质:表示最近才发生的动作,提供新消息。有新闻性质</strong></p><p> a. The President has been assassinated.</p><p> b. He can’t go on holiday because he has broken his leg.</p><p> <strong>强调的时间内容,而不算是发生的过去具体时间。</strong></p><p> <strong>通常的日常对话,以现在完成时开始问答。过去时间咋唉说话人的脑子中已经确定了,则继续用一般过去时。</strong></p><p> c. I hear that famous Chinese comedian has died.</p><p> Really? When did she die? She was dead late last night.</p><h4 id="现在完成时-三-:表示到目前为止的一个时间段内重复发生的动作。"><a href="#现在完成时-三-:表示到目前为止的一个时间段内重复发生的动作。" class="headerlink" title="现在完成时(三):表示到目前为止的一个时间段内重复发生的动作。"></a>现在完成时(三):表示到目前为止的一个时间段内重复发生的动作。</h4><p> For more than eighty years, scientists have argued over whehter life exists on the planet Mars.</p><p> We have taken three tests so far this week.</p><h5 id="其他现在完成时的结构"><a href="#其他现在完成时的结构" class="headerlink" title="其他现在完成时的结构"></a>其他现在完成时的结构</h5><p> <strong>1. This/ That/ It is + 序数词 + 名词 + that + 现在完成时</strong></p><p> a. It is the third thime that I’ve come to Beijing.</p><p> b. It is the fifth time that someone has knocked at my door.</p><p> c. This is the thenth cup of coffee that I’ve drunk this evening.</p><p> <strong>2. This/ That/ It is + 最高等或only修饰名词 + 现在完成时</strong></p><p> a. This is the most interesting movie that I’ve ever seen </p><p> b. This is the best wine I have ever drunk</p><p> c. This is the hardest job I have ever had.</p><p> <strong>3. 如果是It was the second/ best… that 后面要用过去完成时</strong></p><p> a. It was the fifth time that someone had knocked at my door that night.</p><p><strong>总结:一直在持续; 重复发生;影响现状</strong></p><h5 id="现在完成时与一般过去时比较"><a href="#现在完成时与一般过去时比较" class="headerlink" title="现在完成时与一般过去时比较"></a>现在完成时与一般过去时比较</h5><p> <strong>不同时态,表明了说话的时间不同。</strong></p><p> a. I haven’t seen him this morning.</p><p> b. I didn’t see him this morning.</p><p> a. 句用了现在完成时,而完成时生死要与现在发生联系的。所以a说话的时间是this morning</p><p> b. 句用的是一般过去时,说明this morning已经成为了过去,所以b说话时间是今早后</p><p> c. I have called thim three times this morning.</p><p> d. I called thim three times this morning.</p><p> c. 表示到现在为止的一个是时间段内重复的动作。所以c说话时间是this morning</p><p> d. 过去时,和现在没有什么联系,所以说话时间是今早后</p><p> <strong>延续性动词的两种时态区别</strong></p><p> a. He lives in Beijing. He has lived here for 3 years. (可能还继续住在这里)</p><p> b. He lived in Beijing for 3 years and then emigrated to America (曾经住过,已经搬走了)</p><h5 id="过去完成时:过去某时刻之前就开始的动作;"><a href="#过去完成时:过去某时刻之前就开始的动作;" class="headerlink" title="过去完成时:过去某时刻之前就开始的动作;"></a>过去完成时:过去某时刻之前就开始的动作;</h5><p> <strong>(1)该过去时刻仍然在继续,或该过去时刻刚刚停止</strong></p><p> <strong>(2)在该过去时刻之前的某一时刻已经停止的动作做</strong></p><p> <strong>(3)在该过去时刻之前一段时间内重复的动作</strong></p><p><strong>(1)</strong></p><p> a. I had stayed in America for two years when he moved here.</p><p> b. I had lived in 兵庫 for one and a half years when I came to Aizu.</p><p> <strong>有上下文表示持续过去这一时刻刚刚停止</strong></p><p> c. I had waited for her for two hours in susch a severe winter when she eventually turned up</p><p> d. There had been fifty colleges in our city up till 1993.</p><p><strong>(2)</strong></p><p> a. She had made everything ready before I came.</p><p> b. Her baby had fallen asleep when she went into the room.</p><p> c. Before John got home, Mary had gone to bed.</p><p> d. I had just poured myself a cup of tea when the phone rang. When I came back from answering it, the cup was empty. Somebody had drunk the tea or thrown it away.</p><p><strong>(3)</strong></p><p> a. I had written her 100 letters when she finally promised to marry me.</p><p> b. I had proposed to her five times, but she still refused to marry me.</p><h5 id="过去完成时的其他用法"><a href="#过去完成时的其他用法" class="headerlink" title="过去完成时的其他用法"></a>过去完成时的其他用法</h5><p> <strong>1. intend, mean, hope, want, plan, suppose, expect, think, propose, wish</strong></p><p> <strong>动词的过去完成时,可以表示过去未能时间的计划,设想,意图或希望等</strong></p><p> a. I had planned to go shopping with you but my mother came to see me just when I was about to go.</p><p> b. She had hoped that he would come to date her, but he didn’t show up.</p><p> c. I had intended to see you, but I was busy.</p><p> d. They had hoped to see you off at the airport, but they got there too late.</p><p> <strong>2. 用在It was the + 序数词 或最高级 that 句中。</strong></p><p> a. Last week I attended an international conference and saw Mr. Machine. It was the third time that I had met him.</p><h5 id="一把拿过去时与过去完成时的比较"><a href="#一把拿过去时与过去完成时的比较" class="headerlink" title="一把拿过去时与过去完成时的比较"></a>一把拿过去时与过去完成时的比较</h5><p> <strong>1. 两个或以上相继发生的动作,用and 或 but 按动作发生的先后顺序连接,此时要用一般过去时。 过去完成时则强调主语在过去某一时刻回顾更早的动作,具体来说。当我们在讨论过去某一事件时,想到了在这之前已经发生的某事,这时用过去完成时。</strong></p><p> a. He opened the door and entered, but found nobody.</p><p> b. He served in the army for ten years; then retired and married. His children are now at school.</p><p> c. When I had written my letters I did some gardening. </p><p> d. When I wrote him a letter, he came at once.</p><p> e. When the singer had sung her song, she sat down.如果说when the singer sang her song, she sat down.给中一种印象,这位歌手喜欢坐着唱歌。 </p><h5 id="将来完成时:站在将来某一时间来谈某一个动作的完成情况"><a href="#将来完成时:站在将来某一时间来谈某一个动作的完成情况" class="headerlink" title="将来完成时:站在将来某一时间来谈某一个动作的完成情况"></a>将来完成时:站在将来某一时间来谈某一个动作的完成情况</h5><p> <strong>动作开始的时间可以是过去,现在,未来。但并不重要,说话人强调的是他们一共有5门</strong></p><p> a. We started our exam yesterday and we will have taken five exams by next Friday.</p><p> b. We have started our exam today and we will have taken five exams by next Friday.</p><p> c. We will start our exam tomorrow and we will have taken five exams by next Friday.</p><p> <strong>1. 同现在完成时第一种用法的将来完成时</strong></p><p> a. I will have taught English in New Oriental School for five years by the end of next month.</p><p> b. I will have learned 8000 words by the end of next year.</p><p> c. I will have waited for her for two hourss when she arrives at 2 o’clock this afternoon.</p><p> <strong>2. 同现在完成时第二种用法的将来完成时:对将来有影响</strong></p><p> a. We will have finished our exam by the end of next week.</p><p> b. By the year 2050, scientists probably will have discovered a cure for cancer.</p><p> c. I will graduate in July. I will see you in September. By the time I see you, I will have graduated.</p><p> d. I will have finished my homework by the time I go out on a date tonight.</p><p> <strong>3. 同现在完成时第二种用法的将来完成时:重复发生。</strong></p><p> a. By five o’ clock this afternoon the spaceship will have traveled eleven times round the world. </p><h4 id="完成时的三种思维用法"><a href="#完成时的三种思维用法" class="headerlink" title="完成时的三种思维用法"></a>完成时的三种思维用法</h4><p> <strong>1. 延续到现在的动作或状态,可能继续延续,也可能到现在为止。</strong></p><p> <strong>2. 过去发生但与现在仍有联系的动作或状态。对现在有影响。</strong></p><p> <strong>3. 到目前为止的一个时间段内重复发的动作。</strong></p><p> <strong>4.不同时间的完成时本质上是一样的。只是说话人的立足时间不同。</strong></p><p>● Sorry I’m late. The car broke down on my way here.</p><p>● Yesterday I had a phone call from Clint. I was very surprised. I had written to him many times but he had never replied to my letters.</p><p>● The man sitting next to me on the plane was very nervous. It was his first flight. He had never flown before.</p><p>● Last spring I went to France. It was the first time that I had been there.</p><p>● Look! Somebody has spilt milk on the carpet. Well, it wasn’t me. I didn’t do it. I wonder who it was then.</p><p>● I lost my key, so I couldn’t get into my house. But now I have found it.</p><p>● He has been in the army for five years.</p><p>● I’ve already had lunch.</p><p> 英语学习-<a href="https://github.com/removeif/english-learn">语法系列github仓库</a>,欢迎收藏star </p><p>参考文章:<br><a href="https://github.com/yizutianya/English_Grammar_Learning">参考链接</a></p>]]></content>
<summary type="html"><h4 id="现在完成时-一-:开始于过去的动作一直持续到现在,有可能继续持续。谓语动词为延续性动词"><a href="#现在完成时-一-:开始于过去的动作一直持续到现在,有可能继续持续。谓语动词为延续性动词" class="headerlink" title="现在完成时(一):开始于过去的动作一直持续到现在,有可能继续持续。谓语动词为延续性动词"></a>现在完成时(一):开始于过去的动作一直持续到现在,有可能继续持续。谓语动词为延续性动词</h4><p> I have lived here for 3 years. 我仍然住在这里,而且还可能继续住下去。</p>
<p> <strong>如果在搬家时说这句话,则live这件事只持续到目前为止。</strong></p>
<p> The teacher has taught in this school since I came here.</p></summary>
<category term="English" scheme="https://removeif.github.io/categories/English/"/>
<category term="grammar" scheme="https://removeif.github.io/categories/English/grammar/"/>
<category term="English" scheme="https://removeif.github.io/tags/English/"/>
<category term="grammar" scheme="https://removeif.github.io/tags/grammar/"/>
</entry>
<entry>
<title>英语语法-完成进行时</title>
<link href="https://removeif.github.io/english-learn/%E8%8B%B1%E8%AF%AD%E8%AF%AD%E6%B3%95-%E5%AE%8C%E6%88%90%E8%BF%9B%E8%A1%8C%E6%97%B6.html"/>
<id>https://removeif.github.io/english-learn/%E8%8B%B1%E8%AF%AD%E8%AF%AD%E6%B3%95-%E5%AE%8C%E6%88%90%E8%BF%9B%E8%A1%8C%E6%97%B6.html</id>
<published>2020-03-09T17:40:32.000Z</published>
<updated>2025-01-06T09:42:34.422Z</updated>
<content type="html"><![CDATA[<h4 id="现在完成进行时"><a href="#现在完成进行时" class="headerlink" title="现在完成进行时"></a>现在完成进行时</h4><h5 id="一-到现在仍在延续的动作"><a href="#一-到现在仍在延续的动作" class="headerlink" title="(一)到现在仍在延续的动作"></a>(一)到现在仍在延续的动作</h5><p> <strong>1. 与一段时间连用:强调动作的持续性,开始于过去的动作持续到现在,并且还会继续持续</strong><br> 常与for + 时间段、since + 时间点、all morning、all day、all week表示段时间的状语连用</p><p> It began raining two hours ago and it’s still raining. It has been raining for two hours. <span id="more"></span></p><p> <strong>2. 可不与时间段连用;表示最近一段时间内正在持续的活动</strong></p><p> I have been thinking about changing my job. 我最近一直在考虑换工作。</p><h5 id="二-刚刚结束的动作"><a href="#二-刚刚结束的动作" class="headerlink" title="(二)刚刚结束的动作"></a>(二)刚刚结束的动作</h5><p> <strong>1. 动作持续到说话为止</strong></p><p> a. Where have you been? I’ve been looking for you for the last half hour.</p><p> b. Thank you for the binoculars. I’ve been wanting a pair for ages.</p><p> <strong>2. 不久前刚刚结束的动作(完成时没有的用法)</strong></p><p> a. Your friend is out of breath. you ask, “Have you been running?”</p><p> b. Why are your clothes so dirty? what have you been doing?</p><p> c. The little boy is dirty from head to foot because he has been playing in the mud.</p><h5 id="三-重复发生的的动作"><a href="#三-重复发生的的动作" class="headerlink" title="(三)重复发生的的动作"></a>(三)重复发生的的动作</h5><p> <strong>说话时刻以前的一段时间内重复发生的动作</strong></p><p> a. Every Sunday they meet in the same bar. They’re been going there for years.</p><p> b. I’ve been getting up early since I entered the college.</p><p> c. The price has been going up recently. I wonder whether it will remain so.</p><p> d. You’ve been staying up late again?</p><h5 id="与现在完成时比较-一"><a href="#与现在完成时比较-一" class="headerlink" title="与现在完成时比较(一)"></a>与现在完成时比较(一)</h5><p><strong>相同点:</strong></p><p> <strong>1. 都是延续性谓语动作live, learn, study, sleep, snow, wait, work, teach, stay</strong></p><p> <strong>2. 与时间段连用(这时两种时态几乎没有多大的区别)</strong></p><p> a. I have been learning/ have learned English for ten years.</p><p> b. I have been living/ have lived here since 3 years ago.</p><p><strong>不同点:</strong></p><p> <strong>现在完成时只与段时间连用才能表示这类动作。</strong></p><p> a. I have worked/ have been working in this company for 3 years.</p><p> b. I have worked in this company(现在不在了,表示过去的经历)</p><p> c. I have been working in this company. (现在还在这家公司)</p><p> d. He has been sleeping/ has slept for three hours.</p><p> e. He has slept(他睡过了,所以现在不困了)</p><p> g. he has been sleeping(现在还在睡)</p><h5 id="与现在完成时比较-二"><a href="#与现在完成时比较-二" class="headerlink" title="与现在完成时比较(二)"></a>与现在完成时比较(二)</h5><p> <strong>完成进行时强调动作过程</strong></p><p> <strong>完成时强调动作的结果</strong></p><p> a. My hands are very dirty. I’ve been painting the house(理由,做的动作过程)</p><p> b. I have painted the house green. The house was white, but now it’s green.</p><p> c. Sorry about the mess–I’ve been painting the house.</p><h5 id="与现在完成时比较-三"><a href="#与现在完成时比较-三" class="headerlink" title="与现在完成时比较(三)"></a>与现在完成时比较(三)</h5><p> <strong>1. 短暂动词的完成进行时表示重复。</strong></p><p> <strong>短暂动词的完成时不能与一段时间的时间状语连用。但是完成进行时可以,表示重复动作</strong></p><p> a. Over the past few years, many towns in the United States have been joining with neighboring communites to share the costs of government.</p><p> b. Over the past few years, many towns in the United States have joined with …</p><p> c.I’ve got up early since I entered the college.</p><p> <strong>2. 重复动作的分割性</strong></p><p> <strong>完成进行时表示不间断动作。如果要表达做事情的次数,不能用现在完成进行时</strong></p><p> a. I have been sitting in class since 8 o’ clock this morning.</p><p> b. I have had three classes since 8 o’ clock this morning.</p><p> c. The phone has been ringing for almost a minute, why doesn’t someone answer it?<br> d. The phone has rung four times this mrning, and each time it has been for Clint.</p><h5 id="与现在完成时比较-四"><a href="#与现在完成时比较-四" class="headerlink" title="与现在完成时比较(四)"></a>与现在完成时比较(四)</h5><p> <strong>不能用进行时的动词,同样不能用现在完成进行时</strong></p><p> a. How long have you known Jane?</p><p> b. How long have you been knowing Jane? </p><p>英语学习-<a href="https://github.com/removeif/english-learn">语法系列github仓库</a>,欢迎收藏star </p><p>参考文章:<br><a href="https://github.com/yizutianya/English_Grammar_Learning">参考链接</a></p>]]></content>
<summary type="html"><h4 id="现在完成进行时"><a href="#现在完成进行时" class="headerlink" title="现在完成进行时"></a>现在完成进行时</h4><h5 id="一-到现在仍在延续的动作"><a href="#一-到现在仍在延续的动作" class="headerlink" title="(一)到现在仍在延续的动作"></a>(一)到现在仍在延续的动作</h5><p> <strong>1. 与一段时间连用:强调动作的持续性,开始于过去的动作持续到现在,并且还会继续持续</strong><br> 常与for + 时间段、since + 时间点、all morning、all day、all week表示段时间的状语连用</p>
<p> It began raining two hours ago and it’s still raining. It has been raining for two hours.</p></summary>
<category term="English" scheme="https://removeif.github.io/categories/English/"/>
<category term="grammar" scheme="https://removeif.github.io/categories/English/grammar/"/>
<category term="English" scheme="https://removeif.github.io/tags/English/"/>
<category term="grammar" scheme="https://removeif.github.io/tags/grammar/"/>
</entry>
<entry>
<title>英语语法-人称代词</title>
<link href="https://removeif.github.io/english-learn/%E8%8B%B1%E8%AF%AD%E8%AF%AD%E6%B3%95-%E4%BA%BA%E7%A7%B0%E4%BB%A3%E8%AF%8D.html"/>
<id>https://removeif.github.io/english-learn/%E8%8B%B1%E8%AF%AD%E8%AF%AD%E6%B3%95-%E4%BA%BA%E7%A7%B0%E4%BB%A3%E8%AF%8D.html</id>
<published>2020-03-09T17:40:16.000Z</published>
<updated>2025-01-06T09:42:34.418Z</updated>
<content type="html"><![CDATA[<h5 id="主格人称代词"><a href="#主格人称代词" class="headerlink" title="主格人称代词"></a>主格人称代词</h5><p> <strong>作用:主句或从句中做主语</strong></p><p> She is my daughter.</p><p> It was he who helped me when I was in trouble. <span id="more"></span></p><p> <strong>顺序: you, he and I ; We, you and they(I总是 放在最后)</strong></p><h6 id="表示泛指的主格代词"><a href="#表示泛指的主格代词" class="headerlink" title="表示泛指的主格代词"></a>表示泛指的主格代词</h6><p> <strong>one:任何人,包括说话人</strong></p><p> One is knocking at the door.(错误,说话人不算,所以不能用one)</p><p> Somebody is knocking at the door.</p><p> One后面使用的代词,美国一般用he,him,himself,his.</p><p> <strong>We/You/They 可以表示泛指:人们</strong></p><p> They say = People say or It is said</p><p> They say it is going to be a cold winter.</p><p><strong>she(her)的拟人化:表示country, motherland, moon, earth, ship.</strong></p><p> The ship lost most of her rigging in the storm</p><h5 id="宾格人称代词"><a href="#宾格人称代词" class="headerlink" title="宾格人称代词"></a>宾格人称代词</h5><p> <strong>作用:做宾语(也可做表语)</strong></p><p> I like her.</p><p> Who is it? It’s me.</p><p> <strong>注意:做表语时,后面跟定语从句时,需要用主格人称代词。</strong></p><p> It was he in whom we had the greatest faith(he在从句中做介词宾语)</p><p> <strong>主格和宾格人称代词可以做同位语:</strong></p><p> We teachers should be patient with students.</p><p> Our teachers are all nice to us students.</p><p><strong>做宾语时的位置</strong></p><p> <strong>直接宾语前:</strong> He bought me a pen as birthday gift.</p><p> <strong>直接宾语后:</strong>He bought a pen for me as a birthday gift ; I’ve lent much monery to him.</p><p> <strong>若直接宾语是人称代词,只能置后,但是不适用于不定代词:</strong></p><p> I will give it to you. </p><p> I‘ll show you something ; I didn’t give Rex any.</p><p> <strong>在短语动词中间:</strong>Hand them in ; throw it away ; pick it up.</p><p> 若是名词,则中间和后边都可:hand your papers in = hand in your papers.</p><h5 id="物主代词-名词性-形容词性"><a href="#物主代词-名词性-形容词性" class="headerlink" title="物主代词(名词性&形容词性)"></a>物主代词(名词性&形容词性)</h5><p><strong>作用:人称代词的所有格形式,表所有关系。</strong></p><p><strong>形容词性:不能单独使用:</strong> Your book is over there ; His sister is lovely.</p><p> 表强调时后+own:I wish I had my own house.</p><p><strong>名词性:单独使用;避免重复:</strong>This is not my book. Mine(=my book) is in my bog.</p><p> of + 名词性物主代词: a friend of mine ; a teacher of hers= a teacher of her own.</p><h5 id="反身代词"><a href="#反身代词" class="headerlink" title="反身代词"></a>反身代词</h5><p> <strong>必须主语宾语为同一人时,做宾语:</strong>God helps those who help themselves.</p><p> <strong>强调主语:</strong></p><p> He himself went to visit the old lady(他亲自去看望那个老太太的)</p><p> <strong>不产生歧义下可置后:</strong></p><p> He went to visit the old lady himself.</p><p> He spoke to the boss himself.(有歧义)</p><p> <strong>强调宾语:反身代词在宾语后</strong></p><p> He saw Tom himself(他看到Tom本人了)</p><p> I will send this gift to John himself(给john本人,不是通过转交)</p><p> <strong>介词+反身动词</strong></p><p> <strong>(1)by oneself:独自一人地</strong></p><p> I went there by myself(我自己一个人去了那里)</p><p> I went there myself(我亲自去了那)</p><p> <strong>(2)of oneself:自动地</strong></p><p> The door opened of itself(门自动地开了)</p><p>英语学习-<a href="https://github.com/removeif/english-learn">语法系列github仓库</a>,欢迎收藏star </p><p>参考文章:<br><a href="https://github.com/yizutianya/English_Grammar_Learning">参考链接</a></p>]]></content>
<summary type="html"><h5 id="主格人称代词"><a href="#主格人称代词" class="headerlink" title="主格人称代词"></a>主格人称代词</h5><p> <strong>作用:主句或从句中做主语</strong></p>
<p> She is my daughter.</p>
<p> It was he who helped me when I was in trouble.</p></summary>
<category term="English" scheme="https://removeif.github.io/categories/English/"/>
<category term="grammar" scheme="https://removeif.github.io/categories/English/grammar/"/>
<category term="English" scheme="https://removeif.github.io/tags/English/"/>
<category term="grammar" scheme="https://removeif.github.io/tags/grammar/"/>
</entry>
<entry>
<title>英语语法-名词从句</title>
<link href="https://removeif.github.io/english-learn/%E8%8B%B1%E8%AF%AD%E8%AF%AD%E6%B3%95-%E5%90%8D%E8%AF%8D%E4%BB%8E%E5%8F%A5.html"/>
<id>https://removeif.github.io/english-learn/%E8%8B%B1%E8%AF%AD%E8%AF%AD%E6%B3%95-%E5%90%8D%E8%AF%8D%E4%BB%8E%E5%8F%A5.html</id>
<published>2020-03-07T10:41:05.000Z</published>
<updated>2025-01-06T09:42:34.422Z</updated>
<content type="html"><![CDATA[<p><strong>概念:三种句子充当另外一句子的四种句子成分</strong></p><h4 id="1-陈述句:句前-that-当宾语时可省略"><a href="#1-陈述句:句前-that-当宾语时可省略" class="headerlink" title="1. 陈述句:句前 + that (当宾语时可省略)"></a>1. 陈述句:句前 + that (当宾语时可省略)</h4><p> a. That the moon itself does not give off lights is common knowledge.</p><p> b. I’ve learned (that) love, not time heals all wounds.<span id="more"></span></p><h4 id="2-一般疑问:变陈述句语序,句前-whether-当宾语时可用if"><a href="#2-一般疑问:变陈述句语序,句前-whether-当宾语时可用if" class="headerlink" title="2. 一般疑问:变陈述句语序,句前 + whether(当宾语时可用if)"></a>2. 一般疑问:变陈述句语序,句前 + whether(当宾语时可用if)</h4><p> a. My question is whether people will live on the moon someday.</p><p> b. I don’t know if/whether he needs my help. </p><h4 id="3-特殊疑问:变陈述句语序"><a href="#3-特殊疑问:变陈述句语序" class="headerlink" title="3. 特殊疑问:变陈述句语序"></a>3. 特殊疑问:变陈述句语序</h4><p> a. Money is what we are badly in need of. </p><table><thead><tr><th>句子类型</th><th>引导词</th><th>从句中作用</th></tr></thead><tbody><tr><td>陈述句</td><td>that</td><td>不做成分</td></tr><tr><td>一般疑问</td><td>whether, if</td><td>不做成分</td></tr><tr><td>特殊疑问</td><td>连接副词when, where, why, how连接代词who, whom, what; which, whose</td><td>连接副词做状语who, whom, what做主语/表语/宾语which, whose做定语,后+名词连用</td></tr></tbody></table><h4 id="it形式主语:it在句首,主句在后面"><a href="#it形式主语:it在句首,主句在后面" class="headerlink" title="it形式主语:it在句首,主句在后面"></a>it形式主语:it在句首,主句在后面</h4><p> a. It is common knowledge that the moon itself does not give off light.</p><p> b. It is not known where they came from.</p><h5 id="it形式宾语:复合宾语中:动词-it-宾补-宾语从句"><a href="#it形式宾语:复合宾语中:动词-it-宾补-宾语从句" class="headerlink" title="it形式宾语:复合宾语中:动词 + it + 宾补 + 宾语从句"></a>it形式宾语:复合宾语中:动词 + it + 宾补 + 宾语从句</h5><p> I find it encouraging how many young women are pursuing careers in</p><p>science.</p><p><strong>双宾语:</strong>Could you tell me where the post office is?</p><p><strong>介词后做宾语:</strong> You should vote for which candidate you assume best.</p><p><strong>形容词后做宾语:</strong> I am afraid that I can’t come.</p><p><strong>并列宾语从句中that不省略:</strong> I once read that “” and that “”.</p><h4 id="reason后的表语从句:引导词用that,不用because"><a href="#reason后的表语从句:引导词用that,不用because" class="headerlink" title="reason后的表语从句:引导词用that,不用because."></a>reason后的表语从句:引导词用that,不用because.</h4><p> The reason (why) he was dismissed is that he was careless and irresponsible.</p><p><strong>嵌套:</strong>a. I realized that what I said was not exactly what I meant to say.</p><p> b. The question is how what you have learned can be put into practice.</p><p>英语学习-<a href="https://github.com/removeif/english-learn">语法系列github仓库</a>,欢迎收藏star </p><p>参考文章:<br><a href="https://github.com/yizutianya/English_Grammar_Learning">参考链接</a></p>]]></content>
<summary type="html"><p><strong>概念:三种句子充当另外一句子的四种句子成分</strong></p>
<h4 id="1-陈述句:句前-that-当宾语时可省略"><a href="#1-陈述句:句前-that-当宾语时可省略" class="headerlink" title="1. 陈述句:句前 + that (当宾语时可省略)"></a>1. 陈述句:句前 + that (当宾语时可省略)</h4><p> a. That the moon itself does not give off lights is common knowledge.</p>
<p> b. I’ve learned (that) love, not time heals all wounds.</p></summary>
<category term="English" scheme="https://removeif.github.io/categories/English/"/>
<category term="grammar" scheme="https://removeif.github.io/categories/English/grammar/"/>
<category term="English" scheme="https://removeif.github.io/tags/English/"/>
<category term="grammar" scheme="https://removeif.github.io/tags/grammar/"/>
</entry>
<entry>
<title>英语语法-句子简化</title>
<link href="https://removeif.github.io/english-learn/%E8%8B%B1%E8%AF%AD%E8%AF%AD%E6%B3%95-%E5%8F%A5%E5%AD%90%E7%AE%80%E5%8C%96.html"/>
<id>https://removeif.github.io/english-learn/%E8%8B%B1%E8%AF%AD%E8%AF%AD%E6%B3%95-%E5%8F%A5%E5%AD%90%E7%AE%80%E5%8C%96.html</id>
<published>2020-03-07T10:40:57.000Z</published>
<updated>2025-01-06T09:42:34.422Z</updated>
<content type="html"><![CDATA[<h4 id="名词从句"><a href="#名词从句" class="headerlink" title="名词从句"></a>名词从句</h4><p><strong>逻辑思路:从句—>动名词or不定式</strong></p><h5 id="that引导的主语从句:动名词当主语"><a href="#that引导的主语从句:动名词当主语" class="headerlink" title="that引导的主语从句:动名词当主语"></a>that引导的主语从句:动名词当主语</h5><p> It surprised us that John won the marathon.</p><p> John’s winning the marthon suprised us. <span id="more"></span></p><h5 id="that引导的同谓语从句:-of-变成复合结构"><a href="#that引导的同谓语从句:-of-变成复合结构" class="headerlink" title="that引导的同谓语从句:+ of 变成复合结构"></a>that引导的同谓语从句:+ of 变成复合结构</h5><p> There was no chance that Davy would come from the battle alive.</p><p> There was no chance of Davy coming from the battle alive.</p><h5 id="that引导的宾语从句:转换动名词or不定式-取决于主句谓语动词"><a href="#that引导的宾语从句:转换动名词or不定式-取决于主句谓语动词" class="headerlink" title="that引导的宾语从句:转换动名词or不定式(取决于主句谓语动词)"></a>that引导的宾语从句:转换动名词or不定式(取决于主句谓语动词)</h5><p> a. I hope that I can drive to work in my own car.</p><p> I hope to drive to work in my own car.</p><p> b. I consider that I will emigrate to America in the future.</p><p> I consider emigrating to America in the future.</p><p> c. Jane’s mother insisted that she should go swimming with her brother.</p><p> Jane’s mother insisted on her going swimming with her brother.</p><h5 id="名词从句不定式简化:"><a href="#名词从句不定式简化:" class="headerlink" title="名词从句不定式简化:"></a>名词从句不定式简化:</h5><p> a. I don’t know what I should do.</p><p> I don’t know what to do.</p><p> b. Tell me how I can get to the bus station.</p><p> Tell me how to get to the bus station. </p><h4 id="定语从句"><a href="#定语从句" class="headerlink" title="定语从句"></a>定语从句</h4><p><strong>逻辑思路:从句—>短语(只有关系词做主语时可简化)</strong></p><p><strong>从句有be动词:去掉be动词and关系代词</strong></p><h5 id="主动:现在分词;被动:过去分词;形容词短语也可"><a href="#主动:现在分词;被动:过去分词;形容词短语也可" class="headerlink" title="主动:现在分词;被动:过去分词;形容词短语也可"></a>主动:现在分词;被动:过去分词;形容词短语也可</h5><p> a. The man who is standing at the gate is my English teacher.</p><p> The man standing at the gate is my English teacher.</p><p> b. Books that are written in English are more expensive.</p><p> Books written in English are more expensive.</p><p> c. The people who were responsible for the incident were all punished.</p><p> The people responsible for the indident were all punished.</p><h5 id="从句没有be动词:去掉关系代词;动词—-现在分词"><a href="#从句没有be动词:去掉关系代词;动词—-现在分词" class="headerlink" title="从句没有be动词:去掉关系代词;动词—>现在分词"></a>从句没有be动词:去掉关系代词;动词—>现在分词</h5><p> a. They live in a room that faces the south.</p><p> They live in a room facing the south.</p><p> b. English has an alphabet that consists of 26 letters.</p><p> English has an alphabet consisting of 26 letters.</p><h5 id="不定式替换:the-only,the-last,the-next,序数词,最高级修饰的名词"><a href="#不定式替换:the-only,the-last,the-next,序数词,最高级修饰的名词" class="headerlink" title="不定式替换:the only,the last,the next,序数词,最高级修饰的名词"></a>不定式替换:the only,the last,the next,序数词,最高级修饰的名词</h5><p> a. The only one that understands me.</p><p> The only one to understand me.</p><p> b. The next train that arrives is from New York.</p><p> The next train to arrive is from New York.</p><p> c. Jango was the second person that fell into this trap.</p><p> Jango was the second person to fall into this trap.</p><h4 id="状语从句"><a href="#状语从句" class="headerlink" title="状语从句"></a>状语从句</h4><p><strong>注意:主句从句的主语相同时,才可以简化。</strong></p><p><strong>有be动词:去掉be动词(常见:时间,地点,条件,让步)</strong></p><h5 id="主动:现在分词;被动:过去分词;形容词or名词短语也可"><a href="#主动:现在分词;被动:过去分词;形容词or名词短语也可" class="headerlink" title="主动:现在分词;被动:过去分词;形容词or名词短语也可"></a>主动:现在分词;被动:过去分词;形容词or名词短语也可</h5><p> a. Metals expand when heated and contract when (they are) cooled.</p><p> b. When (he was) a student in the university, he read a lot.</p><p> c. while (he was) waitting, he took out a magazine to read.</p><p> d. A tiger can’t be tamed unless (it is) caught very young. </p><h5 id="没有be动词:从句主语省略,动词变成现在分词"><a href="#没有be动词:从句主语省略,动词变成现在分词" class="headerlink" title="没有be动词:从句主语省略,动词变成现在分词"></a>没有be动词:从句主语省略,动词变成现在分词</h5><p> a. Since I came to Beijing, I have made many new friends.</p><p> Since coming to Beijing, I have made many new friends.</p><p> b. After I finished my homework, I fed the dog.</p><p> After finishing my homework, I fed the dog.</p><p> c. After he jumped out of a boat, the man was bitten by a shark.</p><p> After jumping out of a boat, the man was bitten by a shark.</p><p>英语学习-<a href="https://github.com/removeif/english-learn">语法系列github仓库</a>,欢迎收藏star </p><p>参考文章:<br><a href="https://github.com/yizutianya/English_Grammar_Learning">参考链接</a></p>]]></content>
<summary type="html"><h4 id="名词从句"><a href="#名词从句" class="headerlink" title="名词从句"></a>名词从句</h4><p><strong>逻辑思路:从句—&gt;动名词or不定式</strong></p>
<h5 id="that引导的主语从句:动名词当主语"><a href="#that引导的主语从句:动名词当主语" class="headerlink" title="that引导的主语从句:动名词当主语"></a>that引导的主语从句:动名词当主语</h5><p> It surprised us that John won the marathon.</p>
<p> John’s winning the marthon suprised us.</p></summary>
<category term="English" scheme="https://removeif.github.io/categories/English/"/>
<category term="grammar" scheme="https://removeif.github.io/categories/English/grammar/"/>
<category term="English" scheme="https://removeif.github.io/tags/English/"/>
<category term="grammar" scheme="https://removeif.github.io/tags/grammar/"/>
</entry>
<entry>
<title>英语语法-介词</title>
<link href="https://removeif.github.io/english-learn/%E8%8B%B1%E8%AF%AD%E8%AF%AD%E6%B3%95-%E4%BB%8B%E8%AF%8D.html"/>
<id>https://removeif.github.io/english-learn/%E8%8B%B1%E8%AF%AD%E8%AF%AD%E6%B3%95-%E4%BB%8B%E8%AF%8D.html</id>
<published>2020-03-02T19:16:44.000Z</published>
<updated>2025-01-06T09:42:34.422Z</updated>
<content type="html"><![CDATA[<h3 id="介词"><a href="#介词" class="headerlink" title="介词"></a>介词</h3><p><strong>特点:</strong>不能单独使用,后面需带宾语(名词,代词,数词,动名词,动名词短语,名词从句)<br><strong>搭配:</strong>在介词前的词:动词(depend on)名词(pay attention to)形容词(be kind to) <span id="more"></span><br><strong>充当:</strong></p><p> 与其宾语构成介词短语后可充当主语,补足语 ,定语,状语</p><p><strong>作用:词与词之间的表示关系</strong></p><h4 id="种类:"><a href="#种类:" class="headerlink" title="种类:"></a>种类:</h4><h5 id="简单介词(at-by-for-from-in-near-of-off-on)"><a href="#简单介词(at-by-for-from-in-near-of-off-on)" class="headerlink" title="简单介词(at, by, for, from, in,near, of, off, on)"></a>简单介词(at, by, for, from, in,near, of, off, on)</h5><h5 id="复合介词"><a href="#复合介词" class="headerlink" title="复合介词"></a>复合介词</h5><p> 简单链接:inside, into, onto, out of, outside, throughout, upon, within, without</p><p> 搭配连用:as to, from above, from behind, from beneath, from under, until after</p><h5 id="介词短语:"><a href="#介词短语:" class="headerlink" title="介词短语:"></a>介词短语:</h5><p> at the cost of, at the mercy of, at odds with, by means of, by reason of, by virtue of,</p><p> by way of, in place of, in favor of, in spite of, with an eye to. </p><p> 关于:in/with reference to, in/with respect to, in/ with regard to</p><h4 id="时间介词:"><a href="#时间介词:" class="headerlink" title="时间介词:"></a>时间介词:</h4><h5 id="1-at-in-on"><a href="#1-at-in-on" class="headerlink" title="1.at, in, on"></a>1.at, in, on</h5><h6 id="1-at-时间点"><a href="#1-at-时间点" class="headerlink" title="1)at(时间点)"></a>1)at(时间点)</h6><p> a.特定时刻:at nine after ten</p><p> b.不确定时刻:at night, at dawn, at midnight, at that time, at the moment, at Christmas</p><p> c.年龄段:</p><p> at the age of eight/at eight</p><p> He got married at twenty</p><h6 id="2-in-时间段"><a href="#2-in-时间段" class="headerlink" title="2)in(时间段)"></a>2)in(时间段)</h6><p> a.长时间段</p><p> in the morning/afternoon/evening</p><p> in spring/summer/autumn/winter</p><p> in the past, in the past ten years</p><p> in the twenty-first cenfury</p><p> a man in his thirties</p><p> b.在时间之内/后,表将来时</p><p> He said he would come back in a month</p><p> The train is leaving in a minute</p><p> c.in+动名词:在做…过程中</p><p> In crossing the river, we caught some fish.</p><p> In working, we can learn a lot.</p><p> d.几月:in October</p><h6 id="3-on-表示具体日期"><a href="#3-on-表示具体日期" class="headerlink" title="3)on(表示具体日期)"></a>3)on(表示具体日期)</h6><p> a.具体日期和星期</p><p> on Monday On my birthday</p><p> b.特定某天上午、下午等</p><p> On the night of December 31,1999</p><p> On the eve of christmas/New Year</p><p> On a hot midnight in July</p><p> c.在第几天</p><p> On his first day to school.</p><p> On the tenth day I was in Beijing. </p><p> d.on+动名词 or 名词 = as soon as:一…就…</p><p> On hearing the bad news, she burst into tears.</p><p> On arriving, I came directly to visit you.</p><p> The first thing I did on arrival of Beijing was visit him.</p><p><strong>at the beginning of 在..的开头</strong></p><p> at the begining of a book there is often a table of contents.</p><p> at the begining of the concert.</p><p> at the beginning of January. </p><p><strong>in the begining:at first = in the early stages</strong></p><p> In the begining, I wrote to my family regularly. later I just gave up</p><p><strong>at the end of</strong></p><p> But at the end of this process, unfortunately, the students are none the wiser.</p><p> At the end of abook there may be an index</p><p> At the end of the concert at the end of January</p><p><strong>in the end:eventually = at last:最终….</strong></p><p> Jim couldn’t decide where to go for his holidays. He didn’t go anywhere in the end.</p><p><strong>有last/next/this/every不再加介词</strong></p><p> I’ll see your next Friday.</p><p><strong>during for</strong></p><p> during在…期间内,强调这时间内发生了什么 for表示延续时间的长短</p><p> I had lived in the countryside for 8 years before I moved to Beijing.</p><p> I studied in this university for 4 years. During that time most of my time was spent in learning English.</p><p> My father was in hospital for six weeks during the summer. </p><p><strong>during接表示一段时间的名词:stay, visit,travel</strong></p><p> During my visit to China</p><p> During the travel to the south</p><p> During the Middle ages</p><h6 id="for-时间段"><a href="#for-时间段" class="headerlink" title="for+时间段"></a>for+时间段</h6><p> for six years for two months for ever for two hours</p><h6 id="from"><a href="#from" class="headerlink" title="from"></a>from</h6><p> 和to 或 till/untill连用</p><p> Most people work from nine to five.</p><h6 id="since"><a href="#since" class="headerlink" title="since"></a>since</h6><p> 和时间点连用,从那一时刻起。现在完成时,过去完成时连用</p><p> He has been here since last Sunday</p><p> I haven’t seen him since two years ago</p><p> I haven’t seen him for two years</p><p> It’s two years since I last saw him</p><h6 id="for"><a href="#for" class="headerlink" title="for"></a>for</h6><p>和时间段连用,表示动作延续到说话的那一刻。现在完成时,过去完成时连用</p><p> I have lived here for a year</p><p> I have lived here since this time last year </p><p>before, after, till/until(可做介词接短语,可做连词接从句)</p><p> 后接时间点,某时刻前(before)某时刻后(after)直到某一时刻(till/until)</p><p> We finished the work before 10 o’ clock</p><p> I’ll wait for you till 10 o’ clock</p><h6 id="till-until特点"><a href="#till-until特点" class="headerlink" title="till/until特点"></a>till/until特点</h6><p> 延续性句子谓语(肯定)+till/untill+时间点(若是从句,则从句中谓语动词为短暂性动词)</p><p> 短暂性句子谓语(否定)+till/untill+时间点(若是从句,则从句中谓语动词为短暂性动词)</p><p> He didn’t finish the work untill 10 o’ clock(finish短暂动词,用否定)</p><p> He didn’t leave the office till 12 o’ clock</p><p> He will stay here until next Sunday(stay延续性动词,用肯定)</p><h6 id="by"><a href="#by" class="headerlink" title="by"></a>by</h6><p> a.no later than:不迟于某个时间,到了某个时间</p><p> by the end of next year</p><p> b.by引导时间状语常与将来完成时 or 过去完成时连用</p><p> By the end of next year I’ll have learned 2000 words</p><p> By the end of last year I had learned 2000 words</p><h4 id="方位介词"><a href="#方位介词" class="headerlink" title="方位介词"></a>方位介词</h4><h5 id="at-in"><a href="#at-in" class="headerlink" title="at, in"></a>at, in</h5><p> <strong>at表示小地方</strong></p><p> at home, at the office, ata school, at the bridge, at the crossroads, at the bus-stop</p><p> at the doctor’s, at the hairdresser’s</p><p> <strong>in表示大地方</strong></p><p> in a country, in a town, in a village, in the street, in the forest, in a field, in a desert</p><p> <strong>其他情况</strong></p><p> in a line/in a row/in a queue</p><p> in a photo/in a picture</p><p> in a mirror</p><p> in the sky/in the world</p><p> in a book/in a newspaper/in a magazine/in a letter</p><p> in the front/back row(at the front/back)</p><p> in the front/back of the car</p><p> at the front/back of the building/cinema/classroom</p><h5 id="谈论建筑"><a href="#谈论建筑" class="headerlink" title="谈论建筑"></a>谈论建筑</h5><p> <strong>at表示事情发生场合</strong></p><p> I met him at the cinema last night.</p><p> <strong>in表示建筑物本身</strong></p><p> I enjoyed the film but it was very cold in the cinema</p><p> <strong>in强调在建筑里,at包括建筑物周围及里面</strong></p><p> at the restaurant(可以是餐馆内,也可以是在餐馆附近的某个地方)</p><p> in the restaurant(在餐馆里)</p><p> at the cinema(在电影院,不一定在里面)</p><p> in the cinema(在里面)</p><p> There were a lot of people in the shop, It was very crowed</p><p> Go along this road, then turn left at the shop</p><h5 id="on-over-above"><a href="#on-over-above" class="headerlink" title="on, over, above"></a>on, over, above</h5><p> <strong>on表示两者接触</strong></p><p> Put away the books on the desk</p><p> The dictionary on the table is not mine</p><p> There is some water in the bottle</p><p> There is a label on the bottle</p><p> There is somebody at the door. Shall I go and see who it is?</p><p> There is a notice on the door. It says “Do not disturb”</p><p> <strong>on的其他情况</strong></p><p> on the left/on the right</p><p> on the first/second floor</p><p> on a map</p><p> on the page/on page seven(at the top/bottom of the page)</p><p> on the menu</p><p> on the list</p><p> on a farm</p><p> on the way to school</p><p> on the corner of street, in the corner of the room</p><h5 id="over不仅接触,还有覆盖的含义"><a href="#over不仅接触,还有覆盖的含义" class="headerlink" title="over不仅接触,还有覆盖的含义"></a>over不仅接触,还有覆盖的含义</h5><p> Spread the cloth over the table</p><p> Mon put a rug over me when I was asleep</p><h5 id="over还可以表示正上方"><a href="#over还可以表示正上方" class="headerlink" title="over还可以表示正上方"></a>over还可以表示正上方</h5><p> There is a bridge over the river</p><p> There is a lamp over the desk</p><h5 id="above仅表示上下位关系,不接触,也不是正上方"><a href="#above仅表示上下位关系,不接触,也不是正上方" class="headerlink" title="above仅表示上下位关系,不接触,也不是正上方"></a>above仅表示上下位关系,不接触,也不是正上方</h5><p> The sun rose above the horizon</p><p> There is a bridge above the river</p><p> He is over me(He is my immediate superior)</p><p> He is above me</p><h5 id="below-under-beneath"><a href="#below-under-beneath" class="headerlink" title="below,under,beneath"></a>below,under,beneath</h5><p> under在下方,可接触,可不接触</p><p> I put the money under the mattess</p><p> The dog is groveling under the table</p><h5 id="below表示两个表面之间间隔距离"><a href="#below表示两个表面之间间隔距离" class="headerlink" title="below表示两个表面之间间隔距离"></a>below表示两个表面之间间隔距离</h5><p> They live below us</p><h5 id="beneath可以替换under,但是偏向抽象含义"><a href="#beneath可以替换under,但是偏向抽象含义" class="headerlink" title="beneath可以替换under,但是偏向抽象含义"></a>beneath可以替换under,但是偏向抽象含义</h5><p> He would think it beneath him to tell a lie</p><p> She married beneath her</p><h4 id="手段介词"><a href="#手段介词" class="headerlink" title="手段介词"></a>手段介词</h4><h5 id="by-1"><a href="#by-1" class="headerlink" title="by"></a>by</h5><p> <strong>表示行为方式</strong></p><p> send something by post</p><p> do something by hand</p><p> pay by check/by credit card(pay in cash)</p><p> <strong>某事发生:by mistake/by accident/by chance(on purpose)</strong></p><p> <strong>表示交通工具</strong></p><p> by car, by train, by plane/air, by boat/sea/ship, by bus, </p><p> by bicycle, by metro/subway/underground(on foot)</p><p> by car(in a car, im my car, in the car)</p><p> I don’t mind going by car but I don’t want to go in your car</p><p> <strong>car, taxi前用介词in</strong></p><p> They didn’t come in their car. They came in a taxi.</p><p> <strong>自行车和公共交通设施前用on</strong></p><p> on the train/by train, on his bicycle/by bicycle</p><p> <strong>表示通过 某种手段达到预期效果(与with区别)</strong></p><p> We succeeded by cooperating with them</p><p> Our mission is to help our clients achieve their business goals by providing a service</p><p> for the timely delivery of qualified staff to support their operational needs.</p><h5 id="with"><a href="#with" class="headerlink" title="with"></a>with</h5><p> <strong>表示用具体的工具做某事</strong></p><p> I killed a fly with a flyflap</p><p> We can see with our eyes and write with our hands</p><h5 id="in"><a href="#in" class="headerlink" title="in"></a>in</h5><p> <strong>表示以某种方式做某事</strong></p><p> Write in pencil/in ink</p><p> Express this in your own words</p><p> Speak in a low voice</p><p> Pay in installments</p><h5 id="through"><a href="#through" class="headerlink" title="through"></a>through</h5><p> <strong>与by相近,through一般多根名词连用, by多跟 动名词连用</strong></p><p> they talked to each other through an interpreter.</p><p>英语学习-<a href="https://github.com/removeif/english-learn">语法系列github仓库</a>,欢迎收藏star </p><p>参考文章:<br><a href="https://github.com/yizutianya/English_Grammar_Learning">参考链接</a></p>]]></content>
<summary type="html"><h3 id="介词"><a href="#介词" class="headerlink" title="介词"></a>介词</h3><p><strong>特点:</strong>不能单独使用,后面需带宾语(名词,代词,数词,动名词,动名词短语,名词从句)<br><strong>搭配:</strong>在介词前的词:动词(depend on)名词(pay attention to)形容词(be kind to)</p></summary>
<category term="English" scheme="https://removeif.github.io/categories/English/"/>
<category term="grammar" scheme="https://removeif.github.io/categories/English/grammar/"/>
<category term="English" scheme="https://removeif.github.io/tags/English/"/>
<category term="grammar" scheme="https://removeif.github.io/tags/grammar/"/>
</entry>
</feed>