小编Koi*_*rab的帖子

没有路线匹配[GET]"/ logout"[rails]

单击"注销"时出现以下路由错误:

No route matches [GET] "/logout"
Run Code Online (Sandbox Code Playgroud)

这是我的application.html.erb文件:

 <% if session[:user_id] %>
      <%= link_to 'Logout', logout_path, :method => :delete %>
    <% end %>
Run Code Online (Sandbox Code Playgroud)

这是我的routes.rb文件:

get 'admin' => 'admin#index'
  controller :sessions do
    get 'login' => :new
    post 'login'=> :create
    delete 'logout' => :destroy
  end

  get "sessions/create"
  get "sessions/destroy"
Run Code Online (Sandbox Code Playgroud)

有人知道如何解决这个问题吗?

routes ruby-on-rails

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

使用 Junit 5 参数化对象列表

我想使用 Junit 5 进行参数化测试,它应该调用这样的方法:

service.doSomething(List<Person> persons, int amount);
Run Code Online (Sandbox Code Playgroud)

假设 Person 类如下所示:

Class Person {
   PersonId id;
   String name;
}
Run Code Online (Sandbox Code Playgroud)

问题出在List <Person>. 我不确定应该如何参数化它,使用一些转换器将 Person 值转换为某种原语或使用 ArgumentsAgrragator?另外,Person 包含另一个也需要处理的对象(PersonId)。

您对我如何做到这一点有什么建议吗?

java junit5

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

按钮点击计数器 [PHP]

我尝试创建一个变量来存储单击按钮的计数。不幸的是我收到这个错误:

 Undefined variable: counter
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $counter = isset($_POST['counter']) ? $_POST['counter'] : 0;
    if(isset($_POST["button"])){
        $counter++;
        echo $counter;
    }
}
Run Code Online (Sandbox Code Playgroud)

这是一种形式:

<form action = "<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method = post>
    <input type = "submit" name = "button" value = "Submit" >
    <input type = "hidden" name = "counter" value = "<?php print $counter; ?>"; />
</form>
Run Code Online (Sandbox Code Playgroud)

有人知道我做错了什么吗?

html php

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

org.apache.commons.lang3.StringUtils 与 org.apache.logging.log4j.util.Strings

这两个库都有一些类似的方法(例如isEmptyisNotEmptyisBlank, 等)。

在不同的实现中,我注意到这两个库中的这些方法同样经常被使用。

所以我的问题是 - 如果有的话org.apache.commons.lang3.StringUtilsorg.apache.logging.log4j.util.Strings哪个更好?或者在什么情况下其中一个更好?StringUtils.isEmpty例如,使用or更好吗Strings.isEmpty

java string

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

未定义 startActivity [android]

这是我的代码:

public class PowerConnectionReceiver extends BroadcastReceiver {

    public void onReceive(Context context, Intent intent) {

        Bundle extras = intent.getExtras();

        int status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
        boolean isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING || status == BatteryManager.BATTERY_STATUS_FULL;

        int chargePlug = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);

        intent = new Intent (context, MainActivity.class);
        intent.putExtra("Charging", isCharging);
        startActivity(intent);
    }
}
Run Code Online (Sandbox Code Playgroud)

我认为它应该可以正常工作,但我在startActivity(). 它看起来像是未定义的。有人知道这有什么问题吗?

android

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

从SharedPreference列表中删除项目[android]

我想从我的列表中删除已检查的元素,但不仅来自主应用程序,还来自SharedPreferences.现在,在我的应用程序中,我可以删除chcecked元素,但不能从SharedPreferences中删除,所以如果我回到我的活动,所有删除的元素仍然可见.请帮我.

这是我的活动:

    SharedPreferences preferences;
    ArrayList<Object> list = new ArrayList<Object>();
    ArrayAdapter<Object> adapter;
    List<String> localization;
    Button btnDelete;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_moje_miejsca);

        btnDelete = (Button) findViewById(R.id.btnDelete);
        adapter = new ArrayAdapter<>(this,  android.R.layout.simple_list_item_multiple_choice, list);
        preferences = getSharedPreferences("coordinates", Activity.MODE_PRIVATE);

        Set<String> localizationSet = preferences.getStringSet("localization_set", new HashSet<String>());
        localization = new ArrayList<>(localizationSet);

        for (String listPosition : localizationSet) {
            list.add(listPosition);
            adapter.notifyDataSetChanged();
        }

        setListAdapter(adapter);


public void onClickBtnDelete(View view){

    SharedPreferences.Editor editor = preferences.edit();
    SparseBooleanArray checkedItemPositions = getListView().getCheckedItemPositions();
    int itemCount = getListView().getCount();

    for(int i = itemCount-1; i >= 0; …
Run Code Online (Sandbox Code Playgroud)

java android arraylist sharedpreferences

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

在Swing in Java中拥有自己的布局

我需要一个建议,我应该如何创建自己的布局.我知道我应该从其他几个布局创建它,但我想从中具体了解.这就是我想要的布局看起来像:

我的布局

你能帮助我吗 ?

java swing jpanel jframe layout-manager

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

矩形编码的最小周长

这是任务:

给出一个整数 N,表示某个矩形的面积。

边长为 A 和 B 的矩形的面积为 A * B,周长为 2 * (A + B)。

目标是找到面积等于 N 的任何矩形的最小周长。这个矩形的边应该只是整数。

例如,给定整数 N = 30,面积为 30 的矩形为:

    (1, 30), with a perimeter of 62,
    (2, 15), with a perimeter of 34,
    (3, 10), with a perimeter of 26,
    (5, 6), with a perimeter of 22.
Run Code Online (Sandbox Code Playgroud)

写一个函数:

int solution(int N); 
Run Code Online (Sandbox Code Playgroud)

给定一个整数 N,返回任何面积正好等于 N 的矩形的最小周长。

例如,给定一个整数 N = 30,函数应该返回 22,如上所述。

假使,假设:

    N is an integer within the range [1..1,000,000,000].
Run Code Online (Sandbox Code Playgroud)

复杂:

    expected worst-case time complexity …
Run Code Online (Sandbox Code Playgroud)

java algorithm

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

更新到 Spring Boot 3 后 JMS 不工作(以及 ConnectionFactory 从 javax 到 jakarta)

从 SpringBoot v.2.5.5 更新到 v3.1.0 后,还需要ConnectionFactory从更新javax.jms.ConnectionFactoryjakarta.jms.ConnectionFactory。我没有改变任何其他东西。不幸的是现在我收到这样的错误: ERROR - Could not refresh JMS Connection for destination 'tServerEvent' - retrying using FixedBackOff{interval=5000, currentAttempts=0, maxAttempts=unlimited}. Cause: Could not connect to broker URL: tcp://localhost:61616. Reason: java.net.ConnectException: Connection refused: no further information

我调查了它并与旧的进行了比较javax.ConnectionFactory,似乎brokerUrl它们的默认值是不同的

因为javax.jms.ConnectionFactory它是:vm://localhost?broker.persistent=false 因为jakarta.jms.ConnectionFactory它是:tcp://localhost:61616

即使我手动设置经纪人网址,如下所示:

spring:
  activemq:
    broker-url: vm://localhost?broker.persistent=false
Run Code Online (Sandbox Code Playgroud)

它仍然无法工作,错误是: Cause: Could not create Transport. Reason: java.io.IOException: Transport scheme NOT recognized: [vm]

我不知道为什么 jakarta.ConnectionFactory 和旧 javax.ConnectionFactory 的默认brokerUrl 不同,也不知道如何成功运行我的应用程序。如果您能给我一些提示,我将不胜感激。 …

java jms spring-boot

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