问题列表 - 第277372页

数组:以负索引插入

-1 没有在数组的最后一个索引处插入“hello”

如果我有一个数组,x:

>>> x = [1, 2, 3] then
>>> x.insert(-1, "hello")
>>> print(x)
[1, 2, 'hello', 3]
Run Code Online (Sandbox Code Playgroud)

为什么 -1 不在数组的最后一个索引处插入“hello”?由于 -1 索引指的是列表的最后一项,所以我期待:

[1, 2, 3, “你好”]

python

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

asp-fallback-test-property 与 asp-fallback-test 之间的区别

我试图找出 asp-fallback-test-property 和 asp-fallback-test 之间的区别,两者都使用该属性来确定是否回退。它们是相同还是有区别

下面的链接没有回答差异,而且令人困惑。

https://github.com/aspnet/Mvc/issues/1580

javascript asp.net-core

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

如何正确使用where、whereJsonDoesntContain 和whereJsonContains 的多种组合

PHP 版本 7.2.10 Laravel 版本 5.6.39

我有这样的事情:

$statuses = [4, 5, 6, 7, 14, 15, 16, 17, 18, 19];
$notStatues = [8, 9, 10, 11, 12, 13];

$posts = Post::query();

if ( isset( $queryParams['category'] ) ){
    $posts = $posts->where('post_category', '=', $queryParams['category']);
}
if ( isset( $queryParams['language'] ) ){
    $posts = $posts->where('post_language', '=', $queryParams['language']);
}

//  $posts = $posts->jsonNotContains($statuses);

$posts = $posts->whereJsonContains('post_status_ids', $statuses[0])
    ->orWhereJsonContains('post_status_ids',  $statuses[1])
    ->orWhereJsonContains('post_status_ids',  $statuses[2])
    ->orWhereJsonContains('post_status_ids',  $statuses[3])
    ->orWhereJsonContains('post_status_ids',  $statuses[4])
    ->orWhereJsonContains('post_status_ids',  $statuses[5])
    ->orWhereJsonContains('post_status_ids',  $statuses[6])
    ->orWhereJsonContains('post_status_ids',  $statuses[7])
    ->orWhereJsonContains('post_status_ids',  $statuses[8])
    ->orWhereJsonContains('post_status_ids',  $statuses[9]); …
Run Code Online (Sandbox Code Playgroud)

php laravel eloquent

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

docker-php-ext-configure、docker-php-ext-install 和 docker-php-ext-enable 有什么作用?

我正在尝试使用 docker设置一个LAMP Web 服务器,并且很高兴地发现那里的好人php已经为 php组装了一个 docker 容器

通读文档,我发现三个函数表面上可以帮助我安装 php 扩展;

  • docker-php-ext-configure
  • docker-php-ext-install
  • docker-php-ext-enable

作为一个 php 的完全新手,并且尝试过使用apk addphp.inihackery的组合来启用 php 模块但失败了(导致.so not found错误),我准备承认失败并以正确的方式去做。

不幸的是,文档对于这些命令的作用以及如何使用它们非常模糊:

我们提供帮助脚本 docker-php-ext-configure、docker-php-ext-install 和 docker-php-ext-enable 以更轻松地安装 PHP 扩展。

我也尝试用谷歌搜索它,但也无法在网上找到任何有用的资源。

我现在完全混淆了安装、配置和安装 php 扩展的含义,以及诸如此类的命令apk add php7-*与所有这些的关系。

请解释这些函数的作用,以及如何使用它们来启用php 扩展。

php docker

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

启动层初始化时出错

我按照步骤创建了 HelloWorld 示例,但它没有运行。它给出了以下错误:

启动层初始化时出错 java.lang.module.FindException: Error reading module: F:\Develop\eclipse\HelloWorld\bin Caused by: java.lang.module.InvalidModuleDescriptorException: HelloWorld.class found in top-level directory (模块中不允许使用未命名的包)”

在此处输入图片说明 请指教如何解决这个问题。

java eclipse java-module

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

如何仅在特定片段中实施折叠工具栏

我正在尝试构建一个在所有屏幕上都显示标准工具栏的应用程序,但是当用户导航至屏幕B时,我想显示一个折叠工具栏,该工具栏将向用户显示其他信息。

这里的挑战是我遵循的惯例是,一个活动包含所有常用视图(工具栏,底部应用程序栏,FAB等),并在用户导航到不同屏幕时在活动中间替换片段。我正在使用导航组件来实现此目的。不幸的是,共享工具栏有一个问题:

  • 它是所有屏幕上的标准工具栏,或者是所有屏幕上的可折叠工具栏。

我尝试在不需要折叠时(为了防止折叠效果)将所有东西隐藏在可折叠工具栏中,但这导致工具栏根本没有标题。最有可能与导航组件本身有关。

我还考虑过将折叠的工具栏放在需要它的片段中,并只是将主工具栏隐藏在onResume中,但是布局本身不会相应地进行调整。

您知道可以采用其他方法解决此问题吗?最简单的方法是为每个片段仅拥有一个专用的工具栏,但这将导致大量代码重复,我正尝试避免这种情况。

在我的案例中,关于StackOverflow的类似问题并没有帮助解决此问题。

