Create a Delete Function¶
This section describes the delete function based on an example application.
- Description of the function to be created
- Click the project ID in the project list.
- Click the change(変更) button on the details screen.
- Click the delete (削除) button on the update screen.
- The completion screen is displayed.
Delete¶
The basic implementation method of the delete function is described in the following order:
- Create a delete button on the update screen
- Create a delete button on the update screen. For description on creating the update screen, see create business action method to display the update screen and create update screen JSP.
- Create a business action method for deletion
Create a business action method to delete the target project from the database.
- ProjectAction.java
@OnDoubleSubmission public HttpResponse delete(HttpRequest request, ExecutionContext context) { // The project information is stored in the session when the update screen is displayed Project project = SessionUtil.delete(context, "project"); UniversalDao.delete(project); return new HttpResponse(303, "redirect://completeOfDelete"); }
- Key points of this implementation
- Deletion with the primary key can be performed without creating SQL by executing UniversalDao#delete with the entity set in the primary key as an argument.
Tip
Universal DAO provides only the function to delete with the primary key as a condition. When deleting with a condition other than the primary key, a separate SQL is required to be created and executed. For information on how to execute SQL, see execute SQL by specifying SQL ID.
- Create a deletion completion screen
- Displays the deletion completion screen. For description on creating the completion screen, see create business action method to display the completion screen and create update completion screen.
This completes the description of the deletion function.