开发者社区> 问答> 正文

来个高手知道一下springmvc的URL配置:报错

,我想要实现的结果是  http://localhost:8080/index/1   而不是这样的http://localhost:8080/domain/index/1       就是可以不通过类的指向直接访问方法名吗,或者这样也可以直接http://localhost:8080/domain/1          2个只能留一个,,里面方法比较多,求高手解决  下面是我的代码,

@Controller
@RequestMapping("domain")
public class DomainController extends BaseController {


@RequestMapping("/index/{domainId}")
public String showNewDomain(@PathVariable("domainId") int domainId,
ModelMap modelMap, HttpServletRequest request) {
Map<String, Object> maps = new HashMap<String, Object>();
if (0 == domainId) {
maps.put("domainId", 0);
modelMap.addAttribute("domainName", "域");
} else {
maps.put("domainId", domainId);


modelMap.addAttribute("domainName",
s.domainService.getDomainVo(maps).getDomainName());
}
modelMap.addAttribute("styleList", s.styleService.getStyleTop5BydomainId(domainId,0,5,1,1));
modelMap.addAttribute("productList", s.productService.getProudctTop5BydomainId(domainId,0,5,1,1));
modelMap.addAttribute("userId", getUserId(request));
return "index/domain";
}



   

展开
收起
kun坤 2020-06-20 11:35:39 1124 0
1 条回答
写回答
取消 提交回答
  • 删掉@RequestMapping("domain")

    控制器上的方法不要不就得了

    ######

    引用来自“南湖船老大”的评论

    删掉@RequestMapping("domain")

    控制器上的方法不要不就得了

    删掉@RequestMapping("domain")

    控制器上的方法不要不就得了

    或者 把方法上@RequestMapping("/index/{domainId}")的/index去掉

    要想都留着,可以把Controller的去掉,方法上写成

    @RequestMapping({"/domain/{domainId}","/index/{domainId}"})

    ######删除controller上的requestmapping######

    引用来自“南湖船老大”的评论

    删掉@RequestMapping("domain")

    控制器上的方法不要不就得了

    灰常感谢######

    引用来自“Sel8616”的评论

    引用来自“南湖船老大”的评论

    删掉@RequestMapping("domain")

    控制器上的方法不要不就得了

    删掉@RequestMapping("domain")

    控制器上的方法不要不就得了

    或者 把方法上@RequestMapping("/index/{domainId}")的/index去掉

    要想都留着,可以把Controller的去掉,方法上写成

    @RequestMapping({"/domain/{domainId}","/index/{domainId}"})

    灰常感谢,自己研究springmvc呢,还有个问题请教一下哥们,你说怎么可以让我的子页面的链接地址,把主页面的链接地址也带上啊   比如这样的   http://localhost:8080/index/1这是一个人的主页面,我在他的里面在开一个子页面,怎么可以让链接这样表示呢 http://localhost:8080/index/1/indes/20            ######

    删掉第一个RuquestMapping()就行了


    @Controller  

    public class DomainController extends BaseController {


    @RequestMapping("/index/{domainId}")
    public String showNewDomain(@PathVariable("domainId") int domainId,
    ModelMap modelMap, HttpServletRequest request) {
    Map<String, Object> maps = new HashMap<String, Object>();
    if (0 == domainId) {
    maps.put("domainId", 0);
    modelMap.addAttribute("domainName", "域");
    } else {
    maps.put("domainId", domainId);


    modelMap.addAttribute("domainName",
    s.domainService.getDomainVo(maps).getDomainName());
    }
    modelMap.addAttribute("styleList", s.styleService.getStyleTop5BydomainId(domainId,0,5,1,1));
    modelMap.addAttribute("productList", s.productService.getProudctTop5BydomainId(domainId,0,5,1,1));
    modelMap.addAttribute("userId", getUserId(request));
    return "index/domain";

    }



    2020-06-20 11:35:52
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
云栖社区特邀专家徐雷Java Spring Boot开发实战系列课程(第20讲):经典面试题与阿里等名企内部招聘求职面试技巧 立即下载
微服务架构模式与原理Spring Cloud开发实战 立即下载
阿里特邀专家徐雷Java Spring Boot开发实战系列课程(第18讲):制作Java Docker镜像与推送到DockerHub和阿里云Docker仓库 立即下载