[JAVA] If you want to separate Spring Boot + Thymeleaf processing

Using Thymeleaf, I felt "Is there such a usage?", So I will describe it.

For example, the same form is specified as shown below ('/ reservations /'+ $ {date} +'/' + $ {roomId}} ") But suppose you want to separate the processes.

index.html


<form th:action="@{'/reservations/' + ${date} + '/' + ${roomId}}" method="post"
					sec:authorize="${hasRole('ADMIN') or #vars.user.userId==#vars.reservation.user.userId}">
					<!-- th:if="${user.userId==reservation.user.userId}" -->
					<input type="hidden" name="reservationId" th:value="${reservation.reservationId}">
					<input type="submit" name="cancel" value="cancel">
</form>

<form th:action="@{'/reservations/' + ${date} + '/' + ${roomId}}" method="post">
		<input type="text" name="userId">
		<input type="submit" name="search" value="Search">
</form>

Prepare name = "XXXX" as an option of input tag, By specifying (params = "XXXX") in the @GetMapping or @PostMapping option of the Controller You can separate the processing.

Example

index.html


<input type="submit" name="search" value="Search">

Controller.java


@PostMapping(params="search")
	public String search(@RequestParam("userId") String userId, Model model) {

		List<Reservation> lists = reservationService.find(userId);
		model.addAttribute("list", lists);
		return "test";
	}

Recommended Posts

If you want to separate Spring Boot + Thymeleaf processing
If you want to dynamically embed values & add text to attribute values in Thymeleaf 3
When you want to notify an error somewhere when using graphql-spring-boot in Spring Boot
[Spring Boot] If you use Spring Boot, it was convenient to use a lot of util.
If you want to use Mockito with Kotlin, use mockito-kotlin
[Introduction to Spring Boot] Submit a form using thymeleaf
If you want to recreate the instance in cloud9
Try Spring Boot from 0 to 100.
[Java] Thymeleaf Basic (Spring Boot)
Introduction to Spring Boot ① ~ DI ~
Introduction to Spring Boot ② ~ AOP ~
Introduction to Spring Boot Part 1
If you want to study programming at university, go to Australia
[# 3 Java] Read this if you want to study Java! ~ Carefully selected ~
Until INSERT and SELECT to Postgres with Spring boot and thymeleaf
ProxyFactory is convenient when you want to test AOP in Spring!
[PostgreSQL] If you want to delete the Rails app, delete the database first!
I want to understand the flow of Spring processing request parameters
How to set Spring Boot + PostgreSQL
If you want to include the parent class in Lombok's @builder
If you want to change the Java development environment from Eclipse
Spring Boot 2.0 Actuator, 3 changes you need to know to get it working
How to use ModelMapper (Spring boot)
Upgrade spring boot from 1.5 series to 2.0 series
I want to control the default error message of Spring Boot
Thymeleaf usage notes in Spring Boot
Practice to use when you want to execute different processing groups serially
If you get tired of "Spring Boot", why not try "jooby"?
How to apply thymeleaf changes to the browser immediately with #Spring Boot + maven
If you want to use Oracle JDK 11 from September (add Amazon Corretto)
What to do if you get a groovy warning in Thymeleaf Layout
My memorandum that I want to make ValidationMessages.properties UTF8 in Spring Boot
If you want to make a zip file with Ruby, it's rubyzip.
[Swift] If you want to use a URL that includes Japanese, use addingPercentEncoding.
Processing at application startup with Spring Boot
[Introduction to Spring Boot] Form validation check
If you dare to compare Integer with "==" ...
Loosen Thymeleaf syntax checking in Spring Boot
Story when moving from Spring Boot 1.5 to 2.1
Basic Rails commands you want to learn
Changes when migrating from Spring Boot 1.5 to Spring Boot 2.0
Changes when migrating from Spring Boot 2.0 to Spring Boot 2.2
Implement CRUD with Spring Boot + Thymeleaf + MySQL
Asynchronous processing with Spring Boot using @Async
Implement paging function with Spring Boot + Thymeleaf
Spring Boot + Thymeleaf BootStrap installation method memo
What to do if you install Ubuntu
How to split Spring Boot message file
Add spring boot and gradle to eclipse
Run WEB application with Spring Boot + Thymeleaf
If you want to satisfy the test coverage of private methods in JUnit
If you are using Android Room and want to change the column definition
Use Thymeleaf text template mode from Spring Boot
How to use MyBatis2 (iBatis) with Spring Boot 1.4 (Spring 4)
How to use built-in h2db with spring boot
How to make Spring Boot Docker Image smaller
You use context to use MDC with Spring WebFlux
When you want to bind InputStream in JDBI3
How to use Spring Boot session attributes (@SessionAttributes)
The story of raising Spring Boot 1.5 series to 2.1 series
If you don't know Spring Framework, buy this! !! !! !! !! !!