Spring Boot学习笔记

生成项目

可以通过Spring官方网站进行生成。
https://start.spring.io

Controller注解

给方法添加注解

    @RequestMapping(value={"/index","/show"},method= RequestMethod.GET)
    @ResponseBody

如果一个Controller中有很多个方法,每个方法都需要使用@ResponseBody注解,此时可以将类注解@Controller换成@RestController。一旦换成@RestController,则方法不再需要注解@ResponseBody。
同时RequestMapping可以换成GetMapping和PostMapping

Spring Boot配置

Spring Boot的内置容器Tomcat/jetty/undertow
修改端口号:application.properties中添加server.port=8081
修改项目路径: server.servlet.context-path=xxxxxxx(2.0版本以后)

修改Spring Boot启动时的横幅

添加banner.txt
或者使用xxx.txt
并进行如下配置:spring.banner.location=classpath:xxx.txt

如果数据库中的某个字段使用了mysql中的关键字,那么在mybatis中select时,应当在此字段添加

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容