Technology excerpt that can be used for creating EC sites in Java training

Settings used this time


dependencies {

Login information retention

It is convenient to pack in a session to carry around login information

public class AccountModel {
	private String id;
	private String name;
public class MainController {

	private AccountModel accountModel;
 * Login process
	 * @param model
	 * @param id
	 * @param post
	 * @return
	public String login(Model model,@RequestParam("id") String id,@RequestParam("pass") String pass) {
 // TODO password check
		return "shop";
  <form method="post" th:action="@{login}">
  	<input type="text" name="id" />
  	<input type="text" name="pass" />
 <button> Login </ button>

With this, you can check it every time you log in for the first time. If you do not check and retain the session information at the time of purchase, you can move to the personal information registration screen.

Data search

See below for the naming rules for methods that are automatically implemented in SpringDataJPA. [Spring Data JPA] Naming rules for automatically implemented methods

public class Item {
	private int id;
	private String name;
	private int price;
public interface ItemRepos extends JpaRepository<Item, Integer> {
	 * select * from item where name like %{name}%
	 * @param name
	 * @return
	public List<Item> findByNameContains(String name);
public class MainController {

	private ItemRepos itemRepos;

 * Search process
	 * @param model
	 * @param name
	 * @return
	public String search(Model model,@RequestParam("name") String name) {
		List<Item> itemList = itemRepos.findByNameContains(name);
		model.addAttribute("itemList", itemList);
		return "shop";

  <form method="post" th:action="@{search}">
  		<input type="text" name="name"/>
 <button> Search </ button>

Data registration

JpaRepository # save performs update if pk is duplicated, insert if not

 * registration process
	 * @param model
	 * @param name
	 * @param price
	 * @return
	public String submit(Model model,@RequestParam("name") String name,@RequestParam("price") String price) {
		Item item = new Item();
		return "shop";


Since we are assuming training this time, we have not implemented detailed parts, but there are many points to consider such as input value check and separation of processing layer.

Recommended Posts

Technology excerpt that can be used for creating EC sites in Java training
Summary of ORM "uroboroSQL" that can be used in enterprise Java
Write a class that can be ordered in Java
Convenient shortcut keys that can be used in Eclipse
Problems that can easily be mistaken for Java and JavaScript
Java (super beginner edition) that can be understood in 180 seconds
[Java 8] Sorting method in alphabetical order and string length order that can be used in coding tests
Reference memo / In-memory LDAP server that can be embedded in Java
Static analysis tool that can be used on GitHub [Java version]
Note that system properties including JAXBContext cannot be used in Java11
I made a question that can be used for a technical interview
SwiftUI View that can be used in combination with other frameworks
[Java 8] Until converting standard input that can be used in coding tests into a list or array
Java file input / output processing that can be used through historical background
Java code that cannot be used from Kotlin (for in-house study sessions)
[Spring Boot] List of validation rules that can be used in the property file for error messages
[Android Studio] Description that can be continuously input in SQLite Database [Java]
[Android] I want to create a ViewPager that can be used for tutorials
I made a THETA API client that can be used for plug-in development
Technology for reading Java source code in Eclipse
Organize methods that can be used with StringUtils
[Ruby] Methods that can be used with strings
The story that the port can no longer be used in the Spring boot sample program
Basic functional interface that can be understood in 3 minutes
This and that for editing ini in Java. : inieditor-java
[Java] Explains ConcurrentModificationException that occurs in java.util.ArrayList for newcomers
About the matter that hidden_field can be used insanely
Ruby on Rails 5 quick learning practice guide that can be used in the field Summary
Introduction of jQuery-until it can be used (record executed in preparation for asynchronous communication) haml
Summary of css selectors that can be used with Nookogiri
Create a page control that can be used with RecyclerView
Create a jar file that can be executed in Gradle
The case that @Autowired could not be used in JUnit5
Firebase-Realtime Database on Android that can be used with copy
[Question] Can nullif be used in the count function in JPQL?
Introduction to Rakefile that can be done in about 10 minutes
Java 14 new features that could be used to write code
Whether options can be used due to different Java versions
Tools and commands that may be useful for Java troubleshooting
Object-oriented design that can be used when you want to return a response in form format
How to make a key pair of ecdsa in a format that can be read by Java