看demo結構
有兩種方式
1.
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class userController {
@RequestMapping("/")
public String hello(ModelMap map) {
return "index";
}
}
2.
import org.springframework.core.Ordered;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
public class DefultView extends WebMvcConfigurerAdapter {
public void addViewControllers(ViewControllerRegistry registry){
registry.addViewController("/").setViewName("forward:/index.html");
registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
super.addViewControllers(registry);
}
}
瀏覽器輸入http://localhost:8080 或者 http://127.0.0.1:8080 或者 http://192.168.4.123:8080 即可訪問index.html