Skip to content

Commit 62ec6bd

Browse files
committed
ApiBoot Resource Load Sample上传.
1 parent 43d1d4c commit 62ec6bd

File tree

6 files changed

+338
-0
lines changed

6 files changed

+338
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Copyright [2019] [恒宇少年 - 于起宇]
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
~
17+
-->
18+
19+
<project xmlns="http://maven.apache.org/POM/4.0.0"
20+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
21+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
22+
<parent>
23+
<artifactId>api-boot-samples</artifactId>
24+
<groupId>org.minbox.framework</groupId>
25+
<version>2.0.4.RC1</version>
26+
</parent>
27+
<modelVersion>4.0.0</modelVersion>
28+
<description>
29+
ApiBoot Resource Load 示例
30+
</description>
31+
<artifactId>api-boot-sample-resource-load</artifactId>
32+
<dependencies>
33+
<!--Web-->
34+
<dependency>
35+
<groupId>org.springframework.boot</groupId>
36+
<artifactId>spring-boot-starter-web</artifactId>
37+
</dependency>
38+
<!--ApiBoot Resource Load-->
39+
<dependency>
40+
<groupId>org.minbox.framework</groupId>
41+
<artifactId>api-boot-starter-resource-load</artifactId>
42+
</dependency>
43+
44+
</dependencies>
45+
<!--ApiBoot版本依赖-->
46+
<dependencyManagement>
47+
<dependencies>
48+
<dependency>
49+
<groupId>org.minbox.framework</groupId>
50+
<artifactId>api-boot-dependencies</artifactId>
51+
<version>2.0.4.RC1</version>
52+
<type>pom</type>
53+
<scope>import</scope>
54+
</dependency>
55+
</dependencies>
56+
</dependencyManagement>
57+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright [2019] [恒宇少年 - 于起宇]
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
package org.minbox.framework.api.boot.sample;
19+
20+
import org.slf4j.Logger;
21+
import org.slf4j.LoggerFactory;
22+
import org.springframework.boot.SpringApplication;
23+
import org.springframework.boot.autoconfigure.SpringBootApplication;
24+
25+
/**
26+
* ApiBoot Resource Load
27+
*
28+
* @author:恒宇少年 - 于起宇
29+
* <p>
30+
* DateTime:2019-04-15 11:43
31+
* Blog:http://blog.yuqiyu.com
32+
* WebSite:http://www.jianshu.com/u/092df3f77bca
33+
* Gitee:https://gitee.com/hengboy
34+
* GitHub:https://github.com/hengboy
35+
*/
36+
@SpringBootApplication
37+
public class ResourceLoadSampleApplication {
38+
/**
39+
* logger instance
40+
*/
41+
static Logger logger = LoggerFactory.getLogger(ResourceLoadSampleApplication.class);
42+
43+
public static void main(String[] args) {
44+
SpringApplication.run(ResourceLoadSampleApplication.class, args);
45+
logger.info("「「「「「ApiBoot Resource Load 示例启动成功.」」」」」");
46+
}
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright [2019] [恒宇少年 - 于起宇]
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
package org.minbox.framework.api.boot.sample;
19+
20+
import org.springframework.beans.factory.annotation.Autowired;
21+
import org.springframework.web.bind.annotation.GetMapping;
22+
import org.springframework.web.bind.annotation.RestController;
23+
24+
import java.util.List;
25+
import java.util.Map;
26+
27+
/**
28+
* ApiBoot Resource Load Sample Controller
29+
*
30+
* @author:恒宇少年 - 于起宇
31+
* <p>
32+
* DateTime:2019-04-15 11:47
33+
* Blog:http://blog.yuqiyu.com
34+
* WebSite:http://www.jianshu.com/u/092df3f77bca
35+
* Gitee:https://gitee.com/hengboy
36+
* GitHub:https://github.com/hengboy
37+
*/
38+
@RestController
39+
public class ResourceLoadSampleController {
40+
41+
@Autowired
42+
private ResourceLoadSampleService resourceLoadSampleService;
43+
44+
/**
45+
* single sample
46+
*
47+
* @return
48+
*/
49+
@GetMapping(value = "/single")
50+
public ResourceLoadSampleService.SampleUserInfo singleSample() {
51+
return resourceLoadSampleService.singleObjectSample();
52+
}
53+
54+
/**
55+
* list sample
56+
*
57+
* @return
58+
*/
59+
@GetMapping(value = "/list")
60+
public List<ResourceLoadSampleService.SampleUserInfo> listSample() {
61+
return resourceLoadSampleService.listSample();
62+
}
63+
64+
/**
65+
* map sample
66+
*
67+
* @return
68+
*/
69+
@GetMapping(value = "/map")
70+
public Map<String, ResourceLoadSampleService.SampleUserInfo> mapSample() {
71+
return resourceLoadSampleService.mapSample();
72+
}
73+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
* Copyright [2019] [恒宇少年 - 于起宇]
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
package org.minbox.framework.api.boot.sample;
19+
20+
import lombok.Data;
21+
import org.minbox.framework.api.boot.plugin.resource.load.annotation.ResourceField;
22+
import org.minbox.framework.api.boot.plugin.resource.load.annotation.ResourceFields;
23+
import org.minbox.framework.api.boot.plugin.resource.load.annotation.ResourceLoad;
24+
import org.springframework.stereotype.Service;
25+
26+
import java.util.ArrayList;
27+
import java.util.HashMap;
28+
import java.util.List;
29+
import java.util.Map;
30+
31+
/**
32+
* @author:恒宇少年 - 于起宇
33+
* <p>
34+
* DateTime:2019-04-15 11:48
35+
* Blog:http://blog.yuqiyu.com
36+
* WebSite:http://www.jianshu.com/u/092df3f77bca
37+
* Gitee:https://gitee.com/hengboy
38+
* GitHub:https://github.com/hengboy
39+
*/
40+
@Service
41+
public class ResourceLoadSampleService {
42+
/**
43+
* 返回值为单个对象的示例
44+
*
45+
* @return
46+
*/
47+
@ResourceLoad
48+
@ResourceFields({
49+
@ResourceField(name = "headImage", source = "userId", type = "HEAD_IMAGE"),
50+
@ResourceField(name = "shortImage", source = "userId", type = "SHORT_IMAGE")
51+
})
52+
public SampleUserInfo singleObjectSample() {
53+
return new SampleUserInfo("yuqiyu", 24);
54+
}
55+
56+
/**
57+
* 返回值为list集合的示例
58+
*
59+
* @return
60+
*/
61+
@ResourceLoad
62+
@ResourceFields({
63+
@ResourceField(name = "headImage", source = "userId", type = "HEAD_IMAGE"),
64+
@ResourceField(name = "shortImage", source = "userId", type = "SHORT_IMAGE")
65+
})
66+
public List<SampleUserInfo> listSample() {
67+
List<SampleUserInfo> users = new ArrayList();
68+
users.add(new SampleUserInfo("yuqiyu", 24));
69+
users.add(new SampleUserInfo("hengboy", 24));
70+
return users;
71+
}
72+
73+
/**
74+
* 返回值为map集合的示例
75+
*
76+
* @return
77+
*/
78+
@ResourceLoad
79+
@ResourceFields({
80+
@ResourceField(name = "headImage", source = "userId", type = "HEAD_IMAGE"),
81+
@ResourceField(name = "shortImage", source = "userId", type = "SHORT_IMAGE")
82+
})
83+
public Map<String, SampleUserInfo> mapSample() {
84+
Map<String, SampleUserInfo> users = new HashMap<>(2);
85+
users.put("yuqiyu", new SampleUserInfo("yuqiyu", 24));
86+
users.put("hengboy", new SampleUserInfo("hengboy", 24));
87+
return users;
88+
}
89+
90+
/**
91+
* 示例对象
92+
*/
93+
@Data
94+
class SampleUserInfo {
95+
public SampleUserInfo(String userId, int age) {
96+
this.userId = userId;
97+
this.age = age;
98+
}
99+
100+
private String userId;
101+
private String headImage;
102+
private String shortImage;
103+
private int age;
104+
}
105+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright [2019] [恒宇少年 - 于起宇]
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
package org.minbox.framework.api.boot.sample;
19+
20+
import org.minbox.framework.api.boot.common.exception.ApiBootException;
21+
import org.minbox.framework.api.boot.plugin.resource.load.ApiBootResourceStoreDelegate;
22+
import org.slf4j.Logger;
23+
import org.slf4j.LoggerFactory;
24+
import org.springframework.stereotype.Service;
25+
26+
import java.util.Arrays;
27+
import java.util.List;
28+
29+
/**
30+
* 资源加载数据代理实现类
31+
*
32+
* @author:恒宇少年 - 于起宇
33+
* <p>
34+
* DateTime:2019-04-15 13:54
35+
* Blog:http://blog.yuqiyu.com
36+
* WebSite:http://www.jianshu.com/u/092df3f77bca
37+
* Gitee:https://gitee.com/hengboy
38+
* GitHub:https://github.com/hengboy
39+
*/
40+
@Service
41+
public class ResourceLoadService implements ApiBootResourceStoreDelegate {
42+
/**
43+
* logger instance
44+
*/
45+
static Logger logger = LoggerFactory.getLogger(ResourceLoadService.class);
46+
47+
@Override
48+
public List<String> loadResourceUrl(String sourceFieldValue, String resourceType) throws ApiBootException {
49+
logger.info("查询资源的业务逻辑字段值:{}", sourceFieldValue);
50+
logger.info("资源类型:{}", resourceType);
51+
return Arrays.asList(new String[]{"http://test.oss.com/111.png"});
52+
}
53+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
spring:
2+
application:
3+
name: api-boot-sample-resource-load

0 commit comments

Comments
 (0)