嵌套的@RequestMapping - 它在 Apache Tiles 视图中如何工作?

Nested @RequestMapping - how it works in Apache Tiles view?

我正在使用 Spring 和 Apache Tiles(来管理我的视图)。我有控制器 class:

@Controller
@RequestMapping("/insurancecompany")
public class InsuranceCompanyController {

    @Autowired
    private InsuranceCompanyService insuranceCompanyService;

    @RequestMapping("/create")
    public ModelAndView createInsuranceCompany() {
        ModelAndView mv = new ModelAndView();
        mv.addObject("insuranceCompany", new InsuranceCompany());
        return mv;
    }

我应该在 Apache Tiles xml 文件中写入什么才能使其正常工作?我的 xml 文件

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE tiles-definitions PUBLIC
       "-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN"
       "http://tiles.apache.org/dtds/tiles-config_3_0.dtd">

<tiles-definitions>

    <definition name="main.template" template="/WEB-INF/templates/maintemplate.jsp">
        <put-attribute name="title" value="Welcome on my web app" />
        <put-attribute name="menu" value="/WEB-INF/tiles/menu.jsp" />
        <put-attribute name="body" value="" />
    </definition>
    ...
    <definition name="WHAT SHOULD BE HERE??" extends="main.template">
        <put-attribute name="title" value="Insurance Company" />
        <put-attribute name="body" value="/WEB-INF/tiles/createinsurancecompany.jsp" />
    </definition>

</tiles-definitions>

返回的视图名称ModelAndViewinsuranceCompany

 mv.addObject("insuranceCompany" ...

所以方块名称也是 insuranceCompany。 (没有任何斜杠和大写 "C")

我换了控制器class。我替换了我的 createInsuranceCompany 方法的 return 类型,现在它是 returns String(在 apache tiles xml 文件中使用的唯一名称)

@Controller
@RequestMapping("/insurancecompany")
public class InsuranceCompanyController {

    @Autowired
    private InsuranceCompanyService insuranceCompanyService;

    @RequestMapping("/create")
    public String createInsuranceCompany(Model model) {
        model.addAttribute("insuranceCompany", new InsuranceCompany());
        return "insurancecompany-create";
    }
}

我的 apache xml 文件看起来像这样

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE tiles-definitions PUBLIC
       "-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN"
       "http://tiles.apache.org/dtds/tiles-config_3_0.dtd">

<tiles-definitions>

    <definition name="main.template" template="/WEB-INF/templates/maintemplate.jsp">
        <put-attribute name="title" value="Welcome on my web app" />
        <put-attribute name="menu" value="/WEB-INF/tiles/menu.jsp" />
        <put-attribute name="body" value="" />
    </definition>

    ...

    <definition name="insurancecompany-create" extends="main.template">
        <put-attribute name="title" value="Insurance Company" />
        <put-attribute name="body" value="/WEB-INF/tiles/createinsurancecompany.jsp" />
    </definition>

</tiles-definitions>