小编use*_*900的帖子

带有错误输出的switch语句

我遇到了这个基本问题,其中将开关大小写与字符串一起使用。

在案例之间不使用Break语句,但是为什么即使不匹配case字符串也要在所有案例中使用break语句?

所以我很好奇 为什么输出是3而不是1?

 public static void main(String [] args)
      {
        int wd=0;

        String days[]={"sun","mon","wed","sat"};

        for(String s:days)
        {
          switch (s)
          {
          case "sat":
          case "sun":
            wd-=1;
            break;
          case "mon":
            wd++;
          case "wed":
            wd+=2;
          }
        }
        System.out.println(wd);
      }
Run Code Online (Sandbox Code Playgroud)

java arrays break switch-statement

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

Kotlin 课程中“this”的目的

我正在努力弄清楚this上课的目的。考虑以下示例:

class TestMe {

    var a: Int = 1
    var b: Int = 2

    fun setValA(value: Int) {
        this.a = value
    }
    fun setValB(value: Int) {
        b = value
    }
}

val testInstance1 = TestMe()
val testInstance2 = TestMe()

testInstance1.setValA(3)
testInstance1.setValB(4)

println("instance 2A: ${testInstance2.a}, instance 2B: ${testInstance2.b}") // 1 2
println("instance 1A: ${testInstance1.a}, instance 1B: ${testInstance1.b}") // 3 4
Run Code Online (Sandbox Code Playgroud)

似乎我可以简单地省略thisvalue 并且结果将是相同的。有什么我在这里想念的吗?

非常感谢!

class this getter-setter kotlin

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

在jsp中无法解析列表

下面的代码用于显示来自服务器文件夹的图像,但列表显示的是无法解析的类型。使用servlet代码“private static final String UPLOAD_DIRECTORY = "upload";”将图像上传到文件夹中 现在我想将所有图像显示到 jsp 页面。请帮忙

