Spring Mvc With Hibernate Example -

package com.example.springmvc.config; import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; public class AppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer @Override protected Class[] getRootConfigClasses() return new Class[] AppContextConfig.class ; @Override protected Class[] getServletConfigClasses() return new Class[] WebMvcConfig.class ; @Override protected String[] getServletMappings() return new String[] "/" ; Use code with caution. 2. Spring MVC View Configuration

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <!DOCTYPE html> <html> <head> <title>User List</title> <style> table border-collapse: collapse; width: 100%; th, td border: 1px solid #ddd; padding: 8px; text-align: left; th background-color: #4CAF50; color: white; tr:nth-child(even) background-color: #f2f2f2; .button padding: 5px 10px; text-decoration: none; border-radius: 3px; .add-button background-color: #4CAF50; color: white; .update background-color: #2196F3; color: white; .delete background-color: #f44336; color: white; .detail background-color: #ff9800; color: white; </style> </head> <body> <h2>User Management System</h2> <a href="$pageContext.request.contextPath/users/showForm" class="button add-button">Add User</a> <br/><br/> <table> <tr> <th>ID</th> <th>Name</th> <th>Email</th> <th>Age</th> <th>Actions</th> </tr> <c:forEach var="user" items="$users"> <tr> <td>$user.id</td> <td>$user.name</td> <td>$user.email</td> <td>$user.age</td> <td> <a href="$pageContext.request.contextPath/users/showFormForUpdate?userId=$user.id" class="button update">Update</a> <a href="$pageContext.request.contextPath/users/delete?userId=$user.id" class="button delete" onclick="return confirm('Are you sure?')">Delete</a> <a href="$pageContext.request.contextPath/users/detail?userId=$user.id" class="button detail">Detail</a> </td> </tr> </c:forEach> </table> </body> </html> spring mvc with hibernate example

@PostMapping("/save") public String saveProduct(@ModelAttribute("product") Product product) if (product.getId() == 0) productService.saveProduct(product); else productService.updateProduct(product); package com

package com.example.dao;

@GetMapping("/detail") public String showUserDetail(@RequestParam("userId") Long id, Model model) User user = userService.getUserById(id); model.addAttribute("user", user); return "user-detail"; table border-collapse: collapse



Copyright © 2006-2026 Sonic Reality - All Rights Reserved.