<div id="js_content">
<p style="text-align: center">点击上方 "<a href="http://mp.weixin.qq.com/s?__biz=MzI5ODI5NDkxMw%3D%3D&chksm=eca95686dbdedf90db774b5e1b09caaffbb95e72513a579a5c37c16325ccde7e1d75f0a4e736&idx=2&mid=2247490920&scene=21&sn=84fa3d94375cac784eeb24472f885020#wechat_redirect"><strong>程序员小乐</strong></a>"关注, 星标或置顶一起成长</p>
<p style="text-align: center">后台回复“<strong>大礼包</strong>”有惊喜礼包!</p>
<p style="text-align: center"><img src="https://beijingoptbbs.oss-cn-beijing.aliyuncs.com/cs/5606289-e3c1bbb29b8b03e0c60d06fa65fc8f85"></p>
<pre class="blockcode"><code class="language-php">关注订阅号「程序员小乐」,收看更多精彩内容</code></pre>
<p><strong>每日英文</strong></p>
<p>Sometimes there is no next time, no second chance, no time out. Sometimes it is now or never.</p>
<p>有时候,没有下一次,没有机会重来,没有暂停继续。有时候,错过了现在,就永远永远的没机会了。</p>
<p><strong>每日掏心</strong><strong></strong><strong>话</strong></p>
<p>幸福,就是当激情退去、容颜衰老,牵你的还是那双不怨悔的手;陪你的还是那颗不回头的心;暖你的还是那份不冷却的情。</p>
<p>来自:张伯毅 | 责编:乐乐</p>
<p>链接:s.yam.com/w6mfR</p>
<p><a href="http://mp.weixin.qq.com/s?__biz=MzI5ODI5NDkxMw%3D%3D&chksm=eca95d82dbded494d33755649ad9879e32a3fe8b287cb2ecadb173238aa4ac65df3b6cf16aa7&idx=1&mid=2247489132&scene=21&sn=c15c4bf118abad5bea9afc287585f760#wechat_redirect">程序员小乐(ID:study_tech)</a><a href="http://mp.weixin.qq.com/s?__biz=MzI5ODI5NDkxMw%3D%3D&chksm=eca95d82dbded494d33755649ad9879e32a3fe8b287cb2ecadb173238aa4ac65df3b6cf16aa7&idx=1&mid=2247489132&scene=21&sn=c15c4bf118abad5bea9afc287585f760#wechat_redirect">第 1033 次推文</a></p>
<p style="text-align: left">往日回顾:<a href="http://mp.weixin.qq.com/s?__biz=MzI5ODI5NDkxMw%3D%3D&chksm=ecaae692dbdd6f847903101da56e44451e2574db8175dcb8e505592000234a875d871016cd80&idx=1&mid=2247511420&scene=21&sn=bdc6355d94720d01c60af86b4d08a062#wechat_redirect">955.WLB 不加班公司名单新增 6 家公司,移出 1 家公司!</a></p>
<p><strong> </strong></p>
<p><strong> 正文 </strong></p>
<pre class="blockcode"><code class="language-go">一、注解(annotations)列表
@SpringBootApplication: 包含了@ComponentScan、@Configuration和@EnableAutoConfiguration注解。其中@ComponentScan让spring Boot扫描到Configuration类并把它加入到程序上下文。
@Configuration 等同于spring的XML配置文件;使用Java代码可以检查类型安全。
@EnableAutoConfiguration 自动配置。
@ComponentScan 组件扫描,可自动发现和装配一些Bean。
@Component 可配合CommandLineRunner使用,在程序启动后执行一些基础任务。
@RestController 注解是@Controller和@ResponseBody的合集,表示这是个控制器bean,并且是将函数的返回值直 接填入HTTP响应体中,是REST风格的控制器。
@Autowired 自动导入。
@PathVariable 获取参数。
@JsonBackReference 解决嵌套外链问题。
@RepositoryRestResourcepublic 配合spring-boot-starter-data-rest使用。
二、注解(annotations)详解@SpringBootApplication: 申明让spring boot自动给程序进行必要的配置,这个配置等同于:@Configuration ,@EnableAutoConfiguration 和 @ComponentScan 三个配置。
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication // same as @Configuration @EnableAutoConfiguration @ComponentScan
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
@ResponseBody: 表示该方法的返回结果直接写入HTTP response body中,一般在异步获取数据时使用,用于构建RESTful的api。在使用@RequestMapping后,返回值通常解析为跳转路径,加上@responsebody后返回结果不会被解析为跳转路径,而是直接写入HTTP response body中。
比如异步获取json数据,加上@responsebody后,会直接返回json数据。该注解一般会配合@RequestMapping一起使用。
示例代码:
@RequestMapping(“/test”)
@ResponseBody
public String test(){
return”ok”;
}
@Controller: 用于定义控制器类,在spring 项目中由控制器负责将用户发来的URL请求转发到对应的服务接口(service层),一般这个注解在类中,通常方法需要配合注解@RequestMapping。
示例代码:
@Controller
@RequestMapping(“/demoInfo”)
publicclass DemoController {
@Autowired
private DemoInfoService demoInfoService;
@RequestMapping("/hello")
public String hello(Map<String,Object> map){
System.out.println("DemoController.hello()");
|
|