繁体   English   中英

Spring Framework将项目迁移到注释配置JAVA

[英]Spring Framework migrating project to anotation configuration JAVA

我想使用注释配置重写项目。 但是我有一个设置请求映射的问题。 我将复制一个控制器,并希望有人可以帮助我处理该url。 localhost:8080/projectName/{url}

@Controller

   public class HomeController {

        private String homeView;

        private DomainManager domainManager;

        public void setHomeView(String homeView) {
            this.homeView = homeView;
        }

        public void setDomainManager(DomainManager domainManager) {
            this.domainManager = domainManager;
        }

        @RequestMapping(method = RequestMethod.GET)
        public String showPage(HttpSession session, Model model) {
            User u = (User) session.getAttribute(User.SESSION_PROPERTY);

            Domain domain = domainManager.getDomain(u.getDomainId());
            Quota used = domainManager.getQuotaUsage(u.getDomainId());
            boolean active = domainManager.isDomainActive(u.getDomainId());

            model.addAttribute("domain", domain);
            model.addAttribute("active", active);
            model.addAttribute("used", used);

            return homeView;
        }

    }

不要忘记在类上添加注释@Controller,请查看spring doc http://docs.spring.io/spring/docs/current/spring-framework-reference/html/mvc.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM