001package org.lanyonm.playground.config; 002 003import org.springframework.stereotype.Component; 004import org.springframework.web.servlet.view.AbstractUrlBasedView; 005import org.springframework.web.servlet.view.InternalResourceViewResolver; 006 007/** 008 * Custom view resolving 009 * 010 * @author lanyonm 011 */ 012@Component 013public class ViewResolver extends InternalResourceViewResolver { 014 015 /** 016 * Use '/WEB-INF/views/' for the prefix and '.jsp' for the suffix. 017 */ 018 public ViewResolver() { 019 super(); 020 setPrefix("/WEB-INF/views/"); 021 setSuffix(".jsp"); 022 } 023 024 @Override 025 protected AbstractUrlBasedView buildView(String viewName) throws Exception { 026 if (viewName.isEmpty() || viewName.endsWith("/")) { 027 viewName += "index"; 028 } 029 return super.buildView(viewName); 030 } 031}