小编Dam*_*men的帖子

为什么我在运行简单的 Spring Boot 应用程序时总是得到状态为“404”的白标签错误页面

我的控制器

@Controller
//@RequestMapping("/")
//@ComponentScan("com.spring")
//@EnableAutoConfiguration
public class HomeController {

    @Value("${framework.welcomeMessage}")
    private String message;

    @RequestMapping("/hello")
    String home(ModelMap model) {
        System.out.println("hittin the controller...");
        model.addAttribute("welcomeMessage", "vsdfgfgd");
        return "Hello World!";
    }

    @RequestMapping(value = "/indexPage", method = RequestMethod.GET)
    String index(ModelMap model) {
        System.out.println("hittin the index controller...");
        model.addAttribute("welcomeMessage", message);
        return "welcome";
    }

    @RequestMapping(value = "/indexPageWithModel", method = RequestMethod.GET)
    ModelAndView indexModel(ModelMap model) {
        System.out.println("hittin the indexPageWithModel controller...");
        model.addAttribute("welcomeMessage", message);
        return new ModelAndView("welcome", model);
    }
}
Run Code Online (Sandbox Code Playgroud)

我的 JSP(welcome.jsp)在 /WEB-INF/jsp 里面(父文件夹是 WebContent)

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%> …
Run Code Online (Sandbox Code Playgroud)

java spring jsp spring-mvc spring-boot

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

为什么eclipse说即使使用局部变量也不使用?

我有以下代码

private List<String> getItems() {
    XmlDoc document = new XmlDoc();
    List<String> itemList = new ArrayList<String>();
    String itemNum;
    try {
        XmlUtils root = document.parse(xmlFile);
        List<XmlUtils> listNode = root.getChildNodes();
        for (XmlUtils node : listNode)  {
            itemNum = node.getValue();
        }
    } catch (XmlException e) {
        e.printStackTrace();
    }
    return itemList;
}
Run Code Online (Sandbox Code Playgroud)

即使我在for循环eclipse中使用了String itemNum,也说"不使用局部变量itemNum的值".为什么会这样?

java eclipse

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

Jenkins Active Choices 参数插件未按预期工作

我有一个hidden parameter叫. 我想根据参数显示选择。我创建了以下常规脚本,但它不起作用JenkinsplatformTypeplatformType

if (platformType.equals("android")) {
  return ['7.0', '6.0']
} else (platformType.equals("ios")) {
  return ['10.0', '9.0']
}
Run Code Online (Sandbox Code Playgroud)

请看下面的截图 在此输入图像描述

groovy jenkins jenkins-plugins

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

AWS EC2 Boto3中的“ start_instances()仅接受关键字参数”错误

我正在尝试开始EC2 instance使用boto3。当我执行以下代码时,它可以正常工作

import boto3


ec2client = boto3.client('ec2')

class StartInstances:

    def start_ec_instances(self):
        response = ec2client.start_instances(InstanceIds=['i-XXXXXXXXXX'])
        return

StartInstances().start_ec_instances()
Run Code Online (Sandbox Code Playgroud)

但是当我运行下面的代码时,我得到了

import boto3


ec2client = boto3.client('ec2')

class StartInstances:

    def start_ec_instances(self, instanceid):
        response = ec2client.start_instances(instanceid)
        return

StartInstances().start_ec_instances('InstanceIds=[\'i-XXXXXXXXXX\']')
Run Code Online (Sandbox Code Playgroud)

追溯(最近一次通话):文件“ /Users/xxx/PycharmProjects/ctm-scripting-utils/ec2/start_instances.py”,第25行,位于StartInstances()。start_ec_instances(“ InstanceIds = [\'i-XXXXXXXXXX \ ']“)文件” /Users/xxx/PycharmProjects/ctm-scripting-utils/ec2/start_instances.py“,第11行,位于start_ec_instances响应= ec2client.start_instances(instanceids)文件” / Users / xxx / Library / Python / _api_call中的3.6 / lib / python / site-packages / botocore / client.py“,第310行,”%s()仅接受关键字参数。“ %py_operation_name)TypeError:start_instances()仅接受关键字参数。

python amazon-ec2 amazon-web-services boto3

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

控制器未使用Spring Boot和Thymeleaf从HTML的跨度中接收值

我的HTML中有以下内容正在使用 Thymeleaf

<form action="#" th:action="@{/shutDown}" th:object="${ddata}" method="post">
        <span>Domain</span>
        <span th:text="${domain}" th:field="*{domain}">domain</span>
        <input type="Submit" value="close" />
</form>
Run Code Online (Sandbox Code Playgroud)

而且我在下面Controller这是使用Sprint Boot

@RequestMapping(value = "/shutDown", method = RequestMethod.POST)
public ModelAndView shutDownPage(ModelAndView modelAndView, Authentication authentication,
        @ModelAttribute("ddata") DInputBean dInputBean) {
    String domain = dInputBean.getdomain();
    return modelAndView;
}
Run Code Online (Sandbox Code Playgroud)

我希望可以从中获得domainHTML的价值,Controller但它始终为null。DInputBean具有getters and setters“域”字段。

spring spring-mvc thymeleaf spring-boot

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

使用Jackson使用列表反序列化XML

我有以下XML,我想反序列化为Java POJO.

<testdata>
    <foo>
        <bar>
            <![CDATA[MESSAGE1]]>
        </bar>
        <bar>
            <![CDATA[MESSAGE2]]>
        </bar>
        <bar>
            <![CDATA[MESSAGE3]]>
        </bar>
    </foo>
</testdata>
Run Code Online (Sandbox Code Playgroud)

我有以下Java类

public class TestData {

    @JacksonXmlProperty(localName = "foo")
    private Foo foo;

    public Foo getFoo() {
        return foo;
    }

    public void setFoo(Foo foo) {
        this.foo = foo;
    }

}
Run Code Online (Sandbox Code Playgroud)

我有另一个类,如下

public class Foo {

    @JacksonXmlProperty(localName = "bar")
    @JacksonXmlCData
    private List<String> barList;

    public List<String> getBarList() {
        return barList;
    }

    public void setBarList(List<String> barList) {
        this.barList = barList;
    }
}
Run Code Online (Sandbox Code Playgroud)

现在,当我使用下面的类运行代码时,我得到一个异常

