- // 配置默认访问路径 并且自动打开浏览器 需要创建独立文件
- @Controller
- public class HomeController {
- @RequestMapping("/")
- public String toIndex() {// 配置默认访问首页
- return "redirect:/index.jsp";
- }
- // 自动打开浏览器
- @EventListener({ApplicationReadyEvent.class})
- void applicationReadyEvent() {
- String url = "http://localhost:9999/index.jsp";
- Runtime runtime = Runtime.getRuntime();
- try {
- runtime.exec("rundll32 url.dll,FileProtocolHandler" + url);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- // 配置默认启动页面第二种
- @Configuration
- public class HomeController extends webMvcConfigurerAdapter {
- @Override
- public void addViewControllers( ViewControllerRegistry registry )
- {
- registry.addViewController( "/" ).setViewName( "redirect:/index.jsp" );
- registry.setOrder( Ordered.HIGHEST_PRECEDENCE );
- super.addViewControllers( registry );
- }
- }
- // 创建一个独立的文件 配置全局启动
- @SpringBootApplication(scanBasePackages = {"cn.java.controller","cn.java.service.impl"})
- @MapperScan(value = "cn.java.mapper")
- public class Application {
- public static void main(String[] args) {
- SpringApplication.run(Application.class,args);
- }
- }
来源: http://www.bubuko.com/infodetail-3439522.html