小编Sun*_*aik的帖子

如何在java8中继续在forEach循环中继续

如何在java 8中的forEach循环中编写continue语句.

List<Integer> numList = Arrays.asList(10,21,31,40,59,60);
numList.forEach(x->{
    if(x%2==0){
        continue;
    }
    System.out.println(x);
});
Run Code Online (Sandbox Code Playgroud)

上面的代码给出了编译时错误说继续循环之外

List<Integer> numList = Arrays.asList(10,21,31,40,59,60);
LOOP:numList.forEach(x->{
    if(x%2==0){
        continue LOOP;
    }
    System.out.println(x);
});
Run Code Online (Sandbox Code Playgroud)

上面的代码给出了编译时错误,说明了Undefined Label:LOOP

java java-8

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

如何在Spring AOP中获取HttpServletRequest和HttpServletResponse对象

我想在建议之前在Spring AOP中获取响应对象.如果会话无效,我想重定向到登录页面,但无法在Before advice方法中获取HttpServletResponse对象.

尝试以下方式.

    @Autowired
    private HttpServletResponse response;

    public void setResponse(HttpServletResponse response) {
        this.response = response;
    }
Run Code Online (Sandbox Code Playgroud)

堆栈跟踪:

caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: javax.servlet.http.HttpServletResponse com.****.****.aspect.LogProvider.response; nested exception is 

org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [javax.servlet.http.HttpServletResponse] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:506)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:284)
    ... 33 more
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激.

spring servlets spring-mvc spring-aop

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

休眠的标准是不敏感的?

我正在使用条件api来检查用户名是否存在.之后我正在检查密码.但用户名不区分大小写.我想让它区分大小写.

Criteria criteria2 = session.createCriteria(UserMaster.class);
criteria2.add(Restrictions.eq("userName", userName));
userDetails = (UserMaster)criteria2.uniqueResult();
if(userDetails != null) {
      //logic goes here
 }
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激.

java hibernate

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

如何使用收集器而不是手动放入java 8中的ConcurrentHashMap

如何使用收集器在ConcurrentHashMap中收集手动插入ConcurrentHashMap的实例

ConcurrentHashMap<String, String> configurationMap = new ConcurrentHashMap<>();
List<Result> results = result.getResults();
results.stream().forEach(res -> {
     res.getSeries().stream().forEach(series -> {
         series.getValues().stream().forEach(vals ->{
                 configurationMap.put(vals.get(1).toString(),vals.get(2).toString());
         });
     });
});

//Note: vals is List<List<Object>> type
Run Code Online (Sandbox Code Playgroud)

帮助将不胜感激.

java java-8

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

response.sendRedirect在Servlet过滤器中不起作用

以下过滤器在我的prj2.从那里prj2我正在检查会话是否不在那里我想重定向到prj1具有url 的登录页面/prj1/sessionexpiry.在以下场景中,它不会重定向到登录页面而不会抛出任何异常.

public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)    
throws IOException, ServletException {
    HttpServletResponse hsr = (HttpServletResponse) res;
    HttpServletRequest hreq = (HttpServletRequest) req;
    HttpSession session = hreq.getSession(false);

    if (session == null) {
        hsr.sendRedirect("/prj1/sessionexpiry");
        return;
    } else {
        chain.doFilter(req, res);
    }
}
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激

servlets

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

如何使用JdbcTemplate删除多行

想要借助于删除多行JdbcTemplate.在下面的代码中msgNos是一个String变量,包含逗号分隔值,如26,27.执行语句后,它只删除一条记录.

String sqlQuery = " delete from canned_message where msg_no in (?)";
Object[] params = {msgNos};
int rows = smsdbJdbcTemplate.update(sqlQuery, params);
Run Code Online (Sandbox Code Playgroud)

java spring spring-jdbc

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