Ke Vin
Ke Vin

Reputation: 3750

Why my thymeleaf redirect not work?

i want to direct to main page, but my code won't work, and it not give me some error, it just nothing happened.

here is my bean

<bean id="templateResolver" 
    class="org.thymeleaf.templateresolver.ServletContextTemplateResolver">
    <property name="prefix" value="/WEB-INF/thymeleaf/" />
    <property name="suffix" value=".html" />
    <property name="templateMode" value="HTML5" />
    <!-- Template cache is set to false (default is true).        -->
    <property name="cacheable" value="false" />
</bean>

<bean id="templateEngine" class="org.thymeleaf.spring3.SpringTemplateEngine">
    <property name="templateResolver" ref="templateResolver" />
</bean>


<bean id="thymeleafViewResolver" class="org.thymeleaf.spring3.view.AjaxThymeleafViewResolver">
    <property name="viewClass"
    value="org.thymeleaf.spring3.view.FlowAjaxThymeleafView" />
    <property name="templateEngine" ref="templateEngine" />
</bean>

then i want after i do the insert, the user got directed to main page which is home.html

here is my controller code :

public String saveOrder(SaveOrder saveOrder){
    this.saveService.save(saveOrder);

    return "redirect:home";
}

when i do debug it, the process go to the end of the line, it process the return "redirect:home"; but why it won't direct me? help me to find this out

Upvotes: 2

Views: 2775

Answers (1)

Ivan
Ivan

Reputation: 847

You should've provided whole controller sources. But looking at what you've provided, I can see one error: you need a right slash before "home", so it should be "redirect:/home".

Upvotes: 1

Related Questions