JAVA-32055 Upgrade spring-mvc-forms-thymeleaf to Spring Boot 3 (#16203)

Co-authored-by: timis1 <noreplay@yahoo.com>
This commit is contained in:
timis1 2024-03-26 21:01:32 +02:00 committed by GitHub
parent e1e94a088a
commit c25f863bb2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 9 additions and 15 deletions

View File

@ -10,9 +10,9 @@
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-boot-2</artifactId>
<artifactId>parent-boot-3</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../../parent-boot-2</relativePath>
<relativePath>../../parent-boot-3</relativePath>
</parent>
<dependencies>
@ -43,7 +43,6 @@
</dependencies>
<properties>
<thymeleaf.version>3.0.9.RELEASE</thymeleaf.version>
<start-class>com.baeldung.sessionattrs.SessionAttrsApplication</start-class>
</properties>

View File

@ -1,18 +1,17 @@
package com.baeldung.multipartupload;
import lombok.AllArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;
import static org.springframework.web.bind.annotation.RequestMethod.POST;
import lombok.AllArgsConstructor;
@Controller
@AllArgsConstructor
@ -26,20 +25,20 @@ public class EmployeeController {
return "employee/createEmployeeForm";
}
@RequestMapping(path = "/employee", method = POST, consumes = { MediaType.MULTIPART_FORM_DATA_VALUE })
@PostMapping(path = "/employee", consumes = { MediaType.MULTIPART_FORM_DATA_VALUE })
public String saveEmployee(@ModelAttribute Employee employee) {
employeeService.save(employee);
return "employee/success";
}
@RequestMapping(path = "/requestpart/employee", method = POST, consumes = { MediaType.MULTIPART_FORM_DATA_VALUE })
@PostMapping(path = "/requestpart/employee", consumes = { MediaType.MULTIPART_FORM_DATA_VALUE })
public ResponseEntity<Object> saveEmployee(@RequestPart Employee employee, @RequestPart MultipartFile document) {
employee.setDocument(document);
employeeService.save(employee);
return ResponseEntity.ok().build();
}
@RequestMapping(path = "/requestparam/employee", method = POST, consumes = { MediaType.MULTIPART_FORM_DATA_VALUE })
@PostMapping(path = "/requestparam/employee", consumes = { MediaType.MULTIPART_FORM_DATA_VALUE })
public ResponseEntity<Object> saveEmployee(@RequestParam String name, @RequestPart MultipartFile document) {
Employee employee = new Employee(name, document);
employeeService.save(employee);

View File

@ -13,7 +13,7 @@ import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import org.springframework.web.servlet.view.RedirectView;
@Controller
@RequestMapping("/sessionattributes")
@RequestMapping(value = "/sessionattributes")
@SessionAttributes("todos")
public class TodoControllerWithSessionAttributes {

View File

@ -2,7 +2,6 @@ package com.baeldung.sessionattrs;
import java.util.ArrayDeque;
@SuppressWarnings("serial")
public class TodoList extends ArrayDeque<TodoItem>{
}

View File

@ -1,8 +1,6 @@
package com.baeldung.multipartupload;
import org.junit.jupiter.api.Test;
import org.mockito.BDDMockito;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
@ -10,7 +8,6 @@ import org.springframework.mock.web.MockMultipartFile;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import static org.apache.http.entity.ContentType.DEFAULT_BINARY;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.multipart;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@ -18,7 +15,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
@EnableWebMvc
public class EmployeeControllerIntegrationTest {
private static final MockMultipartFile A_FILE = new MockMultipartFile("document", null, DEFAULT_BINARY.toString(), "Employee Record".getBytes());
private static final MockMultipartFile A_FILE = new MockMultipartFile("document", null, "application/octet-stream", "Employee Record".getBytes());
@Autowired
private MockMvc mockMvc;