spring-mvc

Spring pagination - request parameters

怎甘沉沦 提交于 2020-07-17 01:34:32
问题 My REST contorller: @GetMapping("/test") public Page<MyObject> pathParamTest(Pageable pageable) { return myService.getPage(pageable); } I send a request like following: localhost:8091/endpoint/test?page=0&size=3&sort=id&direction=DESC It's my response from server: { "content": [ { "id": 1 }, { "id": 2 }, { "id": 3 } ], "last": true, "totalPages": 1, "totalElements": 3, "first": true, "sort": [ { "direction": "ASC", "property": "id", "ignoreCase": false, "nullHandling": "NATIVE", "descending":

Java Spring Security - User.withDefaultPasswordEncoder() is deprecated?

China☆狼群 提交于 2020-07-14 18:47:10
问题 I am very new to java spring security, and was following the Spring.io tutorial guide. As part of this, I edited the WebSecurityConfig class as required: @Configuration @EnableWebSecurity public class WebSecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http .authorizeRequests() .antMatchers("/", "/home").permitAll() .anyRequest().authenticated() .and() .formLogin() .loginPage("/login") .permitAll() .and() .logout()

Get all non-full fields in ElasticsearchRepository's findAll method in Spring Data Elasticsearch

亡梦爱人 提交于 2020-07-14 12:20:23
问题 We are using we're using spring-data-elasticsearch 3.2.6.RELEASE and here is our repository : @Repository public interface IRepository extends ElasticsearchRepository<User, Integer> { List<User> findAll(); } and here is the sample response: [{ "idDl": null, "clientName": null, "Address": null }, { "idDl": 19810008, "clientName": "ABC", "Address": "NYC" }] And we have our own custom implementation to return all values excluding certain fields, as follows: It is exposed as separate REST point.

How to change response when token expire using AuthExceptionEntryPoint?

时光毁灭记忆、已成空白 提交于 2020-07-09 11:47:58
问题 There are two scenarios for 401 Unauthorized response: Token Expired (received from request header) When token expires, It send default spring security exception in response. Token not found (not received in request header) Custom Response It send custom response, using AuthExceptionEntryPoint class. How can i prepare same response into (1)Token Expired that i am sending in (2)Token not found? Following are the configuration: webSecuritycofig.xml <?xml version="1.0" encoding="UTF-8"?> <beans

Change of multiple select handling in Spring Boot 2.3.1

笑着哭i 提交于 2020-07-09 05:13:58
问题 Just faced a wired change of behavior after upgrading the Spring Boot version from 2.3.0 to 2.3.1 There is such a simple Thymleaf view with multi-select control <div class="form-group"> <label for="roles">Roles</label> <select multiple class="form-control" id="roles" th:field="*{roles}" required> <option th:each="role : ${roles}" th:text="${role.name}" th:value="${role.id}" th:selected="${user.roles?.contains(role)}"></option> </select> </div> and POST handling controller method @PostMapping

Spring Expression Language dollar vs hash ($ vs #)

纵饮孤独 提交于 2020-07-09 04:59:48
问题 I'm a little confused concerning when to use $ compared to #. Spring's documentation only uses # I need to know when to use $ and # ? Can i use # in the MVC jsp pages ? 回答1: According to this : ${...} is the property placeholder syntax. It can only be used to dereference properties. #{...} is SpEL syntax, which is far more capable and complex. It can also handle property placeholders, and a lot more besides. Both are valid, and neither is deprecated. 来源: https://stackoverflow.com/questions

Spring Expression Language dollar vs hash ($ vs #)

扶醉桌前 提交于 2020-07-09 04:58:27
问题 I'm a little confused concerning when to use $ compared to #. Spring's documentation only uses # I need to know when to use $ and # ? Can i use # in the MVC jsp pages ? 回答1: According to this : ${...} is the property placeholder syntax. It can only be used to dereference properties. #{...} is SpEL syntax, which is far more capable and complex. It can also handle property placeholders, and a lot more besides. Both are valid, and neither is deprecated. 来源: https://stackoverflow.com/questions

org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL via JDBC Statement in SpringBoot with h2 and JPA

試著忘記壹切 提交于 2020-07-06 20:42:36
问题 While running spring boot with h2 database and JPA i am getting below error. org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL via JDBC Statement at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:67) ~[hibernate-core-5.2.17.Final.jar:5.2.17.Final] at org.hibernate.tool.schema.internal.SchemaCreatorImpl.applySqlString(SchemaCreatorImpl.java:440) [hibernate-core-5.2.17.Final.jar:5.2.17.Final] It is caused due

Using generic JSON Object as Request Body

北城以北 提交于 2020-07-06 11:22:50
问题 I'm having a controller which receives JSON Object as input. But the problem is that, the content of JSON will vary for different requests, so Im not able to map the RequestBody to a POJO. Is there a way I can specify the input parameter as generic JSONObject without having to specify a specific POJO. I tried @RequestBody JSONObject inputJson . But this is throwing bad request from the client side. I'm using spring 3.2.13 and Angular as Front End. Any help is much appreciated. Thanks. 回答1:

Spring boot deployed on tomcat won't start

让人想犯罪 __ 提交于 2020-07-06 03:05:36
问题 I have a working Spring application that contains a embedded Tomcat. As a executable war, it works fine. As I'm going to use AngularJ for the front end, it isn't very practical to have the Spring project in an executable jar, as I will do debugging in the browser and want to be able to quickly edit the js source files. If they are saved in an archive, this is annoying. That's why I want to make it deployable, so it would get unpacked on a tomcat. It seems to be that easy, but I can't get it