<%@ page import ="java.io.*"%>;
<%@ page import ="java.io.File.*"%>;
<%@ page import="java.sql.*"%>
<%@ page import="javax.sql.*"%>
<%@ page import ="java.util.ArrayList.*"%>
<%@ page import ="java.util.List.*"%>

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>File Upload Example</title>
    </head>
    <body> 
        <div id="result">
            <h3>${requestScope["message"]}</h3>
        </div>

        <%
            List imageUrlList = new ArrayList(); //List cannot be resolved type
            File imageDir = new File("Upload");
            for (File imageFile : imageDir.listFiles()) {
                String imageFileName = imageFile.getName();

                // add this images name to the …
Run Code Online (Sandbox Code Playgroud)

java import jsp

0
推荐指数
1
解决办法
7955
查看次数

从夏季报告中排除JSR 223样本

我有几个JSR 223采样器,它们在Thread组中具有脚本,在调用HTTP请求之前,它们会做一些工作。

问题是最终摘要报告中包含JSR 233采样器。
我的问题是,如何从最终计算中排除那些JSR 223采样器?

更新

当我尝试设置预处理器JSR 223时,收到此错误,因为预处理器JSR 223之后的if控制器无法识别我在中设置的变量vars.put。它仅在我使用JSR 223采样器时才识别。

2017/08/24 16:07:37 ERROR - jmeter.control.IfController: If Controller: error while processing [${my_foo_var} >=0]
 org.mozilla.javascript.EvaluatorException: missing ; before statement (<cmd>#1)
    at org.mozilla.javascript.DefaultErrorReporter.runtimeError(DefaultErrorReporter.java:77)
    at org.mozilla.javascript.DefaultErrorReporter.error(DefaultErrorReporter.java:64)
    at org.mozilla.javascript.Parser.addError(Parser.java:188)
    at org.mozilla.javascript.Parser.addError(Parser.java:166)
    at org.mozilla.javascript.Parser.reportError(Parser.java:256)
    at org.mozilla.javascript.Parser.reportError(Parser.java:243)
    at org.mozilla.javascript.Parser.reportError(Parser.java:236)
    at org.mozilla.javascript.Parser.autoInsertSemicolon(Parser.java:1100)
    at org.mozilla.javascript.Parser.statementHelper(Parser.java:1077)
    at org.mozilla.javascript.Parser.statement(Parser.java:934)
    at org.mozilla.javascript.Parser.parse(Parser.java:573)
    at org.mozilla.javascript.Parser.parse(Parser.java:511)
    at org.mozilla.javascript.Context.compileImpl(Context.java:2488)
    at org.mozilla.javascript.Context.compileString(Context.java:1476)
    at org.mozilla.javascript.Context.compileString(Context.java:1465)
    at org.mozilla.javascript.Context.evaluateString(Context.java:1216)
    at org.apache.jmeter.control.IfController$RhinoJsEngine.evaluate(IfController.java:105)
    at org.apache.jmeter.control.IfController.evaluateCondition(IfController.java:187)
    at org.apache.jmeter.control.IfController.next(IfController.java:240)
    at org.apache.jmeter.control.GenericController.nextIsAController(GenericController.java:222)
    at org.apache.jmeter.control.GenericController.next(GenericController.java:176)
    at org.apache.jmeter.control.LoopController.next(LoopController.java:123)
    at org.apache.jmeter.threads.AbstractThreadGroup.next(AbstractThreadGroup.java:87)
    at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:247)
    at …
Run Code Online (Sandbox Code Playgroud)

jmeter

0
推荐指数
1
解决办法
1032
查看次数

冲浪到 localhost:8000/x 时 /x/ 处的 Django UnboundLocalError

我是 Django 的新手,我刚刚创建了一个包含几个类的模型,并创建了视图和 url,一切正常,直到我尝试提取对象的 id 以在 url 中使用它。这是我的代码:

网址.py:

from django.conf.urls import url
from . import views

urlpatterns = [
    # / structures/
    url(r'^$', views.index, name='index'),

    # / structures/712
    url(r'^(?P<structure_id>[0-9]+)/$', views.detail, name='detail'),
]
Run Code Online (Sandbox Code Playgroud)

视图.py:

from django.http import HttpResponse
from .models import Structure

def index(request):
    all_structures = Structure.objects.all()
    html = ''
    for Structure in all_structures:
        url = '/structures/' + str(Structure.id) + '/'
        html += '<a href="' + url + '">' + Structure.name + '</a><br>'
    return HttpResponse(html)

def detail(request, structure_id):
    return HttpResponse("<h2>Details …
Run Code Online (Sandbox Code Playgroud)

python django python-3.6

0
推荐指数
1
解决办法
40
查看次数

在 Spring boot 中查找传入请求的 Content-type

我有一个将由前端调用的 Spring-Boot 控制器应用程序。Spring-boot@PostMapping将接受XMLJSON。我想根据Content-Type.

有没有办法检查传入的内容类型是什么?

@CrossOrigin(origins = "*")
@RestController
@RequestMapping("/api")
public class MyController {
    
    @PostMapping(value = "/generator", consumes = {"application/json", "application/xml"}, produces = "application/json")
    public String generate(@RequestBody String input) {
        try {
            System.out.println("INPUT CONTENT TYPE : ");
            if(contentType == "application/xml")
            {
                //Call Method-1
            }else if(contentType == "application/json"){
                //Call Method-2
            }
        } catch (Exception exception) {
            System.out.println(exception.getMessage());
        }
    }

}
Run Code Online (Sandbox Code Playgroud)

正如我们所看到的,该RestController方法接受XML and JSON. 我想检查传入的内容Content-type是根据其需要做出不同的决定。有人可以向我解释一下该怎么做吗?

请注意:我知道我可以创建不同的方法来处理 XML 和 JSON,但我想用单一方法来完成,这样既简单又高效。

java spring json content-type spring-boot

0
推荐指数
1
解决办法
2335
查看次数

为什么$ {flag == Y}返回True,而$ {flag =='Y'}返回False?

我对以下行为感到困惑。变量标志从控制器传递到jsp代码:

flag: <c:out value="${requestScope.flag}"/> 
flag eq 'Y': ${requestScope.flag eq 'Y'}
flag == 'Y': ${requestScope.flag=='Y'}
flag==Y: ${requestScope.flag==Y}
Run Code Online (Sandbox Code Playgroud)

情况1:标志未传递到视图(输出):

flag: 
flag eq 'Y': false 
flag == 'Y': false 
flag==Y: true
Run Code Online (Sandbox Code Playgroud)

情况2:将值“ Y”的标志传递给视图:

flag: Y
flag eq 'Y': true 
flag == 'Y': true 
flag==Y: false
Run Code Online (Sandbox Code Playgroud)

java jsp servlets jstl undefined

-1
推荐指数
1
解决办法
69
查看次数

应使用 lambda 删除未使用的方法参数 (squid:S1172) 误报

我有一个使用参数作为 lambda 表达式的工作方法

private BiConsumer<List<String>, Properties> handleList(Properties p) {
    return (list, prop) -> executeSubList(list, prop);
}
Run Code Online (Sandbox Code Playgroud)

因为p我收到了来自 SonarLint 的误报警告

Unused method parameters should be removed (squid:S1172)
Run Code Online (Sandbox Code Playgroud)

如果我更改prop为,p则会出现编译错误

Lambda 表达式的参数 p 无法重新声明封闭范围内定义的另一个局部变量

使用方法参数作为 lambda 参数时是否存在真正的问题或者是否存在误报检查?

java lambda false-positive method-parameters sonarlint

-1
推荐指数
1
解决办法
2535
查看次数

枚举数据库中的常量和动态值

我有一个当前状态,其中enumMyType表示类型表,其列为:

ID
Name
Run Code Online (Sandbox Code Playgroud)

并使用ID参数和byId方法来识别类型:

public enum MyType {

FIRST_TYPE("First Type", 10),
SECOND_TYPE("Second Type", 20);
public static class Holder {
    static Map<Integer, MyType > idMap = new HashMap<>();
    private Holder() { }
}

private MyType(String name, Integer id) {
    this.name = name;
    this.id = id;
    Holder.idMap.put(id, this);
}

public String getName() {
    return name;
}

public static MyType byId(Integer id) {
    return Holder.idMap.get(id);
}
Run Code Online (Sandbox Code Playgroud)

我的新要求是支持Type表中也存在值,我找到了动态枚举的答案,但是接受答案不是这样做

否。枚举始终固定在编译时。您执行此操作的唯一方法是动态生成相关的字节码。

从数据库(例如ID 30)中查找值(主要是ID)的更好解决方案是什么

 select ID from TYPE
Run Code Online (Sandbox Code Playgroud)

我可以 …

java enums database-driven

-3
推荐指数
2
解决办法
373
查看次数