代码之家  ›  专栏  ›  技术社区  ›  renan gado

如何显示不同于页面JPS页面的URL链接?

  •  0
  • renan gado  · 技术社区  · 7 年前

    我不确定这是否可能。我看到,在Facebook上,当你创建一个商业页面时,你会得到一个带有页码的链接,例如:

    https://www.facebook.com/degendaUK/
    

    我想知道是否有可能创建这样一个链接,而不需要一个名为“DegendaUK”的HTML或JSP页面。

    在我的代码中,我有第页

    http://localhost:8080/offers/empresa?get_Business_ID=29-11-2017-03:39:22R7M5NZ8ZAL
    

    标准页面称为“Empresa”,然后我传递ID以便查询数据库。

    不管怎样,我会得到什么而不是我的URL

    http://localhost:8080/offers/BUSINESS-NAME
    

    没有为每个业务创建JSP页面?

    我正在使用Spring MVC。

    1 回复  |  直到 7 年前
        1
  •  1
  •   TomB    7 年前

    您可以使用Spring@Controller、@RequestMapping和@PathVariable注释来完成此操作。

    @Controller
    public class Controller
    {
        @RequestMapping(value = "/offers/{id}")
        public String offer(@PathVariable String id, final Model model)
        {
            //pass the value from the url to your jsp-view, access it via ${id} from 
            //there
            model.add("id",id);  
            //render the page "empressa.jsp"
            return "empressa";
        }
    }
    

    提示:您可能需要在XML配置中使用一些and才能使这些注释正常工作。 如果您使用的是spring boot,那么应该预先配置它,这已经是现成的了。

    如果这些东西不是公共物品,请不要忘记使用spring security保护它们:)