下面的代码并没有解决所有无法解决的问题,因此我删除了这些更改。

主要活动

class MainActivity : AppCompatActivity(), OnActivityComponentRequest, NavController.OnDestinationChangedListener {

    private lateinit var floatingActionButton: FloatingActionButton
    private lateinit var appBarLayout: AppBarLayout
    private lateinit var navHostFragment: View

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        floatingActionButton = fab
        appBarLayout = app_bar_layout
        navHostFragment = include

        setSupportActionBar(toolbar)

        val navigationController = Navigation.findNavController(this, R.id.nav_host_fragment)
        val appBarConfiguration = AppBarConfiguration(navigationController.graph)

        toolbar.setupWithNavController(navigationController, appBarConfiguration)
        navigationController.addOnDestinationChangedListener(this)
    }

    override fun onDestinationChanged(controller: NavController, destination: NavDestination, arguments: Bundle?) {
        Log.d("MainActivity", "Destination has been changed $destination")
    }

    override fun getFap(): …
Run Code Online (Sandbox Code Playgroud)

navigation layout android

6
推荐指数
0
解决办法
572
查看次数

WebStorm CSS 无法解析自定义属性

从照片中可以看出,在我的 CSS 文件中,我使用了自定义 CSS。WebStorm 给出错误。我该如何解决?

当悬停在它上面时,完整的错误就在这里

Cannot resolve '--color-gray-1' custom property
This inspection warns about CSS custom property variable references which cannot be resolved to any valid target
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

css custom-properties webstorm

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

如何在稳定的 Rust 中声明一个 const String?

我试图const String在稳定的 Rust 中声明一个,但它不允许我声明它:

const CONSTANT_VALUE: String = String::from("constant value");

fn main() {
    println!("{}", TARGET_PORT_KEY);     
}
Run Code Online (Sandbox Code Playgroud)

它说:

常量调用仅限于元组结构和元组变体

我不想将 my 声明string为文字并一直调用to_string()文字。

声明常String量值的正确方法是什么?

操场

string constants literals rust

5
推荐指数
0
解决办法
2155
查看次数

如果响应来自ExceptionHandler,Spring Mvc异步Rest Controller测试将失败:TestDispatcherServlet未设置asyncDispatch CountDownLatch

我有一个Spring Boot 2 MVC应用程序,它返回异步结果。请注意,尽管我正在使用Mono,但它不是webflux应用程序,而是webmvc,因此结果将被视为Spring MVC异步结果(Callable / DeferredResult)。此外,我的控制器为Post输入定义了一个验证器:

@ExceptionHandler
@ResponseStatus(HttpStatus.BAD_REQUEST)
public Flux<ObjectError> exception(MethodArgumentNotValidException ex) {
    logger.error("{}", ex.getLocalizedMessage(), ex);
    return Flux.fromIterable(ex.getBindingResult().getAllErrors());
}

@InitBinder
public void initBinder(WebDataBinder binder) {
    binder.setValidator(customerValidator);
}

@PostMapping(produces = APPLICATION_JSON_UTF8_VALUE)
@ResponseStatus(HttpStatus.CREATED)
public Mono<Customer> createCustomer(@Valid @RequestBody Customer customer) {
    return customerService.create(customer);
}
Run Code Online (Sandbox Code Playgroud)

当我与有效的客户一起运行测试时,它会按预期通过:

@WebMvcTest(CustomerRestController.class)
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@Import({CustomerValidator.class})
class CustomerRestControllerTests {

    @Test
    void shouldCreateNewCustomer() throws Exception {

        Customer customer = new Customer("66666D");
        given(customerService.create(customer)).willReturn(Mono.just(customer));

        MvcResult asyncResult = mockMvc
                .perform(post("/api/v1/customers")
                        .content(objectMapper.writeValueAsString(customer))
                        .accept(MediaType.APPLICATION_JSON_UTF8)
                        .contentType(MediaType.APPLICATION_JSON_UTF8))
                .andReturn();

        final MvcResult result = mockMvc.perform(asyncDispatch(asyncResult))
                .andExpect(status().isCreated())
                .andExpect(header().string("Content-Type", MediaType.APPLICATION_JSON_UTF8_VALUE))
                .andReturn();

        final …
Run Code Online (Sandbox Code Playgroud)

spring spring-mvc spring-boot

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

如何从 Angular 的库中导出模型?

我创建了一个 Angular 库,但我想导出一个我的应用程序可以使用的模型。我怎样才能做到这一点 ?

例如 :

我的图书馆

库-model.ts

export class LibraryModel{
  //some model data
}
Run Code Online (Sandbox Code Playgroud)

my-library.component.ts

import { Component, OnInit, Input } from '@angular/core';

//some imports    

@Component( {
    selector: '...',
    templateUrl: '...',
    styleUrls: [...]
} )
export class MyLibraryComponent implements OnInit {

    @Input() libInputData: LibraryModel;

    // some other codes
}
Run Code Online (Sandbox Code Playgroud)

my-library.module.ts

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';

import { MyLibraryComponent} from './my-library.component';
import { LibraryModel} from './library-model';

@NgModule( {
    declarations: [MyLibraryComponent, LibraryModel],
    imports: [ …
Run Code Online (Sandbox Code Playgroud)

angular angular-library

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