package com.midm.controller; import java.util.Locale; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.security.core.Authentication; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; /** * 【Web 控制器】{@code FragmentController} * * 类职责: * * * 学习提示:先看类上的 @RequestMapping 路径,再沿 public 方法里的 service 调用链阅读。 */ @Controller public class FragmentController extends BaseController { /** * 处理view。 * * 实现要点:包含 1 个条件分支、0 个循环。 * * 框架注解:{@code @RequestMapping(value = {"/view/**"}, method = {RequestMethod.GET})}。 * * @param request HTTP 请求({@code HttpServletRequest}) * @param response HTTP 响应({@code HttpServletResponse}) * @param authentication Spring Security 认证信息({@code Authentication}) * @param model 参数 {@code model}({@code Model}) * @return 字符串结果 */ @RequestMapping( value = {"/view/**"}, method = {RequestMethod.GET} ) public String view(HttpServletRequest request, HttpServletResponse response, Authentication authentication, Model model) { this.init(request, response, authentication); model.addAttribute("theme", this.theme); if (authentication == null) { model.addAttribute("hasUser", this.userService.hasUser()); } return this.getView(authentication, request.getServletPath()); } /** * 处理resourceView。 * * 框架注解:{@code @RequestMapping(value = {"/view/system/resource"}, method = {RequestMethod.GET})}。 * * @param request HTTP 请求({@code HttpServletRequest}) * @param response HTTP 响应({@code HttpServletResponse}) * @param authentication Spring Security 认证信息({@code Authentication}) * @param locale 参数 {@code locale}({@code Locale}) * @param model 参数 {@code model}({@code Model}) * @param category 分类(app/ota/other/report 等)({@code String}) * @return 字符串结果 */ @RequestMapping( value = {"/view/system/resource"}, method = {RequestMethod.GET} ) public String resourceView(HttpServletRequest request, HttpServletResponse response, Authentication authentication, Locale locale, Model model, @RequestParam String category) { super.init(request, response, authentication); model.addAttribute("category", category); return "template/system/resource.html"; } /** * 处理fragment。 * * 实现要点:包含 1 个条件分支、0 个循环。 * * 框架注解:{@code @RequestMapping(value = {"/fragment/{fragmentName}"}, method = {RequestMethod.GET})}。 * * @param request HTTP 请求({@code HttpServletRequest}) * @param response HTTP 响应({@code HttpServletResponse}) * @param authentication Spring Security 认证信息({@code Authentication}) * @param locale 参数 {@code locale}({@code Locale}) * @param model 参数 {@code model}({@code Model}) * @param fragmentName 参数 {@code fragmentName}({@code String}) * @return 字符串结果 */ @RequestMapping( value = {"/fragment/{fragmentName}"}, method = {RequestMethod.GET} ) public String fragment(HttpServletRequest request, HttpServletResponse response, Authentication authentication, Locale locale, Model model, @PathVariable String fragmentName) { super.init(request, response, authentication); model.addAttribute("theme", this.theme); if (authentication == null) { model.addAttribute("hasUser", this.userService.hasUser()); } return this.getView(authentication, request.getServletPath()) + " :: fragment"; } /** * 处理fragment。 * * 框架注解:{@code @RequestMapping(value = {"/fragment/{fragmentName}/{blockName}"}, method = {RequestMethod.GET})}。 * * @param request HTTP 请求({@code HttpServletRequest}) * @param response HTTP 响应({@code HttpServletResponse}) * @param authentication Spring Security 认证信息({@code Authentication}) * @param locale 参数 {@code locale}({@code Locale}) * @param model 参数 {@code model}({@code Model}) * @param fragmentName 参数 {@code fragmentName}({@code String}) * @param blockName 参数 {@code blockName}({@code String}) * @return 字符串结果 */ @RequestMapping( value = {"/fragment/{fragmentName}/{blockName}"}, method = {RequestMethod.GET} ) public String fragment(HttpServletRequest request, HttpServletResponse response, Authentication authentication, Locale locale, Model model, @PathVariable String fragmentName, @PathVariable String blockName) { super.init(request, response, authentication); return this.getView(authentication, "/fragment/" + fragmentName) + " :: " + blockName; } /** * 处理dialog。 * * 实现要点:包含 1 个条件分支、0 个循环。 * * 框架注解:{@code @RequestMapping(value = {"/dialog/{dialogName}"}, method = {RequestMethod.GET})}。 * * @param request HTTP 请求({@code HttpServletRequest}) * @param response HTTP 响应({@code HttpServletResponse}) * @param authentication Spring Security 认证信息({@code Authentication}) * @param locale 参数 {@code locale}({@code Locale}) * @param model 参数 {@code model}({@code Model}) * @param dialogName 参数 {@code dialogName}({@code String}) * @param category 分类(app/ota/other/report 等)({@code String}) * @return 字符串结果 */ @RequestMapping( value = {"/dialog/{dialogName}"}, method = {RequestMethod.GET} ) public String dialog(HttpServletRequest request, HttpServletResponse response, Authentication authentication, Locale locale, Model model, @PathVariable String dialogName, @RequestParam(required = false) String category) { this.init(request, response, authentication); model.addAttribute("theme", this.theme); if (authentication == null) { model.addAttribute("hasUser", this.userService.hasUser()); } return this.getView(authentication, request.getServletPath()) + " :: dialog"; } }