spring-mvc

What's the intended use of `servlet-context.xml`, `root-context.xml` and `web.xml`?

╄→尐↘猪︶ㄣ 提交于 2021-02-06 11:47:44
问题 I a new to Java Spring MVC web development. I am kind of confused by the 3 config files below. They are auto created by the STS webmvc project template. What's the intended use of them? Why do we need 3 config files rather than a single one? Is there any special reason for their different locations? 回答1: root-context.xml is the Spring Root Application Context Configuration. It's optional. It's for configuring your non-web beans. You need it for Spring Security or OpenEntityManagerInView

What's the intended use of `servlet-context.xml`, `root-context.xml` and `web.xml`?

人走茶凉 提交于 2021-02-06 11:47:18
问题 I a new to Java Spring MVC web development. I am kind of confused by the 3 config files below. They are auto created by the STS webmvc project template. What's the intended use of them? Why do we need 3 config files rather than a single one? Is there any special reason for their different locations? 回答1: root-context.xml is the Spring Root Application Context Configuration. It's optional. It's for configuring your non-web beans. You need it for Spring Security or OpenEntityManagerInView

Spring Unsatisfied dependency expressed through constructor argument with index 0 of type

前提是你 提交于 2021-02-06 10:17:31
问题 The full message is Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userRepositoryUserDetailsService' defined in file [/Users/tdaley/apache-tomcat-8.0.12/wtpwebapps/cloud-management/WEB-INF/classes/ org/cru/cloud/management/security/UserRepositoryUserDetailsService.class]: Unsatisfied dependency expressed through constructor argument with index 0 of type [org.cru.cloud.management.data.UserRepository]: : No qualifying bean of type

Custom converter for @RequestParam in Spring MVC

China☆狼群 提交于 2021-02-06 10:14:08
问题 I am getting an encrypted String as Query parameter to a Spring rest controller method. I wanted to decrypt the string before it reaches the method based on some annotation (say @Decrypt ) like below @RequestMapping(value = "/customer", method = RequestMethod.GET) public String getAppointmentsForDay(@RequestParam("secret") @Decrypt String customerSecret) { System.out.println(customerSecret); // Needs to be a decrypted value. ... } Is a custom Formatter the right approach in this use case? Or

If-Else in a th:each statement in Thymeleaf

你说的曾经没有我的故事 提交于 2021-02-05 20:37:55
问题 What I want is an if-else in a th:each statement in Thymeleaf. If currentSkill != null , then show table with content, else 'You don't have any skills' This is the code without the if/else: <div th:each="skill : ${currentSkills}"> <table> <tr><td th:text="${skill.name}"/></tr> </table> </div> 回答1: <div th:if="${currentSkills != null}"> <table> <tr th:each="skill : ${currentSkills}"><td th:text="${skill.name}"/></tr> </table> </div> <div th:if="${currentSkills == null}"> You don't have any

If-Else in a th:each statement in Thymeleaf

…衆ロ難τιáo~ 提交于 2021-02-05 20:37:01
问题 What I want is an if-else in a th:each statement in Thymeleaf. If currentSkill != null , then show table with content, else 'You don't have any skills' This is the code without the if/else: <div th:each="skill : ${currentSkills}"> <table> <tr><td th:text="${skill.name}"/></tr> </table> </div> 回答1: <div th:if="${currentSkills != null}"> <table> <tr th:each="skill : ${currentSkills}"><td th:text="${skill.name}"/></tr> </table> </div> <div th:if="${currentSkills == null}"> You don't have any

Thymeleaf with Spring Security - how to check if user is logged in or not?

吃可爱长大的小学妹 提交于 2021-02-05 20:27:03
问题 I'm using Spring Boot with Thymeleaf and Spring Security. I've got a simple view with a login link. When the user logs in, I'd like to change login link to logout link. I tried: <div sec:authorize="#{isAuthenticated()}"> <a th:href="@{/logout}">Log out</a> </div> <div sec:authorize="#{isAnonymous()}"> <a th:href="@{/login}">Log in</a> </div> but it's not working - it displays both links. Best regards. EDIT: I solved it. I had to register Thymeleaf dialect. In order to do this, I created a new

Thymeleaf with Spring Security - how to check if user is logged in or not?

前提是你 提交于 2021-02-05 20:19:26
问题 I'm using Spring Boot with Thymeleaf and Spring Security. I've got a simple view with a login link. When the user logs in, I'd like to change login link to logout link. I tried: <div sec:authorize="#{isAuthenticated()}"> <a th:href="@{/logout}">Log out</a> </div> <div sec:authorize="#{isAnonymous()}"> <a th:href="@{/login}">Log in</a> </div> but it's not working - it displays both links. Best regards. EDIT: I solved it. I had to register Thymeleaf dialect. In order to do this, I created a new

Thymeleaf with Spring Security - how to check if user is logged in or not?

北城余情 提交于 2021-02-05 20:18:57
问题 I'm using Spring Boot with Thymeleaf and Spring Security. I've got a simple view with a login link. When the user logs in, I'd like to change login link to logout link. I tried: <div sec:authorize="#{isAuthenticated()}"> <a th:href="@{/logout}">Log out</a> </div> <div sec:authorize="#{isAnonymous()}"> <a th:href="@{/login}">Log in</a> </div> but it's not working - it displays both links. Best regards. EDIT: I solved it. I had to register Thymeleaf dialect. In order to do this, I created a new

How to calculate the sum of variables from JSON data?

时间秒杀一切 提交于 2021-02-05 12:29:14
问题 I wrote a project where the string is returned the other way around. @PostMapping("/reverse") public String reverseList(@RequestBody String string) { List<String> stringList = Arrays.asList(string.split("[+,]")); return IntStream.range(0, stringList.size()) .mapToObj(i -> stringList.get(stringList.size() - 1 - i)) .collect(Collectors.joining("+")); } Command through curl : curl -H "Content-Type: application/json" -d "a1+a2+a3+a4" localhost:8080/hello/reverse Output : a4+a3+a2+a1 How can I