spring-mvc

Not able to print message from properties file using size annotation using spring-mvc

早过忘川 提交于 2021-01-29 06:40:47
问题 I am completely new to Spring MVC. I have a Student class with below annotation @Size(min=2, max=10 ) public String studentHobby; and a StudentController class: @RequestMapping("admissionSuccess.html") public ModelAndView admissionSuccess(@Valid @ModelAttribute("student") Student student,BindingResult result) { if(result.hasErrors()) { ModelAndView model=new ModelAndView("admissionForm"); return model; } ModelAndView model=new ModelAndView("admissionSuccess"); model.addObject("student"

Getting blank response in spring rest controller unit test cases

我与影子孤独终老i 提交于 2021-01-29 05:06:49
问题 I have written unit test cases for a spring rest controller for below put method @PutMapping("/offers/{jobTitle}") public Offer updateOffer(@PathVariable String jobTitle,@Valid @RequestBody Offer offer) { return offerService.updateNoOfPost(jobTitle, offer); } Below is my service class @Override public Offer updateNoOfPost(String jobTitle, Offer offer) { if(!offerRepository.existsById(jobTitle)) throw new ResourceNotFoundException("JobTitle "+jobTitle+" not found !!"); offer.setNoOfPost(offer

How to enable CORS properly in Spring Restfull WebService?

烈酒焚心 提交于 2021-01-29 04:33:34
问题 what i trying to achieve is consume my spring restful web service in another domain, but when i excute the json url that generated JSON value, my javascript console generate this error : Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:8080/SpringServiceJsonSample/service/updatepool/1. (Reason: CORS header 'Access-Control-Allow-Origin' missing). Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote

IllegalStateException: Cannot initialize context because there is already a root application context present

夙愿已清 提交于 2021-01-29 04:25:59
问题 In my application there are 2 initializers: one extends AbstractSecurityWebApplicationInitializer , the other extends AbstractAnnotationConfigDispatcherServletInitializer . When I tried to run the application, I got the an IllegalStateException: Cannot initialize context because there is already a root application context present If I understand correctly, both the initializers tried to create their own WebApplicationContext . So I tried overriding the createRootApplicationContext() to force

Generic DAO implementation, Injection failure @ controller level

江枫思渺然 提交于 2021-01-29 04:23:15
问题 import java.lang.reflect.Field; import java.lang.reflect.ParameterizedType; import java.text.ParseException; import java.util.ArrayList; import java.util.Collection; import java.util.Date; import java.util.List; import java.util.Map; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import javax.persistence.Query; import javax.persistence.Transient; import org.apache.log4j.Logger; import org.springframework.dao.DataAccessException; /** * Generic DAO

IllegalStateException: Cannot initialize context because there is already a root application context present

|▌冷眼眸甩不掉的悲伤 提交于 2021-01-29 04:20:46
问题 In my application there are 2 initializers: one extends AbstractSecurityWebApplicationInitializer , the other extends AbstractAnnotationConfigDispatcherServletInitializer . When I tried to run the application, I got the an IllegalStateException: Cannot initialize context because there is already a root application context present If I understand correctly, both the initializers tried to create their own WebApplicationContext . So I tried overriding the createRootApplicationContext() to force

Using thymeleaf to post form data to a Controller that uses @ModelAttribute (complex objects)

|▌冷眼眸甩不掉的悲伤 提交于 2021-01-29 04:16:16
问题 There is the Element class: public class Element { private Long id; private Name name; // Getters and Setters ... } And the Name class: public class Name { private String en; private String fr; private String de; // Getters and Setters ... } There is a getElementsController: @GetMapping("/elements/create") public String getElementsCreate() { return "private/new-element"; } There is a NewElementController controller: @PostMapping("/elements/create") public String postElementsCreate(

How to do a if else in thymeleaf inside a loop that populate a table

大城市里の小女人 提交于 2021-01-29 04:07:40
问题 I'm populating a table using a <tr th:each> and I want to put a if statement that evaluates the value if it is null, if the values is null I want to put this "--" instead of "null". How can I do this using the th:if or other similar function I am new using thymeleaf? This is my code: <table id="datatable_fixed_column" class="table table-striped table-bordered" width="100%"> <thead> <tr> <th>name</th> <th>lastname</th> <tr> <tbody> <tr th:each="nodeInfo : ${listOfData}"> <td th:if="${nodeInfo

How to redirect page after ajax complete?

Deadly 提交于 2021-01-29 03:57:42
问题 My ajax is performing successfully because it deletes the row from database : @Controller ... @ResponseBody @RequestMapping(value = "/ajaxDeleteUser", method = RequestMethod.POST) public ModelAndView ajaxDelUser(HttpServletRequest request) { int userId = Integer.parseInt(request.getParameter("id")); userDao.delete(userId); return new ModelAndView("redirect:/"); } ... At the view : <c:url value="/" var="home" scope="request" /> $.ajax({ data: {"id":data}, type: "POST", url: "${home}"+

How to redirect page after ajax complete?

半城伤御伤魂 提交于 2021-01-29 03:50:20
问题 My ajax is performing successfully because it deletes the row from database : @Controller ... @ResponseBody @RequestMapping(value = "/ajaxDeleteUser", method = RequestMethod.POST) public ModelAndView ajaxDelUser(HttpServletRequest request) { int userId = Integer.parseInt(request.getParameter("id")); userDao.delete(userId); return new ModelAndView("redirect:/"); } ... At the view : <c:url value="/" var="home" scope="request" /> $.ajax({ data: {"id":data}, type: "POST", url: "${home}"+