spring-mvc

Need universal method to read csv files

风流意气都作罢 提交于 2020-06-13 06:26:09
问题 I am working on spring web based application in which I facilitate the user to upload the csv files and all the content of csv file will be stored in my MySQL database. I ma using OpenCsv for reading the CSV files, I wrote a method, which I want to be universal, because right now It only written for my Model Employee , I want to be use it as Utility class. Here it is public static List<Employee> parseCSVWithHeader() throws IOException { CSVReader reader = new CSVReader(new FileReader("emps1

When we must use @ModelAttribute, and how it works

陌路散爱 提交于 2020-06-12 11:44:08
问题 Hello I have question about @ModelAttribute annotation. As i understand, we use @ModelAttribute in method arguments to get data from the model. But it's quite hard to understand clearly when and how its used. (Code samples are from Spring in Action 5 book) Why in this case in the code below in public String processOrder() method we do not use @ModelAttribute annotation on @Valid Order order @Controller @RequestMapping("/orders") @SessionAttributes("order") public class OrderController {

When we must use @ModelAttribute, and how it works

安稳与你 提交于 2020-06-12 11:43:51
问题 Hello I have question about @ModelAttribute annotation. As i understand, we use @ModelAttribute in method arguments to get data from the model. But it's quite hard to understand clearly when and how its used. (Code samples are from Spring in Action 5 book) Why in this case in the code below in public String processOrder() method we do not use @ModelAttribute annotation on @Valid Order order @Controller @RequestMapping("/orders") @SessionAttributes("order") public class OrderController {

Relationship between Spring DispatcherServlet and Filters

血红的双手。 提交于 2020-06-12 09:14:00
问题 Spring MVC uses a DispatcherServlet to route control to an appropriate Controller. But where do filters fit into the flow? If I specify a filter to perform session management or authentication, will the filters always be called before DispatcherServlet? My confusion comes from the fact that they both specify a URL pattern. What happens if they both provide the same url pattern? 回答1: This is not really specific to Spring and Spring MVC. In general fitlers are always called before servlets.

Spring controller method called twice

烂漫一生 提交于 2020-06-12 01:58:03
问题 I'm making a Spring MVC web app. The problem is that on single method is called twice and I don't know why. @RequestMapping(value="/profile/{id}", method = RequestMethod.GET) public String displayUserProfile( @PathVariable String id) { System.out.println("asdasddsasd"); return "account/userProfile"; } I commented many line from this method, but is still not working. Also tried to return other view..no good luck. In console(ulr requests are written): /demo/account/profile/f91b3a38-6921-41e0

Cant persist a Hashset in hibernate

两盒软妹~` 提交于 2020-06-11 12:09:28
问题 I am having trouble in saving a Hashset in hibernate. I am trying to save more than one entries but it is only saving the first item it gets. I am looping through and adding new element to set in every iteration but in the end its size is always 1. After execution, in database table, a new priceList is created but only one entry is created in price table (It should create 5). More info in images. PriceList.java @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Integer id; public

How to POST form-url-encoded data with Spring Cloud Feign

北战南征 提交于 2020-06-09 17:04:47
问题 Using spring-mvc annotations, how can I define an @FeignClient that can POST form-url-encoded? 回答1: Use form encoder for feign: https://github.com/OpenFeign/feign-form and your feign configuration can look like this: class CoreFeignConfiguration { @Autowired private ObjectFactory<HttpMessageConverters> messageConverters @Bean @Primary @Scope(SCOPE_PROTOTYPE) Encoder feignFormEncoder() { new FormEncoder(new SpringEncoder(this.messageConverters)) } } Then, the client can be mapped like this:

Spring Security filter chain not ignoring specified path [duplicate]

牧云@^-^@ 提交于 2020-06-09 04:10:10
问题 This question already has answers here : Prevent Spring Boot from registering a servlet filter (2 answers) Closed 2 years ago . I have a Spring Boot REST API that is authenticating via JWT. My issue is that I have configured Spring Security to allow unrestricted access to the the path used to authenticate /auth/token , but it is still hitting my security filter when it shouldn't be. Not sure where I've got wrong here any advice is greatly appropriated The security config public class

Spring @ModelAttribute Model field mapping

家住魔仙堡 提交于 2020-06-08 19:31:58
问题 I am rewriting an old REST service written in an in-house framework to use Spring. I have a Controller with a POST method which takes a parameter either as a POST or as x-www-form-urlencoded body. Following multiple StackOverflow answers, I used @ModelAttribute annotation and created a model. My problem is that the old REST API is using a property name in snake case - say some_property . I want my Java code to follow the Java naming conventions so in my model the field is called someProperty

Simple spring-boot jar doesn't work except build/target folder

天涯浪子 提交于 2020-06-01 04:48:51
问题 I have a simple spring-boot application but it doesn't work except run from target/build folder. Here are all my config and files. Please help me to find out why it is not working and what is the wrong I am doing. It works perfectly fine while I run from target folder java -jar target\demo-0.0.1-SNAPSHOT and by running from IDE(Eclipse). and my weburl is http://localhost:8082/demo/edit.html . I just copied this jar to different machine/folder it is not longer working. package com.example.demo