小编Men*_*han的帖子

为什么词典"没有订购"?

我已经在这里回答了许多问题.但究竟是什么意思呢?

var test = new Dictionary<int, string>();
test.Add(0, "zero");
test.Add(1, "one");
test.Add(2, "two");
test.Add(3, "three");

Assert(test.ElementAt(2).Value == "two");
Run Code Online (Sandbox Code Playgroud)

上面的代码似乎按预期工作.那么字典被认为是无序的?在什么情况下上面的代码会失败?

.net c# dictionary operator-precedence base-class-library

45
推荐指数
4
解决办法
9948
查看次数

重新排序因子会产生不同的结果,具体取决于加载的包

我想创建一个条形图,其中条形按高度排序,而不是按类别按字母顺序排列.当我加载的唯一包是ggplot2时,这工作正常.但是,当我加载一些包并运行创建,排序和绘制数据框的相同代码时,条形图已经恢复为按字母顺序排序.

我每次使用都检查了数据帧str(),结果发现数据框的属性现在不同了,即使我每次都运行相同的代码.

我的代码和输出如下所示.任何人都可以解释不同的行为吗?为什么加载一些显然不相关的包(在我所使用的所有函数似乎都没有被新加载的包掩盖的意义上无关)会改变运行transform()函数的结果?

案例1:刚加载ggplot2

library(ggplot2)

group = c("C","F","D","B","A","E")
num = c(12,11,7,7,2,1)
data = data.frame(group,num)
data1 = transform(data, group=reorder(group,-num))

> str(data1)
'data.frame':   6 obs. of  2 variables:
 $ group: Factor w/ 6 levels "C","F","B","D",..: 1 2 4 3 5 6
  ..- attr(*, "scores")= num [1:6(1d)] -2 -7 -12 -7 -1 -11
  .. ..- attr(*, "dimnames")=List of 1
  .. .. ..$ : chr  "A" "B" "C" "D" ...
 $ num  : num  12 11 7 7 2 1 …
Run Code Online (Sandbox Code Playgroud)

namespaces r masking operator-precedence

18
推荐指数
1
解决办法
870
查看次数

在Spring RESTful服务中生成和使用自定义JSON对象

我有一些JSON对象比我拥有的java对象的JSON表示更复杂.我有构建这些JSON对象的方法,我想直接返回并使用它们.我使用org.json库来构建我的JSON.我可以GET通过返回JSON对象来获得该方法String.这是正确的方法吗?

@RequestMapping(value = "/getjson", method = RequestMethod.GET, produces="application/json")
@ResponseBody
public String getJson() {
    JSONObject json = new JSONObject();
     JSONObject subJson = new JSONObject();
    subJson .put("key", "value");
    json.put("key", subJson);
    return json.toString();
}
Run Code Online (Sandbox Code Playgroud)

现在我想知道如何使用JSON对象?作为字符串并将其转换为JSON对象?

    @RequestMapping(value = "/post", method = RequestMethod.POST, produces="application/json", consumes="application/json")
    @ResponseBody
    public String post(@RequestBody String json) {
        JSONObject obj = new JSONObject(json);
        //do some things with json, put some header information in json
        return obj.toString();
    }
Run Code Online (Sandbox Code Playgroud)

这是解决我问题的正确方法吗?我是一个新手,所以请指出任何可以做得更好的事情.请注意:我不想退回POJO.

java rest post spring json

18
推荐指数
1
解决办法
6万
查看次数

在 Ubuntu 20.04 LTS(Vmware) 上安装 docker 失败

我正在 Ubuntu 20.04 上使用https://docs.docker.com/engine/install/ubuntu/在 VMware 上的 Ubuntu VM 上跟踪 docker 安装。

但是当运行命令将存储库添加到 Ubuntu 时。

sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
    software-properties-common
Run Code Online (Sandbox Code Playgroud)

我得到以下错误

Get:1 http://us.archive.ubuntu.com/ubuntu focal InRelease [265 kB]                                                                           
Ign:2 http://dl.google.com/linux/chrome/deb stable InRelease                                                                                 
Hit:3 http://dl.google.com/linux/chrome/deb stable Release                                                                                   
Hit:5 http://security.ubuntu.com/ubuntu focal-security InRelease                                                                             
Ign:6 https://download.docker.com/linux/ubuntu focal InRelease                                             
Err:7 https://download.docker.com/linux/ubuntu focal Release
  404  Not Found [IP: 13.225.7.126 443]
Get:8 http://us.archive.ubuntu.com/ubuntu focal-updates InRelease [89.1 kB]
Hit:9 http://us.archive.ubuntu.com/ubuntu focal-backports InRelease
Reading package lists... Done
E: The repository 'https://download.docker.com/linux/ubuntu …
Run Code Online (Sandbox Code Playgroud)

ubuntu vmware docker ubuntu-20.04

17
推荐指数
4
解决办法
2万
查看次数

ERD图中的继承关系

我对 ERD 图中的继承表示有疑问。下面的例子:我有飞机,我也有两种类型的飞机 1-PersonsPlane 2-CargoPlane 我对使用哪种关系感到困惑(1-to-1 OR 1-to-Many)。我的 DB 老师告诉我应该使用 1 对 1 关系,但是我在互联网上发现许多示例使用(1 对多)关系而不是(1 对 1)关系。检查这些图像:

一对一关系 一对一关系

一对多关系 一对多关系

哪一个是正确的??

database erd mysql-workbench

7
推荐指数
2
解决办法
2万
查看次数

