小编Cha*_*lah的帖子

删除R中的冗余列

我有类似的东西:

date        pgm      in.x     logs       out.y
20130514    na       12       j1         12
20131204    z2       03       j1         03
20130516    a01      04       j0         04
20130628    z1       05       j2         05
Run Code Online (Sandbox Code Playgroud)

我注意到in和out值总是一样的,所以我想删除out.y列.我有这样的其他列我希望能够检测匹配.x列的任何.y列并在合并后删除它们.

merge r

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

使用HTTP标头的Spring Security

我正在尝试为我的Spring Boot应用程序添加安全性.我当前的应用程序是使用REST控制器,每次我收到GETPOST请求时,我都会读取HTTP标头以检索用户和密码,以便根据我存储了所有用户的属性文件验证它们.我想将此更改为使用Spring Security,这是我到目前为止所得到的:

public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Bean
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
            .antMatchers("/index.html").permitAll()
            .antMatchers("/swagger-ui.html").hasRole("ADMIN")
            .anyRequest().authenticated();
    }

    @Bean
    public UserDetailsService userDetailsService() {
        InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager();
        manager.createUser(User.withUsername("admin").password("password").roles("ADMIN").build());
    }
}
Run Code Online (Sandbox Code Playgroud)

如何告诉configure方法从头部而不是登录表单中检索用户凭据?

security authentication spring-security http-headers spring-boot

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

JsonPathRequestMatchers 到 ResultMatcher 使用 MockMVC

我正在使用 MockMVC 测试一个 todo 控制器:

            mockMvc.perform(MockMvcRequestBuilders.get("/toDos/")
                    .with(user("user").password("password").roles("ADMIN"))
                    .content("{ \"saved_date\": \"2010-01-01\"}")
                    .accept(MediaType.APPLICATION_JSON_VALUE))
                    .andExpect((ResultMatcher) jsonPath("$.id").doesNotExist())
                    .andExpect(status().isOk())
                    .andExpect( content().contentType("application/json"));
        }
Run Code Online (Sandbox Code Playgroud)

我不断收到此错误:

java.lang.ClassCastException: org.springframework.test.web.client.match.JsonPathRequestMatchers$5 cannot be cast to org.springframework.test.web.servlet.ResultMatcher
Run Code Online (Sandbox Code Playgroud)

我想删除对 (ResultMatcher) 的转换,但不知道如何创建一个 ResultMatcher 来测试 Id 的存在。有任何想法吗 ?

junit spring unit-testing jsonpath mockmvc

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

使用外部 Tomcat 进行 Spring Boot 和日志记录

我正在外部 Tomcat 服务器上部署我的 Spring Boot 应用程序。我似乎无法让我的 Eclipse 控制台显示我在代码中编写的日志消息:

private static final Logger log = LoggerFactory.getLogger(PersonServiceImpl.class);
...
log.info("Running...");
Run Code Online (Sandbox Code Playgroud)

我设法记录了所有休眠跟踪,但仍然无法显示我添加到代码中的日志消息:

logging.level.org.hibernate.SQL=DEBUG
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE
logging.level.root=INFO
logging.level.org.springframework.web=INFO
Run Code Online (Sandbox Code Playgroud)

而且 catalina 日志文件夹不包含我需要的记录信息。

我该怎么办?

java logging spring spring-mvc log4j2

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

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

java Date和LocalDateTime中一个月中的天数

对于startDate和endDate,如何确定以月和日为单位的时间段(剩下的内容):

String pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
SimpleDateFormat format = new SimpleDateFormat(pattern);
Date start = format.parse("2016-11-09T02:00:00.000Z");
Date end = format.parse("2017-09-30T09:00:00.000Z");
Run Code Online (Sandbox Code Playgroud)

结果我想要:10个月和22天(结束日期)

java datetime jodatime

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