//配置默认访问路径 并且自动打开浏览器 需要创建独立文件
1 @Controller
2 public class 3 @RequestMapping("/")
4 public String toIndex() {// 配置默认访问首页
5 return "redirect:/index.jsp";
6 }
7 //自动打开浏览器
8 @EventListener({ApplicationReadyEvent.class})
9 void applicationReadyEvent() {
10 String url = "http://localhost:9999/index.jsp";
11 Runtime runtime = Runtime.getRuntime();
12 try {
13 runtime.exec("rundll32 url.dll,FileProtocolHandler " + url);
14 } catch (IOException e) {
15 e.printStackTrace();
16 }
17 }
18 }
//配置默认启动页面第二种
1 @Configuration
2 public class HomeController extends WebMvcConfigurerAdapter {
3 @Override
4 public void addViewControllers( ViewControllerRegistry registry )
5 {
6 registry.addViewController( "/" ).setViewName( "redirect:/index.jsp" );
7 registry.setOrder( Ordered.HIGHEST_PRECEDENCE );
8 super.addViewControllers( registry );
9 }
10 }
11 //创建一个独立的文件 配置全局启动
12 @SpringBootApplication(scanBasePackages = {"cn.java.controller","cn.java.service.impl"})
13 @MapperScan(value = "cn.java.mapper")
14 public class Application {
15 public static void main(String[] args) {
16 SpringApplication.run(Application.class,args);
17 }
18 }