小编pba*_*ris的帖子

Java,Simplified检查int数组是否包含int

基本上我的伙伴一直在说我可以通过使用一种不同的方式检查一个int数组是否包含int来缩短我的代码,尽管他不会告诉我它是什么:P.

当前:

public boolean contains(final int[] array, final int key) {
    for (final int i : array) {
        if (i == key) {
            return true;
        }
    }
    return false;
}
Run Code Online (Sandbox Code Playgroud)

也试过这个,虽然它总是由于某种原因返回false.

public boolean contains(final int[] array, final int key) {
    return Arrays.asList(array).contains(key);
}
Run Code Online (Sandbox Code Playgroud)

任何人都可以帮我吗?

谢谢.

java arrays int contains

82
推荐指数
6
解决办法
21万
查看次数

无法使用maven-assembly-plugin设置最终的jar名称

这就是我配置的方式 maven-assembly-plugin

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.4</version>
    <configuration>
        <finalName>myapp</finalName>
        <archive>
            <manifest>
                <mainClass>com.myapp.Main</mainClass>
            </manifest>
        </archive>
        <!--
        <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>
        -->
    </configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)

我希望最终的jar文件应该是,myapp.jar但它最终会结束myapp-jar-with-dependencies.jar

你能告诉我如何配置以排除"jar-with-dependencies"最终名称吗?

java maven-3 maven

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

什么是背书以及如何在应用程序中使用它?

关于maven-compiler-plugin.我的项目的POM文件中添加了一个设置.配置如下.

<plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.3.2</version>
        <configuration>
            <source>1.6</source>
            <target>1.6</target>
            <compilerArguments>
                <endorseddirs>${endorsed.dir}</endorseddirs>
            </compilerArguments>
        </configuration>
    </plugin>
</plugins>
Run Code Online (Sandbox Code Playgroud)

<endorseddirs>在编译器参数中有一个含义是什么意思?它如何与java编译器一起使用?

java maven

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

为什么我收到"使用GWT生命周期配置未涵盖的插件执行"错误?

我正在使用STS,我从另一台机器上导入了一个GWT项目.该项目使用m2eclipse.我在构建项目时遇到了这两个错误:

Plugin execution not covered by lifecycle configuration: org.codehaus.mojo:gwt-maven-plugin:2.2.0:i18n (execution: default, phase: generate-sources)    pom.xml /contactsgwt    line 175
Plugin execution not covered by lifecycle configuration: org.apache.maven.plugins:maven-war-plugin:2.1.1:exploded (execution: default, phase: compile)  pom.xml /contactsgwt    line 198
Run Code Online (Sandbox Code Playgroud)

怎么了?有没有进一步的配置需要这样做才能gwt maven plugin工作?

pom.xml导致错误的代码:

<!-- GWT Maven Plugin -->
<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>gwt-maven-plugin</artifactId>
    <version>2.2.0</version>
    <executions>
        <execution>
            <goals>
                <goal>compile</goal>
                <goal>test</goal>
                <goal>i18n</goal>
            </goals>
        </execution>
    </executions>
    <!-- Plugin configuration. There are many available options, see gwt-maven-plugin documentation at codehaus.org -->
    <configuration>
        <runTarget>Contacts.html</runTarget>
        <hostedWebapp>${webappDirectory}</hostedWebapp
        <i18nMessagesBundle>es.indra.gwt.contactsgwt.client.ContactsMessages</i18nMessagesBundle>
    </configuration>
</plugin>

<!-- Copy …
Run Code Online (Sandbox Code Playgroud)

eclipse gwt m2eclipse pom.xml maven

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

如何集中无序列表?

我需要将无序宽度的无序列表居中,同时仍保持列表项左对齐.

获得与此相同的结果:

HTML

<div>
    <ul>
        <li></li>
        <li></li>
        <li></li>
    </ul>
</div>
Run Code Online (Sandbox Code Playgroud)

CSS

div { text-align: center; }
ul { display: inline-block; text-align: left; }
Run Code Online (Sandbox Code Playgroud)

除了我<ul>没有父div.ul { margin: 0 auto; }不起作用,因为我没有固定的宽度.ul { text-align: center; }不起作用,因为列表项不再左对齐.那么我如何<ul>在保持<li>s左对齐的同时将其居中(没有父div包装器)?

<ul>
    <li></li>
    <li></li>
    <li></li>
</ul>
Run Code Online (Sandbox Code Playgroud)

编辑:也许我的措辞是不是最好的...第一个代码块已经工作...我需要的是做<div>包装,如果可能的话,当然.漂浮技巧?伪元素技巧?一定有办法.

html css center html-lists

24
推荐指数
3
解决办法
12万
查看次数

此版本的SQL Server不支持没有聚簇索引的表

我正在使用SQL Server数据库处理vs 2010和EF 4.1.下面提到的代码适用于本地SQL Server DB.(SQL 2008).

但是,当我发布Windows AZURE云SQL Azure的MVC应用程序时,它给出了下面提到的错误.

  1. 为什么此错误仅返回SQL Azure(使用桌面SQL Server 2008)?
  2. 如何摆脱这个?

我的存储库代码示例如下所示.下面提到错误来自调用 Catalog.SaveChanges()方法.

using (var catalog = new DataCatalog())
{
    var retailSaleReturn = new RetailSaleReturn
    {
        ReturnQuantity = returnQuantity,
        Product = saleDetailObj.Product,
        Owner = owner,
        Provider = provider,
    };

    //add to context
    Catalog.RetailSaleReturns.Add(retailSaleReturn);

    //save for db
    Catalog.SaveChanges();
}
Run Code Online (Sandbox Code Playgroud)

DbUpdateException如下所示:

