<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    皮杜妮

      BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
      887 Posts :: 3 Stories :: 7 Comments :: 0 Trackbacks
    spring boot 是spring 4.0提供的微框架,支持 jdk 1.8, maven 3以上,  否則會報一些錯誤。

    1. pom 文件, 主要寫依賴關系,
    <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>com.example</groupId>
        <artifactId>spring-boot</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <name>spring-boot-example</name>
        
        <parent>
           <groupId>org.springframework.boot</groupId>
           <artifactId>spring-boot-starter-parent</artifactId>
           <version>1.3.3.RELEASE</version>
        </parent>
        
        <!-- Add typical dependencies for a web application -->
        
        <dependencies>
            <dependency>
               <groupId>org.springframework.boot</groupId>
               <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
            
            
            
        </dependencies>

        <repositories>
            <repository>
                <id>spring-snapshots</id>
                <url>http://repo.spring.io/libs-snapshot</url>
            </repository>
        </repositories>

        <pluginRepositories>
            <pluginRepository>
                <id>spring-snapshots</id>
                <url>http://repo.spring.io/libs-snapshot</url>
            </pluginRepository>
        </pluginRepositories>

        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
        </build>
    </project>

    2. 然后就是提供的接口類UserController, 實體類User, 主要是幾個注解
    @RestController   l類同spring mvc 的@Controller
    @RequestMapping   類同spring mvc

    package two;

    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;

    @RestController
    @RequestMapping("/user")

    public class UserController {

        @RequestMapping("/hello")
        public User view(){
            
            User user=new User();
            user.setId((long)100);
            user.setName("fanjs");
            return user;
            
            
        }

    package two;

    public class User {
    private Long id;
    private String name;
    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }


    3.  然后就是程序啟動,這里不需要spring xml文件,完全依賴注解。
    @EnableAutoConfiguration
    @Configuration
    @ComponentScan

    package two;

    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
    import org.springframework.context.annotation.ComponentScan;
    import org.springframework.context.annotation.Configuration;

    @Configuration
    @ComponentScan
    @EnableAutoConfiguration


    public class RunMain {

        /**
         * @param args
         */
        public static void main(String[] args) {
            // TODO Auto-generated method stub

            SpringApplication.run(RunMain.class, args);
        }

    }

    4.  測試路徑

    http://localhost:8080/user/hello

    {"id":100,"name":"fanjs"}






    posted on 2016-05-04 15:39 豬眼睛 閱讀(198) 評論(0)  編輯  收藏 所屬分類: Spring
    主站蜘蛛池模板: 国产偷国产偷亚洲高清日韩| 69精品免费视频| 精品久久久久成人码免费动漫 | 久久亚洲国产午夜精品理论片| 亚洲aⅴ无码专区在线观看春色| 亚洲一区二区三区免费观看| 久久精品国产69国产精品亚洲| 黄色网址免费在线| 成人午夜大片免费7777| 国产亚洲成av片在线观看| 国产亚洲漂亮白嫩美女在线 | 亚洲av无码日韩av无码网站冲| 1000部拍拍拍18勿入免费视频软件 | 国产成人综合亚洲绿色| 在线A级毛片无码免费真人 | 亚洲成a人一区二区三区| 亚洲av成人综合网| 四虎影视无码永久免费| 免费国产a国产片高清| 亚洲色成人网站WWW永久四虎| 最近最新高清免费中文字幕| 亚洲AV日韩AV永久无码绿巨人 | 亚洲日本中文字幕区| 无码免费一区二区三区免费播放 | 亚洲Av永久无码精品一区二区| 日本亚洲免费无线码| 亚洲精品欧洲精品| 成年人视频免费在线观看| 久久久久亚洲精品无码蜜桃| 蜜桃视频在线观看免费视频网站WWW| 国产精品亚洲片在线| 91国内免费在线视频| 亚洲AV美女一区二区三区| 日韩免费电影网址| 亚洲一区二区三区高清| **aaaaa毛片免费| 亚洲av成人一区二区三区| 免费无码不卡视频在线观看| 亚洲色大成WWW亚洲女子| 亚洲精品无码久久久久牙蜜区| 国产成人青青热久免费精品|