从 JavaScript 检索自定义属性(使用 Javascript 适配器)Keycloak

我有一个具有如下自定义属性的 keycloak 用户。 keycloak 自定义属性

我使用 Reactjs 作为前端。我想从 javascript 端检索自定义属性。就像这个答案所说的那样。

/sf/answers/2302300241/

但我找不到如何在 javascript 方面做到这一点。

我在 Chrome 中进行了调试,但找不到适合自定义属性的结果。

请帮忙

javascript reactjs keycloak

7
推荐指数
2
解决办法
3857
查看次数

使用Keycloak保护Tomcat应用程序时出现HTTP 403禁止错误

我为这个错误苦苦挣扎了一整天。我一遍又一遍地检查我在tomcat中Keycloak和APP的配置,没有发现错误。

下图为测试场景:

在此输入图像描述

APP配置:

1.Keycloak.json是从Keycloak控制台复制的

2.context.xml 也正确,因为它在“localhost”场景下工作正常

3.web.xml:

<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
  version="3.0">

    <module-name>Keycloak-Tomcat-App</module-name>

<!--
<security-constraint>
    <web-resource-collection>
        <web-resource-name>init pages</web-resource-name>
        <url-pattern>/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
        <role-name>user</role-name>
    </auth-constraint>
</security-constraint>
-->

<security-constraint>
    <web-resource-collection>
        <web-resource-name>All roles pages</web-resource-name>
        <url-pattern>/roles/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
        <role-name>admin</role-name>
    </auth-constraint>
</security-constraint>

<login-config>
    <auth-method>BASIC</auth-method>
    <realm-name>this is ignored currently</realm-name>
</login-config>

<security-role>
    <role-name>admin</role-name>
</security-role>
<security-role>
    <role-name>user</role-name>
</security-role>
Run Code Online (Sandbox Code Playgroud)

Keycloak控制台配置:

我创建一个名为 csf-admin 的用户,并将角色“admin”和“user”分配给 csf-admin

然后

1)在linux.1上使用broswer访问linux.3上部署在TOMCAT中的APP(用户https)

2)我的浏览器可以打开Keycloak认证页面(用户https,linux.2上的keycloak)

3)以csf-admin身份登录keycloak

4)Keycloak将我重定向到APP url(使用https)

5)HTTP 403“已禁止访问指定资源。” 到场

我真的不知道根本原因......需要你的帮助......

java jboss tomcat single-sign-on keycloak

5
推荐指数
1
解决办法
7121
查看次数

此环境中不提供编译器。也许您在 IntelliJ 中运行于 JRE 而不是 JDK

我尝试在 Intellij 中进行 mvn clean install 。但它引发了这个错误。 在此输入图像描述

mvn -version 命令在 intellij 终端中工作正常。

在此输入图像描述

intellij-idea maven maven-compiler-plugin

5
推荐指数
1
解决办法
2万
查看次数

D3.js 按组分层边缘捆绑着色

我正在尝试根据连接到的组来为分层边缘捆绑可视化中的连接着色。可以在这里看到这样的一个例子。

在此输入图像描述

这是我当前的鼠标悬停功能:

    function mouseover(d) {
        svg.selectAll("path.link.target-" + d.key)
            .classed("target", true)
            .each(updateNodes("source", true));

        svg.selectAll("path.link.source-" + d.key)
            .classed("source", true)
            .each(updateNodes("target", true));
    }
Run Code Online (Sandbox Code Playgroud)

这是我发布的示例中的鼠标悬停函数:

function mouseovered(d) 
{
        // Handle tooltip
        // Tooltips should avoid crossing into the center circle

        d3.selectAll("#tooltip").remove();
        d3.selectAll("#vis")
            .append("xhtml:div")
            .attr("id", "tooltip")
            .style("opacity", 0)
            .html(d.title);
        var mouseloc = d3.mouse(d3.select("#vis")[0][0]),
            my = ((rotateit(d.x) > 90) && (rotateit(d.x) < 270)) ? mouseloc[1] + 10 : mouseloc[1] - 35,
            mx = (rotateit(d.x) < 180) ? (mouseloc[0] + 10) :  Math.max(130, (mouseloc[0] - …
Run Code Online (Sandbox Code Playgroud)

html javascript css svg d3.js

5
推荐指数
1
解决办法
2337
查看次数

为什么我得到"无法加载ApplicationContext"Spring,jUnit和JavaConfig

为什么我得到"无法加载ApplicationContext"Spring,jUnit和JavaConfig

这是我的测试类:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = HelloWorldConfig.class)
public class TestApp
{

    @Test
    public void testBean()
    {
      ApplicationContext context = new AnnotationConfigApplicationContext(HelloWorldConfig.class);

      HelloWorld helloWorld = context.getBean(HelloWorld.class);
      helloWorld.setMessage("I am in Staten Island, New York");

      Assert.assertEquals(helloWorld.getMessage(), "I am in Staten Island, New York");
    }
}
Run Code Online (Sandbox Code Playgroud)

这是堆栈跟踪.

    java.lang.IllegalStateException: Failed to load ApplicationContext  at
org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:99)
    at
org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:122)
    at
org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)
    at
org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
    at
org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:312)
    at
org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:211)    at
org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:288)
    at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at
org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:284)
    at
org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
    at
org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:88)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)  at
org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)     at
org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)   at
org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)     at
org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)    at …
Run Code Online (Sandbox Code Playgroud)

java junit spring

4
推荐指数
1
解决办法
4万
查看次数