-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Snailclimb/master
增加IOC功能
- Loading branch information
Showing
52 changed files
with
764 additions
and
248 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
task applyGitHooks(type: Copy) { | ||
// TODO remove | ||
def pushFile = rootProject.file(".git/hooks/pre-push") | ||
if (pushFile.exists()) pushFile.delete() | ||
static def isWindows() { | ||
return org.gradle.internal.os.OperatingSystem.current().isWindows() | ||
} | ||
|
||
task applyGitHooks(type: Copy) { | ||
from { rootProject.file("config/git-hooks/pre-commit") } | ||
into { rootProject.file(".git/hooks") } | ||
Runtime.getRuntime().exec("chmod -R +x .git/hooks/") | ||
if (!isWindows()) { | ||
println "not on windows" | ||
Runtime.getRuntime().exec("chmod -R +x .git/hooks/") | ||
} else { | ||
println "windows" | ||
} | ||
} | ||
compileJava.dependsOn applyGitHooks |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.github.demo.sms; | ||
|
||
import com.github.jsoncat.annotation.ioc.Component; | ||
|
||
/** | ||
* @author shuang.kou | ||
* @createTime 2020年09月30日 15:43:00 | ||
**/ | ||
@Component(name = "aliSmsServiceImpl") | ||
public class AliSmsServiceImpl implements SmsService { | ||
|
||
|
||
@Override | ||
public String send(SmsDto smsDto) { | ||
System.out.println("send message to " + smsDto.getPhone()); | ||
return AliSmsServiceImpl.class.getSimpleName(); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/com/github/demo/sms/QiNiuSmsServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.github.demo.sms; | ||
|
||
import com.github.jsoncat.annotation.ioc.Component; | ||
|
||
/** | ||
* @author shuang.kou | ||
* @createTime 2020年09月30日 15:43:00 | ||
**/ | ||
@Component(name = "qiNiuSmsServiceImpl") | ||
public class QiNiuSmsServiceImpl implements SmsService { | ||
|
||
|
||
@Override | ||
public String send(SmsDto smsDto) { | ||
System.out.println("send message to " + smsDto.getPhone()); | ||
return QiNiuSmsServiceImpl.class.getSimpleName(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.github.demo.sms; | ||
|
||
import com.github.jsoncat.annotation.ioc.Autowired; | ||
import com.github.jsoncat.annotation.springmvc.PostMapping; | ||
import com.github.jsoncat.annotation.ioc.Qualifier; | ||
import com.github.jsoncat.annotation.springmvc.RequestBody; | ||
import com.github.jsoncat.annotation.springmvc.RestController; | ||
|
||
/** | ||
* @author shuang.kou | ||
* @createTime 2020年09月30日 15:43:00 | ||
**/ | ||
@RestController("/sms") | ||
public class SmsController { | ||
@Autowired | ||
@Qualifier("aliSmsServiceImpl") | ||
private SmsService smsService; | ||
|
||
@PostMapping("/send") | ||
public String send(@RequestBody SmsDto smsDto) { | ||
return smsService.send(smsDto); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.github.demo.sms; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
/** | ||
* @author shuang.kou | ||
* @createTime 2020年09月30日 7:19:00 | ||
**/ | ||
@Data | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class SmsDto { | ||
private String phone; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.github.demo.sms; | ||
|
||
/** | ||
* @author shuang.kou | ||
* @createTime 2020年09月30日 15:43:00 | ||
**/ | ||
public interface SmsService { | ||
String send(SmsDto smsDto); | ||
} |
2 changes: 1 addition & 1 deletion
2
src/main/java/com/github/demo/User.java → src/main/java/com/github/demo/user/User.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package com.github.demo; | ||
package com.github.demo.user; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.github.demo.user; | ||
|
||
import com.github.jsoncat.annotation.ioc.Autowired; | ||
import com.github.jsoncat.annotation.springmvc.GetMapping; | ||
import com.github.jsoncat.annotation.springmvc.PathVariable; | ||
import com.github.jsoncat.annotation.springmvc.PostMapping; | ||
import com.github.jsoncat.annotation.springmvc.RequestBody; | ||
import com.github.jsoncat.annotation.springmvc.RequestParam; | ||
import com.github.jsoncat.annotation.springmvc.RestController; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* @author shuang.kou | ||
* @createTime 2020年09月24日 14:52:00 | ||
**/ | ||
@RestController("/user") | ||
public class UserController { | ||
@Autowired | ||
private UserService userService; | ||
|
||
@GetMapping | ||
public User get(@RequestParam("name") String name, @RequestParam("des") String des, @RequestParam("age") Integer age) { | ||
return new User(name, des, age); | ||
} | ||
|
||
@GetMapping("/{id}") | ||
public User get(@PathVariable("id") Integer id) { | ||
return userService.get(id); | ||
} | ||
|
||
@PostMapping | ||
public List<User> create(@RequestBody UserDto userDto) { | ||
return userService.create(userDto); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
src/main/java/com/github/demo/UserDto.java → ...in/java/com/github/demo/user/UserDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package com.github.demo; | ||
package com.github.demo.user; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.github.demo.user; | ||
|
||
import com.github.jsoncat.annotation.ioc.Component; | ||
import com.github.jsoncat.annotation.springmvc.RequestBody; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* @author shuang.kou | ||
* @createTime 2020年09月30日 00:14:00 | ||
**/ | ||
@Component | ||
public class UserService { | ||
private Integer id = 1; | ||
|
||
private final Map<Integer, User> users = new HashMap<Integer, User>() { | ||
{ | ||
put(1, new User("盖伦", "德玛西亚", 22)); | ||
} | ||
}; | ||
|
||
public User get(Integer id) { | ||
return users.get(id); | ||
} | ||
|
||
public List<User> create(@RequestBody UserDto userDto) { | ||
users.put(++id, new User(userDto.getName(), userDto.getDes(), userDto.getAge())); | ||
return new ArrayList<>(users.values()); | ||
|
||
} | ||
|
||
public void say() { | ||
System.out.println("UserService say 你真帅!"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/main/java/com/github/jsoncat/annotation/ioc/Autowired.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.github.jsoncat.annotation.ioc; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Target(ElementType.FIELD) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Documented | ||
public @interface Autowired { | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/github/jsoncat/annotation/ioc/Component.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.github.jsoncat.annotation.ioc; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Target(ElementType.TYPE) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Documented | ||
public @interface Component { | ||
String name() default ""; | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/github/jsoncat/annotation/ioc/Qualifier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.github.jsoncat.annotation.ioc; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Inherited; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.TYPE, ElementType.ANNOTATION_TYPE}) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Inherited | ||
@Documented | ||
public @interface Qualifier { | ||
String value() default ""; | ||
} |
2 changes: 1 addition & 1 deletion
2
...github/jsoncat/annotation/GetMapping.java → ...ncat/annotation/springmvc/GetMapping.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...thub/jsoncat/annotation/PathVariable.java → ...at/annotation/springmvc/PathVariable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ithub/jsoncat/annotation/PostMapping.java → ...cat/annotation/springmvc/PostMapping.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ithub/jsoncat/annotation/RequestBody.java → ...cat/annotation/springmvc/RequestBody.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...thub/jsoncat/annotation/RequestParam.java → ...at/annotation/springmvc/RequestParam.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.