{"An error occurred while saving entities that do not expose foreign …
Run Code Online (Sandbox Code Playgroud)

azure c#-4.0 entity-framework-4.1 asp.net-mvc-3 azure-sql-database

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

我可以将参数传递给使用_.lodash去抖动的函数吗?

我一直在尝试使用_lodash.debounce(),我让它工作.但是我不确定它是否以最好的方式工作.我查看了lodash网站上的示例,它们似乎只是简单的示例,不传递参数.这就是我所拥有的:

$scope.parsePid = _.debounce(function () {
    $scope.$apply(function () {
        var pid = $scope.option.sPidRange;
        if (pid == null || pid === "") {
            $scope.pidLower = null;
            $scope.pidUpper = null;
        }
        else if (pid.indexOf("-") > 0) {
            pid = pid.split("-");
            $scope.pidLower = parseInt(pid[0]);
            $scope.pidUpper = parseInt(pid[1]);
        }
        else {
            $scope.pidLower = parseInt(pid);
            $scope.pidUpper = null;
        }
    });
}, 1500);
Run Code Online (Sandbox Code Playgroud)

上面的代码返回一个$scope.parsePid被去抖动的函数.请注意,在第4行,我得到了值$scope.option.SPidRange并在函数中使用它.我真的想以某种方式传递这个参数而不是这样.

我把这个函数称为:

$scope.$watch("option.sPidRange", function (pid) {
    if (pid !== null) {
        $scope.parsePid();
    }
});
Run Code Online (Sandbox Code Playgroud)

这里的值pid应该等于 $scope.parsePid

我想将这个pid的值传递给debounced函数,但我不知道该如何做到这一点.我尝试了一些不同的东西,但去抖功能会出错.

是否可以将参数传递到去抖动function …

javascript angularjs lodash

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

覆盖WildFly中的日志记录

我使用tomcat并简单地覆盖默认日志系统.如何在我的spring应用程序中使用wildfly上的logback启用日志记录?

我的logback.xml是关于tomcat的

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>ERROR</level>
            <onMatch>ACCEPT</onMatch>
            <onMismatch>DENY</onMismatch>
        </filter>
        <encoder>
            <pattern>%-4relative [%thread] %-5level %logger{35} - %msg %n</pattern>
        </encoder>
    </appender>

    <logger name="org.springframework" level="WARN" />
    <logger name="com.citronium.planstery" level="INFO" />
    <logger name="org.apache.http.impl.conn.tsccm" level="ERROR" />

    <root level="INFO">
        <appender-ref ref="STDOUT" />
    </root>
</configuration>
Run Code Online (Sandbox Code Playgroud)

jboss log4j logback wildfly

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

杰克逊自我引用导致循环


使用Jackson将hibernate对象转换为JSON时遇到问题,因为某些对象在其定义中有自引用.问题是我不控制那些实体的代码,所以我不能在那里添加注释.

实际上我只想限制递归的深度,例如5级.我需要与包含自引用的任何实体对象一起使用的通用代码.是否可能?我不介意使用另一个JSON库.

以下简单代码

ObjectMapper mapper = new ObjectMapper();

Query q = session.createQuery("from Hazard ");
List<Hazard> hazards = q.list();

for (Hazard h : hazards) {
    String hazardJson;
    hazardJson = mapper.writeValueAsString(h);
}
Run Code Online (Sandbox Code Playgroud)

给我例外:

org.codehaus.jackson.map.JsonMappingException: Direct self-reference leading to cycle (through reference chain: com.fgm.imsma.pojo.Hazard["location"]->com.fgm.imsma.pojo.Location["location"])
    at org.codehaus.jackson.map.ser.BeanPropertyWriter._reportSelfReference(BeanPropertyWriter.java:473)
    at org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:411)
    at org.codehaus.jackson.map.ser.BeanSerializer.serializeFields(BeanSerializer.java:245)
    at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:212)
    at org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:428)
    at org.codehaus.jackson.map.ser.BeanSerializer.serializeFields(BeanSerializer.java:245)
    at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:212)
    at org.codehaus.jackson.map.ser.StdSerializerProvider._serializeValue(StdSerializerProvider.java:587)
    at org.codehaus.jackson.map.ser.StdSerializerProvider.serializeValue(StdSerializerProvider.java:245)
    at org.codehaus.jackson.map.ObjectMapper._configAndWriteValue(ObjectMapper.java:1993)
    at org.codehaus.jackson.map.ObjectMapper.writeValueAsString(ObjectMapper.java:1595)
    at imsma.json.GetObjects.main(GetObjects.java:47)

在此先感谢您的任何建议!

json hibernate jackson

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

如何在C#中使用Timer

我正在system.Timers.Timer用来创建一个计时器.

public System.Timers.Timer timer = new System.Timers.Timer(200);
private void btnAutoSend_Click(object sender, EventArgs e)
{
    timer.Enabled = true;
    timer.Elapsed += new System.Timers.ElapsedEventHandler(send);
    timer.AutoReset = true;
}

public void send(object source, System.Timers.ElapsedEventArgs e)
{
    this.rtbMsg.AppendText("psyche-->" + receiver + ": hello\n");
}
Run Code Online (Sandbox Code Playgroud)

发送函数中的接收器是我在使用函数时需要设置的参数,但是当我在发送函数中添加参数时,如:

public void send(object source, System.Timers.ElapsedEventArgs e,string receiver)
Run Code Online (Sandbox Code Playgroud)

然后它会抛出一个错误.在检查了MSDN之后,它说ElapsedEventArgs仅适用于这些不会产生数据的函数.

我怎么解决这个问题?我的程序不是windows.Form,所以我不能使用System.Windows.Forms.Timer.

c# timer

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