spring boot入门

开发软件 sts3.8.4
开发环境 java8
开发工具 Maven

sts下载maven插件,创建maven项目
pom.xml配置文件

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>office</groupId>
  <artifactId>office</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.4.RELEASE</version>
</parent>
<dependencies>

<!-- web应用 -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

<!-- mybatis -->
    <dependency>
        <groupId>org.mybatis.spring.boot</groupId>
        <artifactId>mybatis-spring-boot-starter</artifactId>
        <version>1.3.0</version>
    </dependency>
</dependencies>
</project>

不使用mybatis的可以删掉,由于我本地搭建了别的版本的tomcat,需要指定tomcat版本才能启动,加入了下面这些代码


<!-- tomcat自定义版本 -->
<dependency>
    <groupId>org.apache.tomcat</groupId>
    <artifactId>tomcat-juli</artifactId>
    <version>${tomcat.version}</version>
</dependency>
<!-- 打war包时加入此项, 告诉spring-boot tomcat相关jar包用外部的,不要打进去
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-tomcat</artifactId>
    <scope>provided</scope>
</dependency> -->
<properties>
     <tomcat.version>7.0.69</tomcat.version>
</properties>

这里写图片描述

config 里面是配置文件
MvcConfig是必须的,是配置mvc的文件
WebSecurityConfig是额外的安全插件,无视这个;
dao 里面是mybatis对数据库的操作
domain里是数据库对应的类
service 是服务接口,和dao分离便于数据库的管理
web 是对外访问接口的controller
application是springboot的启动的指定文件,必须放在最外层包名下,不然要额外配置才能运行。

application里的内容都是一致的

@SpringBootApplication
public class Application {

    public static void main(String[] args) throws InterruptedException {
        SpringApplication.run(Application.class, args);
    }

}

MvcConfig里的内容

@Configuration    //springMvc的注解
@MapperScan("com.changyu.office.dao")    //注解扫描的dao层路径
public class MvcConfig extends WebMvcConfigurerAdapter{

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        //添加访问的路径,指定访问的界面
        registry.addViewController("/").setViewName("home.html");
        registry.addViewController("/home").setViewName("home.html");
    }

     @Override
        public void addResourceHandlers(ResourceHandlerRegistry registry) {
            registry.addResourceHandler("/css/**").addResourceLocations(
                    "classpath:/static/css/");  
            registry.addResourceHandler("/images/**").addResourceLocations(
                    "classpath:/static/images/");
            registry.addResourceHandler("/js/**").addResourceLocations(
                    "classpath:/static/js/");
        }
}

写个html界面

<!DOCTYPE html>
<html>
<meta charset="UTF-8"/>
    <head>
        <title>Spring Security Example</title>
    </head>
    <body>
        <h1>Welcome!哈哈哈哈</h1>
    </body>
</html>

然后 run as –> spring boot app 就可以跑起来了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值