温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

spring boot学习1————搭建与简单的使用

发布时间:2020-06-24 10:27:09 来源:网络 阅读:462 作者:无语的白痴 栏目:软件技术

    spring boot的搭建非常简单

先创建mavan项目,在java目录下创建一个启动类application(类名随意),此处application文件必须在最外层,spring boot 只会去扫描application低层数文件中的方法spring boot学习1————搭建与简单的使用


用SpringBootApplication注解标识为项目启动类:
Application {
   main(String[] args) {
      SpringApplication.(AccountApplication., args);
   }

}

然后添加依赖:

 <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <version>1.3.5.RELEASE</version>
</dependency>
再是controller层:

用@Controller或@RestController指明为controller
RestController注解的效果相当于@Controller+@ResponseBody,使用RestController时只需直接return字符串就会把数据返回给前端,
方法部分依旧使用@RequestMapping注解
比如:
@Controller
@RequestMapping(value="/test")
public class test{
    @ResponseBody
    @RequestMapping(value="/hello",method = RequestMethod.GET)
    public String  test(){
        System.out.print("11111");
        return "222222";
    }

}
等效于
@RestController
@RequestMapping(value="/test")
public class test{
    @RequestMapping(value="/hello",method = RequestMethod.GET)
    public String  test(){
        System.out.print("11111");
        return "222222";
    }

}

以上spring boot 就算搭好了,spring boot内嵌了tomcat,只需启动main方法,web端就可以访问项目中的方法了
向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI