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

时间:2016-12-31 18:37:02

标签: spring spring-mvc apache-tiles request-mapping

我正在使用Spring和Apache Tiles(来管理我的观点)。我有Controller类:

@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>

2 个答案:

答案 0 :(得分:0)

返回的insuranceCompany的视图名称为 mv.addObject("insuranceCompany" ...

insuranceCompany

所以图块名称也是 int DateDifInSecond = EndDate.Subtract(StartDate).TotalSeconds 。 (没有任何斜杠和大写“C”)

答案 1 :(得分:0)

我改变了我的控制器类。我替换了我的createInsuranceCompany方法的返回类型,现在它返回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>