我收到以下查询的错误.基本上要||和' distinct一起使用.
select string_agg( 'pre' || distinct user.col, 'post')
Run Code Online (Sandbox Code Playgroud)
它工作得很好
select string_agg( 'pre' || user.col, 'post')
Run Code Online (Sandbox Code Playgroud)
& 这个
select string_agg(distinct user.col, 'post')
Run Code Online (Sandbox Code Playgroud) 我试图用一个例子来理解这个干净的代码实践.考虑具有折扣开关案例的类产品.我试图用多态替换switch语句.
代码之前:
class Product {
String priceCode;
int discount;
Product(String priceCode) {
setDiscount(priceCode);
}
public int getDiscount() {
return discount;
}
public void setDiscount(String priceCode) {
switch (priceCode) {
case "CODE1":
discount = // some logic;
case "CODE2":
discount = // some other logic;
case "CODE3":
discount = // some other logic;
}
}
}
Run Code Online (Sandbox Code Playgroud)
在下面的代码中你可以看到我删除了switch语句但是我仍然有条件来创建discountStrategy的对象.我的问题是,我仍然有条件,我试图删除多态性.
代码后:
class Product {
String priceCode;
DiscountStrategy discountStrategy;
Product(String priceCode) {
setDiscount(priceCode);
}
public int getDiscount() {
return discountStrategy.getDiscount();
}
public void setDiscount(String priceCode) …Run Code Online (Sandbox Code Playgroud) 我正在尝试调用 graph api 来获取用户信息。我首先使用邮递员获取令牌,然后使用该令牌尝试向图形 api 发出请求
我通过以下发布请求获得了令牌,并有 4 个关键值grant_type, client_id, client_secret and resource.
https://login.microsoftonline.com/{{tenantid}}/oauth2/token
Run Code Online (Sandbox Code Playgroud)
响应是
{
"token_type": "Bearer",
"expires_in": "3600",
"ext_expires_in": "3600",
"expires_on": "1555583717",
"not_before": "1555579817",
"resource": "https://management.azure.com/",
"access_token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxNiIsIng1dCI6IkhCeGw5bUFlNmd4YXZDa2NvT1UyVEhzRE5hMCIsImtpZCI6IkhCeGw5bUFlNmd4YXZDa2NvT1UyVEhzRE5hMCJ9.yyyyyyyLTBjYjZmZDNiM2UwNCIsInRpZCI6IjM3NGY4MDI2LTdiNTQtNGEzYS1iODdkLTMyOGZhMjZlYzEwZCIsInV0aSI6ImVWTWdDbkU4QWtPVXY3bFQ2QlRSQUEiLCJ2ZXIiOiIxLjAifQ.kxHCm2oGsuUvlXbncXQe7Wb0l-ZENqqG9_P_co0SPdYA3GkhFKDi6sQ7OaaHeDs4S6kN0-Diw5qBOzmFipSA5EUorA7UDbJfiSVVlaEzLY3IX_4WSV4Exc-kLOaX0j7KgvsEQbc5TEk8e4dPfokG98gGPmhy19xLyV84lX1v6DzgXINzP8gPkGmqR_J7iVFQ3m-Y18dHlxDpqQMTKxvQGnrsa7rflyxGUwEwwFZJH8t5NRv_mjQOIQBuosfhMAH88l-J8zEmXWLFqEzFBBWrz9UxT6X-XxRQZW4WBSoHTKd3vuBcEo6kUclfe4G7COOvI4zG0-j10mmGziKlzjNVMw"
}
Run Code Online (Sandbox Code Playgroud)
然后我使用令牌发出 GET 请求
https://graph.windows.net/{{company}}/users/{{email}}?api-version=1.6
Run Code Online (Sandbox Code Playgroud)
和标题
Key Value
Authorization Bearer {{token}}
Run Code Online (Sandbox Code Playgroud)
但它因这个错误而失败
{
"odata.error": {
"code": "Authentication_MissingOrMalformed",
"message": {
"lang": "en",
"value": "Access Token missing or malformed."
}
}
}
Run Code Online (Sandbox Code Playgroud)
向 graph api 发出请求的正确方法是什么?
所以我有User类
User{
id
name
}
Run Code Online (Sandbox Code Playgroud)
我需要转换List<User>为使用流的数组,所以我正在做的一种方法是转换为列表然后转换为数组
coll.stream().map(am -> am.getId())
.collect(Collectors.<Integer>toList())
.toArray(new Integer[0])
Run Code Online (Sandbox Code Playgroud)
但我认为应该有另一种方法直接转换为数组而不是添加列表然后转换为数组.
我试图通过maven命令分离单元测试和集成测试。
pom.xml
....
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>**/*Fast*</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</project>
Run Code Online (Sandbox Code Playgroud)
这是我的整合测试
@RunWith(SpringRunner.class)
@SpringBootTest(classes = StudentApplication.class,
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class StudentControllerIT {
...
Run Code Online (Sandbox Code Playgroud)
这是单元测试
@RunWith(SpringRunner.class)
@WebMvcTest(value = StudentController.class, secure = false)
public class StudentFastControllerTest {
....
Run Code Online (Sandbox Code Playgroud)
现在,当我尝试运行命令时,mvn test仅 StudentFastControllerTest执行测试,但是当我运行命令mvn integration-test或mvn verify同时执行两个测试类而不是仅执行时StudentControllerIT。
我有一个私有方法,使用元类在grails 1.3.7中进行了模拟,但现在我将grails版本升级到2.2.4,同样的模拟失败了.
测试方法有私有方法调用
private def MyPrivateMeth1(def arg1, def arg2) {
...
}
Run Code Online (Sandbox Code Playgroud)
模拟是这样的
MyController.metaClass.private.MyPrivateMeth1 = { a, b ->
...
}
Run Code Online (Sandbox Code Playgroud) 我有一个类 Person。
\n\nclass Person{\nInteger id;\nString firstName;\nString lastName;\n//other params, constructors, getters & setters\n}\nRun Code Online (Sandbox Code Playgroud)\n\n&我的方法是
\n\n @RequestMapping(value = "/test", method = RequestMethod.POST)\n public void testPerson(\n @RequestBody Person person){\n...\n}\nRun Code Online (Sandbox Code Playgroud)\n\n现在我需要使用休息客户端来测试它。我尝试将 Firefox 插件的 \xe2\x80\x9crequest header\xe2\x80\x9d 部分设置为 \xe2\x80\x9cname\xe2\x80\x9d = \xe2\x80\x9cContent-Type\xe2\x80 \x9d 和 \xe2\x80\x9cvalue\xe2\x80\x9d = \xe2\x80\x9capplication/x-www-form-urlencoded\xe2\x80\x9d\n& 然后在 body 中添加参数,
\n\nid=1&firstName=aaa&lastName=bbb\nRun Code Online (Sandbox Code Playgroud)\n\n但它给出了 404。
\n我有这样的课
ObjectA
id
type
Run Code Online (Sandbox Code Playgroud)
其中id是唯一的,但类型可以重复,所以如果我有这样的ObjectA列表
(id, type) = (1, "A") , (2, "B"), (3, "C"), (4, "A")
Run Code Online (Sandbox Code Playgroud)
然后我想要Map<type, List<id>>地图在哪里
< "A",[1,4],
"B",[2],
"C",[3] >
Run Code Online (Sandbox Code Playgroud)
它正在使用Java 7,但无法在Java 8中找到方法.在Java 8中,我可以创建键值对,但如果类型相同则无法创建列表.
我有一个具有这样的值的Answer实体
question answer
1 x
2 y
3 z
4 p
1 x
2 q
3 r
Run Code Online (Sandbox Code Playgroud)
我需要逐个问题地得到答案
Map<Integer, List<String>>
<1, [x,x]
2, [y,p]
3, [z,r]
4, [p]>
Run Code Online (Sandbox Code Playgroud)
我可以List<Answer>这样
Map<Integer, List<Answer>> collect = answers
.stream()
.collect(Collectors.groupingBy(Answer::getQuestion));
Run Code Online (Sandbox Code Playgroud)
但我找不到一种方法来获得它List<String>而不是List<Answer>?
java-8 ×3
java-stream ×3
java ×2
azure ×1
grails ×1
groovy ×1
junit ×1
junit4 ×1
maven ×1
mocking ×1
polymorphism ×1
post ×1
postgresql ×1
postman ×1
rest ×1
spring ×1
spring-boot ×1
unit-testing ×1