private void readXml() throws FileNotFoundException, IOException { …
Run Code Online (Sandbox Code Playgroud)

java jackson fasterxml

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

如果它不存在,请创建一个新的数组索引

说我有一个像下面的字符串

String s1 = "test1=1&test2=2&test3=&test4=4";
Run Code Online (Sandbox Code Playgroud)

请注意字符串S1中的test3参数,因为它没有任何值

String [] splitS1 = s1.split("\\&");
for (int i = 0; i < splitS1.length; i++) {
    String[] params = splitS1[i].split("=");
    System.out.println("Attribute:"+params[0]+"   Value : "+params [1]);
}
Run Code Online (Sandbox Code Playgroud)

上面的代码抛出java.lang.ArrayIndexOutOfBoundsException:1,因为String s1中的test3没有任何值,因此params [1]对test3无效.

我试过这样做

                if(params.length == 1) {
                    params[1] = "";
                }
Run Code Online (Sandbox Code Playgroud)

但我知道我们无法扩展数组.这可以做什么?

谢谢!

java arrays string

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

循环List <String>并删除项目的更好方法

我有一个List,如果匹配,我将循环删除列表中的项目.如果列表中的项目被删除,我正在使用i = -1.但它又从头开始循环.有一个更好的方法吗?

private List<String> populateList(List<String> listVar) {
    List<String> list = new ArrayList<String>();
    list.add("2015-01-13 09:30:00");
    list.add("2015-01-13 06:22:12");
    list.add("2015-01-12 05:45:10");
    list.add("2015-01-12 01:52:40");
    list.add("2015-01-12 02:23:45");
    return list;
}

private void removeItems() {
    List<String> list = new ArrayList<String>();
    list = populateList(list);  
    System.out.println("List before modification : "+list);
    for (int i = 0; i <  list.size(); i++) {
        String dateNoTime = list.get(i).split(" ")[0];
        System.out.println("   Going over : "+list.get(i));
        if(!dateNoTime.equalsIgnoreCase("2015-01-13")) {
            System.out.println("      Removing : "+list.get(i));
            list.remove(i);
            i = -1; //This is making the loop start from …
Run Code Online (Sandbox Code Playgroud)

java

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

启动多个实例并等待它们完全使用boto3启动

我开始EC2 Instances使用以下代码

def start_ec2_instances(self, instanceids):
    ec2client = boto3.resource('ec2')
    response = ec2client.start_instances(InstanceIds=instanceids)
    return
Run Code Online (Sandbox Code Playgroud)

现在它成功启动.但是,我想使用wait_until_running方法来检查实例的状态,并等到所有实例都启动.

wait_until_running方法只能在单个实例上发出?如何等待已开始使用的实例列表boto3

这就是我目前正在做的事情.但想知道是否还有其他方法可以一次性完成

def wait_until_instance_running(self, instanceids):
    ec2 = boto3.resource('ec2')
    for instanceid in instanceids:
        instance = ec2.Instance(instanceid)
        logger.info("Check the state of instance: %s",instanceid)
        instance.wait_until_running()
    return
Run Code Online (Sandbox Code Playgroud)

amazon-ec2 amazon-web-services boto3

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

为什么会抛出并发修改异常

当特定地图中有多个修改时,以下代码可以正常工作.但是当只有一个修改时,它会抛出并发修改异常

for(Map.Entry<String, List<String>> mapEntry : beanMap.entrySet()) {
    for(String dateSet : dateList) {
        String mName = mapEntry.getKey();
        boolean dateFound = false;
        if(beanMap.containsKey(dateSet)) {
            dateFound = true;
            System.out.println("    Found : "+mapEntry.getKey());
        }
        if(!dateFound)
        {
            Map<String, List<String>> modifiedMap = beanMap;
            List<String> newBeanList = new ArrayList<String>();
            dBean beanData = new Bean(dateSet+"NA","NA","NA",0,0,0);
            newBeanList.add(beanData);
            System.out.println("    Adding : "+dateSet+" "+"NA");
            modifiedMap.put(mName, newBeanList);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

在上面的代码中,只修改一次"modifiedMap"时抛出ConcurrentModificationException.可能还有更多,但无法找出原因.

java

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

使用 Boto3 启动多个 EC2 实例

我正在使用下面的代码获取实例列表

    def list_instances_by_tag_value(self, tagkey, tagvalue):
    ec2client = boto3.client('ec2')
    response = ec2client.describe_instances(
        Filters=[
            {
                'Name': 'tag:'+tagkey,
                'Values': [tagvalue]
            }
        ]
    )
    instancelist = []
    for reservation in (response["Reservations"]):
        for instance in reservation["Instances"]:
            instancelist.append(instance["InstanceId"])
    return instancelist
Run Code Online (Sandbox Code Playgroud)

现在该方法list_instances_by_tag_value返回一个List. 现在我需要开始EC2 instances. 所以我正在做类似下面的事情

def start_ec_instances(self, instanceids):
    response = ec2client.start_instances(InstanceIds=instanceids)
    return
Run Code Online (Sandbox Code Playgroud)

instanceids从第一个方法返回的列表在哪里。但是ec2client.start_instances只接受String而不是List.

我知道我可以将其转换listString然后解析它。我需要在 instanceID 前面附加 (') 并在每个实例 ID 之间附加逗号 (,)。

问题是,有没有什么简单的方法可以做到这一点,而不是将列表转换为字符串并执行一些append操作?

它需要看起来像 'i-XXXXXX', 'i-XXXXX', 'i-XXXXXXX'

编辑:当我将列表传递给start_instances …

python amazon-ec2 amazon-web-services boto3

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