小编Nat*_*an 的帖子

DFS 和 BFS 可以互换吗?

我知道 DFS 对某些问题有好处,而 BFS 对其他一些问题有好处,但如果可以使用 DFS 解决某些问题,是否可以用 BFS 解决(可能不太理想)(反之亦然)?有证据吗?谢谢!

algorithm breadth-first-search depth-first-search

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

如何在C中的字符串末尾添加"\n"

我知道怎么在字符串上做,所以"hello world""hello world\n".但是,如果我有类似的东西char *str = "helloworld".,我想在str的末尾添加\n,我该怎么做呢?

c arrays string char

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

拦截器中 Springboot @Autowired 组件的 NullPointerException

我有一个组件,其主要工作是返回 Jedis 实例,它如下所示:

@Component
public class JedisConfig {

    private Jedis jedis;

    public JedisConfig() {
        jedis = new Jedis("localhost", 6379);
    }

    public Jedis getJedis() {return jedis;}
}
Run Code Online (Sandbox Code Playgroud)

然后,我使用 Jedis 实例在拦截器的 preHandler 中执行一些操作:

public class AuthInterceptor implements HandlerInterceptor {

    @Autowired
    private JedisConfig jc;

    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        Jedis jedis = jc.getJedis();
        
        // do some other stuff with jedis below
    }
}

Run Code Online (Sandbox Code Playgroud)

但我在调用时收到 NullPointerException jc.getJedis(),但我不明白为什么会发生这种情况。

在相关说明中,我在单元测试中做了几乎完全相同的事情,并且运行良好:

@Autowired
private JedisConfig jc;

@Test
public void testJedis(){
    Jedis …
Run Code Online (Sandbox Code Playgroud)

java spring redis jedis spring-boot

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