spring-mvc

In Spring 3 is it possible to dynamically set the reason of @ResponseStatus?

被刻印的时光 ゝ 提交于 2020-01-12 02:31:32
问题 I have a custom exception class annotated to return a given HttpStatus : @ResponseStatus(value=HttpStatus.BAD_REQUEST, reason="Invalid parameter") public class BadRequestException extends RuntimeException { public BadRequestException(String msg) { super(msg); } } This works when I throw a BadRequestException from my controller but the reason is always "Invalid parameter" of course. Is there a way to set the returned reason in this class? I'd like to pass a string to be used as the reason.

Session management with Spring Boot?

断了今生、忘了曾经 提交于 2020-01-11 21:55:19
问题 I want to set up session management and authentication with Spring Boot. Specifically, when the user logs into my web application, they should be able to call my REST API to get data. Furthermore, after a certain period of time, they should be automatically logged out of the system at which point any REST calls should also fail. How can I accomplish this with Spring Boot ? 回答1: You can make use of Spring Session works well with spring boot Docs :http://docs.spring.io/spring-session/docs

How can I retrieve the list of object associated as field into an entity class?

╄→гoц情女王★ 提交于 2020-01-11 12:47:30
问题 when i fine a Customer by any of his fields, everything goes well, i get the JSON with the global object returned. i am writing a code to fine a Customer By his lastName . The Customer Entity has and object in wich the field lastName is declared. So i want my Endpoint to return the Customer Global Object as in the first case. I have into my postman Status 200 OK, but with and empty body. Any solution ? THANKS here is a sample. The lastName field is declared both into the prefBillAddressUid

Jackson bidirectional relationship (One-to-many) not working

百般思念 提交于 2020-01-11 12:42:16
问题 I'm using Spring(xml+annotations), Hibernate(annotations) in this web service project. The database relationship diagram, models, expected and actual output are given below, Database Table relationship Customer.java @Entity @Table(name="customer") public class Customer implements Serializable{ private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy=GenerationType.IDENTITY) @Column(name="customer_id", unique=true, nullable =false) long customerId; @Column(name="name")

Jackson bidirectional relationship (One-to-many) not working

江枫思渺然 提交于 2020-01-11 12:42:06
问题 I'm using Spring(xml+annotations), Hibernate(annotations) in this web service project. The database relationship diagram, models, expected and actual output are given below, Database Table relationship Customer.java @Entity @Table(name="customer") public class Customer implements Serializable{ private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy=GenerationType.IDENTITY) @Column(name="customer_id", unique=true, nullable =false) long customerId; @Column(name="name")

Binding child object on submit spring mvc

浪尽此生 提交于 2020-01-11 12:04:17
问题 I'm newbie in Java so this question looks so simple. I have a model like: @Entity(name="website") public class Website { @Id @GeneratedValue(strategy=GenerationType.IDENTITY) @Column(name="websiteId", nullable=false, unique=true) private long websiteId; @ManyToOne @JoinColumn(name = "publisherId") private Publisher publisher; public Website() { } //... all getter and setter.... } You see, inside Website class, i have an object of Publisher type: @Entity(name="publisher") public class

How to change/update/delete a property in ConfigurableEnvironment of Spring

て烟熏妆下的殇ゞ 提交于 2020-01-11 10:07:10
问题 In Spring you can use inject an Environment object to read all environment properties @Resource private org.springframework.core.env.Environment environment; So the question is can I programatically change an value of some property? The only workaround I see is to get the all MutablePropertySource that holds this property. to remove this source completely from the environment and to add a new PropertySource that contains all properties of the previous one + the changed one (or the removed one

Spring Boot - unable to add JS in a webpage

半腔热情 提交于 2020-01-11 09:54:26
问题 I have a simple webpage and want to add JS to it. The controller rendering the page is - @Controller @RequestMapping("/testui") public class GreetingController { @RequestMapping("/greeting") public String greeting(@RequestParam(value="name", required=false, defaultValue="World") String name, Model model) { model.addAttribute("name", name); return "pages/greeting"; } } The struture of my resources folder are - src/main/resources | -- static --templates | --css --js --pages The Thymeleaf page

Failed to convert value of type 'org.springframework.web.multipart.commons.CommonsMultipartFile' to required type

耗尽温柔 提交于 2020-01-11 09:42:55
问题 I have following controller method: @RequestMapping(value = "/owner/terminals/save", method = RequestMethod.POST) public String saveTerminal( @RequestParam(value = "name") String name, @RequestParam(value = "file") @Valid OnlyForImagesFileWrapper file, BindingResult bindingResult ) { ... and I see the following stacktrace: org.springframework.beans.ConversionNotSupportedException: Failed to convert value of type 'org.springframework.web.multipart.commons.CommonsMultipartFile' to required type

Failed to convert value of type 'org.springframework.web.multipart.commons.CommonsMultipartFile' to required type

喜欢而已 提交于 2020-01-11 09:42:09
问题 I have following controller method: @RequestMapping(value = "/owner/terminals/save", method = RequestMethod.POST) public String saveTerminal( @RequestParam(value = "name") String name, @RequestParam(value = "file") @Valid OnlyForImagesFileWrapper file, BindingResult bindingResult ) { ... and I see the following stacktrace: org.springframework.beans.ConversionNotSupportedException: Failed to convert value of type 'org.springframework.web.multipart.commons.CommonsMultipartFile' to required type