小编pyb*_*pyb的帖子

ResultSet:按索引检索列值与按标签检索

使用JDBC时,我经常遇到类似的结构

ResultSet rs = ps.executeQuery();
while (rs.next()) {
    int id = rs.getInt(1);
    // Some other actions
}
Run Code Online (Sandbox Code Playgroud)

我问自己(以及代码的作者)为什么不使用标签来检索列值:

int id = rs.getInt("CUSTOMER_ID");
Run Code Online (Sandbox Code Playgroud)

我听过的最好的解释是关于表现的.但实际上,它是否会使处理速度极快?我不相信,尽管我从未进行过测量.即使按标签检索会慢一点,但在我看来,它提供了更好的可读性和灵活性.
那么有人可以给我很好的解释,避免通过列索引而不是列标签来检索列值吗?这两种方法的优点和缺点是什么(可能是关于某些DBMS)?

java optimization maintenance jdbc resultset

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

如果Google的边框到达南极,则Google地图会绘制错误的圆圈

我正在尝试绘制一个给定半径和中心点的圆.但是,出于某些原因,如果圆圈到达南极,Google Maps for iOS会恢复结果.

这是半径= 6000公里,悉尼中心的结果.它看起来很好:

在此输入图像描述

但是,如果我将半径设置为7000 km,结果将变得无用:

在此输入图像描述

预期结果是:

在此输入图像描述

我用来添加圆圈的代码非常基本:

GMSCircle *geoFenceCircle = [[GMSCircle alloc] init];
geoFenceCircle.radius = 6000000; // Meters
geoFenceCircle.position = _sydneyMarker.position;
geoFenceCircle.fillColor = [UIColor colorWithWhite:0.7 alpha:0.5];
geoFenceCircle.strokeWidth = 3;
geoFenceCircle.strokeColor = [UIColor orangeColor];
geoFenceCircle.map = mapView; 
Run Code Online (Sandbox Code Playgroud)

有没有什么办法解决这一问题?

maps google-maps objective-c ios

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

AWS 配置服务 - 在所有区域实施规则

我需要确保 AWS 中的策略合规性(例如安全组)。我使用 AWS 配置服务和 lambda 函数完成了相同的操作。但是 - AWS 配置服务是特定于区域的,因此需要在所有区域中定义规则。这使得维护变得繁琐。关于如何处理这个问题有其他选择吗?

region amazon-web-services aws-config

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

Spring GlobalExceptionHandler : java.lang.IllegalStateException: 无法解析参数 [0] ... 没有合适的解析器

尝试设置全局异常处理程序以响应通用错误响应时出现以下错误:

@RestControllerAdvice
class GlobalExceptionHandler {

    @ExceptionHandler(HttpClientErrorException::class)
    @ResponseStatus(HttpStatus.BAD_REQUEST)
    fun handleClientException(exception: HttpClientErrorException): ErrorDto {
        // do something with client errors, like logging
        return ErrorDto(errorMessage)
    }

    @ExceptionHandler(Exception::class)
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    fun handleServerException(exception: HttpClientErrorException): ErrorDto {
        // do some other thing with server errors, like alerts
        return ErrorDto(errorMessage)
    }

}

data class ErrorDto(val message: String)

@RestController
class DemoController {
    @GetMapping("/error")
    @ResponseBody
    fun error(): ErrorDto {
        throw RuntimeException("test")
    }
}
Run Code Online (Sandbox Code Playgroud)

和错误:

ExceptionHandlerExceptionResolver : Failure in @ExceptionHandler
public ErrorDto
GlobalExceptionHandler.handleServerException(org.springframework.web.client.HttpClientErrorException)

java.lang.IllegalStateException: Could not resolve parameter [0] in
public …
Run Code Online (Sandbox Code Playgroud)

spring

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

使用java在浮点值中丢失精度

给出下面的测试代码及其输出.当我从数值获得浮点值时,精度会丢失..任何人都可以告诉我为什么这种行为以及如何处理这个问题?

public static void main(String[] args)
    {
        try
        {
            java.lang.Number numberVal = 676543.21;
            float floatVal = numberVal.floatValue();
            System.out.println("Number value    : " + numberVal);
            System.out.println("float value     : " + floatVal);
            System.out.println("Float.MAX_VALUE : " + Float.MAX_VALUE);
            System.out.println("Is floatVal > Float.MAX_VALUE ? " + ( floatVal > Float.MAX_VALUE));
        }catch(Exception e)
        {
            e.printStackTrace();
        }
    }
Run Code Online (Sandbox Code Playgroud)

输出:

    Number value    : 676543.21
    float value     : 676543.2
    Float.MAX_VALUE : 3.4028235E38
    Is floatVal > Float.MAX_VALUE ? false
Run Code Online (Sandbox Code Playgroud)

为什么浮点值小于Float.MAX_VALUE?

java floating-point

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

Spring MockMvc不包含Cookie

我有一个受HTTP Basic身份验证保护的控制器。

我将应用程序设置为使用会话cookie,并且可以正常工作。

但是,当我使用MockMvc测试控制器时,成功的身份验证不会给我任何cookie。

网页配置:

package world.pyb.spring.cookiesdemo;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.annotation.web.servlet.configuration.EnableWebMvcSecurity;
import org.springframework.security.config.http.SessionCreationPolicy;

@Configuration
@EnableWebMvcSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.inMemoryAuthentication().withUser("admin").password("argentina").roles("USER");
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        //@formatter:off
        http.httpBasic()
                .and().authorizeRequests().antMatchers(HttpMethod.GET, "/hello").authenticated()
                .and().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.ALWAYS);
        //@formatter:on
    }
}
Run Code Online (Sandbox Code Playgroud)

简单的控制器:

package world.pyb.spring.cookiesdemo;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {

    @RequestMapping("/hello")
    public String index() {
        return "Greetings from Spring Boot!";
    }

}
Run Code Online (Sandbox Code Playgroud)

不给我会话cookie的简单控制器测试: …

testing cookies spring-mvc spring-security

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

锈:打印!宏直到按 Enter 才执行

我正在研究 Rust,在做猜谜游戏时,我发现了这种奇怪的行为:

use std::io;

fn main() {
    println!("Welcome!");

    let mut input = String::new();
    print!("Please type something:"); // this line is not printed UNTIL the Enter key is pressed
    io::stdin()
        .read_line(&mut input)
        .expect("Failed to read input!");

    println!("Bye!");
}
Run Code Online (Sandbox Code Playgroud)

发生以下情况:

  1. Welcome! 被打印
  2. Please type something: 不打印
  3. 如果您输入一些文本并按 Enter,您将看到您的文本后跟 Please type something:Bye!

如何将消息打印到标准输出并将输入打印在同一行上?

例如:

Please enter your name:
(user types Chuck Norris)
Please enter your name: Chuck Norris
Run Code Online (Sandbox Code Playgroud)

rust

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