Provide server-side rendering using Spring MVC with HTML templates.
When to Use
Use when building applications that render HTML on the server.
Rules
Use @Controller (NOT @RestController)
Return template names (not JSON)
Use Model to pass data to views
Prefer immutable web model types; use Java record for request/response/view DTOs when mutability is not required
For @ModelAttribute, prefer constructor binding for dedicated web-binding objects
Architecture
Controller → handles HTTP requests
Service → business logic
Repository → data access
Routing
Each route returns a full HTML page OR a fragment
Use clear URL structure (e.g. /users, /users/{id})
Web Model Design (Java 17)
Preferred: Java record for immutable web-facing objects (request DTOs, response DTOs, view models, form command objects that are constructor-bound)
Keep web-binding objects separate from domain/persistence objects
Use mutable classes only when property mutation is required by the use case
Do NOT use records for JPA entities that require mutable lifecycle behavior
Example
@Controller
@RequestMapping("/users")
public class UserController {
@GetMapping
public String list(Model model) {
model.addAttribute("users", userService.findAll());
return "users/list";
}
}
Defaults
Template folder: src/main/resources/templates
Naming: feature-based (users/list.html)
Anti-Patterns
Do NOT return JSON
Do NOT use @RestController
Do NOT mix REST and MVC
1---2name: spring-mvc3description: Skill: spring-mvc4---5# Skill: spring-mvc67## Type8core910## Purpose1112Provide server-side rendering using Spring MVC with HTML templates.1314---1516## When to Use1718Use when building applications that render HTML on the server.1920---2122## Rules2324- Use @Controller (NOT @RestController)25- Return template names (not JSON)26- Use Model to pass data to views27- Prefer immutable web model types; use Java `record` for request/response/view DTOs when mutability is not required28- For `@ModelAttribute`, prefer constructor binding for dedicated web-binding objects2930---3132## Architecture3334- Controller → handles HTTP requests35- Service → business logic36- Repository → data access3738---3940## Routing4142- Each route returns a full HTML page OR a fragment43- Use clear URL structure (e.g. /users, /users/{id})4445---4647## Web Model Design (Java 17)4849- Preferred: Java `record` for immutable web-facing objects (request DTOs, response DTOs, view models, form command objects that are constructor-bound)50- Keep web-binding objects separate from domain/persistence objects51- Use mutable classes only when property mutation is required by the use case52- Do NOT use records for JPA entities that require mutable lifecycle behavior5354---5556## Example5758```java59@Controller60@RequestMapping("/users")61public class UserController {6263 @GetMapping64 public String list(Model model) {65 model.addAttribute("users", userService.findAll());66 return "users/list";67 }68}69```7071---7273## Defaults7475* Template folder: `src/main/resources/templates`76* Naming: feature-based (users/list.html)7778---7980## Anti-Patterns8182* Do NOT return JSON83* Do NOT use @RestController84* Do NOT mix REST and MVC
Run npx skillmds@latest add carlnaddy/spring-mvc in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
Skill: spring-mvc It is listed under Coding & Dev Tools on SkillMD.
This skill has not completed SkillMD's automated safety review yet. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
CarlNaddy (@carlnaddy) published this skill. Their other Agent Skills are listed on their SkillMD profile.