{"id":879,"date":"2021-08-25T22:21:27","date_gmt":"2021-08-25T14:21:27","guid":{"rendered":"https:\/\/fireinsect.top\/?p=879"},"modified":"2023-05-04T21:52:03","modified_gmt":"2023-05-04T13:52:03","slug":"java%e6%b3%a8%e8%a7%a3%e9%83%a8%e5%88%86%e6%95%b4%e7%90%86","status":"publish","type":"post","link":"https:\/\/fireinsect.top\/index.php\/2021\/08\/25\/java%e6%b3%a8%e8%a7%a3%e9%83%a8%e5%88%86%e6%95%b4%e7%90%86\/","title":{"rendered":"Java\u6ce8\u89e3\u90e8\u5206\u6574\u7406"},"content":{"rendered":"\n<p>Java\u6ce8\u89e3\u672c\u8d28\u662f\u4e00\u4e2a\u7c7b\uff0c\u4f7f\u7528\u65f6\u4e5f\u9700\u8981import\u5f15\u5165\uff0c\u8fd9\u91cc\u53ea\u8bb0\u5f55\u4e86\u6ce8\u89e3\u4f5c\u7528\u4ee5\u53ca\u4f7f\u7528\uff0c\u65e0\u7279\u6b8a\u60c5\u51b5\u6982\u4e0d\u8bb0\u5f55\u5305\u4f4d\u7f6e<\/p>\n\n\n\n<!--more-->\n\n\n\n<p><strong>@SpringBootApplication<\/strong> \u4f5c\u7528\u4e8e\u7c7b\uff0c\u5176\u6ce8\u89e3\u7684\u7c7b\u662f\u6574\u4e2a\u7a0b\u5e8f\u7684\u542f\u52a8\u5165\u53e3<\/p>\n\n\n\n<p><strong>@Service<\/strong> \u4e00\u822c\u60c5\u51b5\u4e0b\u4f7f\u7528\u7684\u6ce8\u89e3\uff0c\u8868\u793a\u7c7b<\/p>\n\n\n\n<p><strong>@Controller<\/strong> Web\u4e2d\u4f7f\u7528\u7684\u6ce8\u89e3\uff0c\u4ee3\u66ffServe<\/p>\n\n\n\n<p><strong>@Repository<\/strong> \u4f5c\u7528\u4e8e\u6301\u4e45\u5316\u76f8\u5173\u7684bean<\/p>\n\n\n\n<p><strong>@Component<\/strong> \u901a\u7528\u6ce8\u89e3\uff0c\u4e0a\u9762\u4e09\u4e2a\u90fd\u62d3\u5c55\u4e8e\u6b64<\/p>\n\n\n\n<p><strong>@Autowired<\/strong> \u81ea\u52a8\u88c5\u8f7dbean\uff0c\u5176\u4e0b\u7684\u5bf9\u8c61\u4f1a\u81ea\u52a8\u5bfb\u627e\u76f8\u5e94\u7684bean\u5e76\u88c5\u8f7d\uff08\u4f5c\u7528\u4e8e\u7c7b\u7684\u5c5e\u6027\uff09<\/p>\n\n\n\n<p><strong>@Resource<\/strong> \u4e5f\u53ef\u4ee5\u81ea\u52a8\u88c5\u8f7dbean\uff0c\u4e14\u652f\u6301byName\u548cbyType\u65b9\u5f0f\u6ce8\u5165\uff08\u4f5c\u7528\u4e8e\u7c7b\u7684\u5c5e\u6027\uff09<\/p>\n\n\n\n<p><strong>@Qualifier<\/strong> \u6307\u5b9a\u81ea\u52a8\u88c5\u914d\u7684\u5bf9\u8c61\u540d\u79f0\uff0c\u901a\u5e38\u4e0e@Autowired\u8054\u5408\u4f7f\u7528<\/p>\n\n\n\n<p><strong>@PostConstruct<\/strong>  \u4f5c\u7528\u4e8e\u65b9\u6cd5\uff0c\u5176\u4e0b\u7684\u65b9\u6cd5\uff0c\u5728\u5bf9\u5e94Bean\u542f\u7528\u65f6\u81ea\u52a8\u6267\u884c\uff08\u56e0\u6b64\u53ea\u80fd\u653e\u5728Bean\u4e0b\u9762\uff09<\/p>\n\n\n\n<p><strong>@PreDestroy<\/strong> \u4f5c\u7528\u4e8e\u65b9\u6cd5 \u6307\u5b9aBean\u9500\u6bc1\u4e4b\u524d\u8c03\u7528\u7684\u65b9\u6cd5<\/p>\n\n\n\n<p><strong>@RequestMapping(&#8220;\/hello&#8221;)<\/strong> \u4f5c\u7528\u4e8e\u65b9\u6cd5\uff0c\u8868\u793a\u8def\u7531\uff08\u5373url\u663e\u793a\uff09<\/p>\n\n\n\n<p><strong>@GetMapping(&#8220;\/html&#8221;)<\/strong> \u4f5c\u7528\u4e8e\u65b9\u6cd5\uff0c\u5bf9\u4e8eGet\u65b9\u6cd5\u7684\u8def\u7531\uff0c\u76f8\u5f53\u4e8eRequestMapping\u7684\u5b50\u96c6<\/p>\n\n\n\n<p><strong>@PostMapping(&#8220;&#8221;)<\/strong> \u4f5c\u7528\u4e8e\u65b9\u6cd5\uff0c\u5bf9\u4e8ePost\u65b9\u6cd5\u7684\u8def\u7531 \u4e0eGetMapping\u4e0d\u540c\u7684\u662f\u53ea\u63a5\u6536 http method\u4e3apost\u8bf7\u6c42\u7684\u6570\u636e<\/p>\n\n\n\n<p>@PathVariable(value=) \u4f5c\u7528\u4e8e\u53c2\u6570\uff0c\u7528\u4e8e\u63a5\u6536URL\u4e2d\u7684\u52a8\u6001\u53c2\u6570\u5373Mapping\u5185\u7684{}\u5185\u6570\u636e<\/p>\n\n\n\n<p><strong>@RequestParam( <strong>name=&#8221;pageNum&#8221;,required = false<\/strong> )<\/strong> \u4f5c\u7528\u4e8e\u53c2\u6570\uff0c\u8868\u793aurl\u4f20\u9012\u53c2\u6570\u5373<strong>url\u540e\u7684 ?id=xxx<\/strong> \u6dfb\u52a0\u540e\u6b64\u53c2\u6570\u503c\u4e3a\u5bf9\u5e94\u4f20\u9012\u53c2\u6570\u503c\uff0c\u524d\u4e00\u53c2\u6570\u8868\u793a\u540d\u5b57\uff0c\u540e\u4e00\u53c2\u6570\u8868\u793a\u662f\u5426\u5fc5\u987b\uff0c\u53ef\u76f4\u63a5\u7b80\u5199\u540d\u5b57\u8868\u793a\u5fc5\u987b<\/p>\n\n\n\n<p><strong>@RequestBody<\/strong> \u4f5c\u7528\u4e8e\u53c2\u6570\uff0c\u7528\u4e8e\u63a5\u6536JSON\u53c2\u6570<\/p>\n\n\n\n<p><strong>@ResponseBody<\/strong> \u4f5c\u7528\u4e8e\u65b9\u6cd5\uff0c\u8868\u793a\u8fd4\u56de\u4e3aJSON\u6570\u503c\u5373\u8868\u9762\u4e3aAPI\uff0c\u53ef\u653e\u5728Mapping\u4e0b<\/p>\n\n\n\n<p><strong>@RestController&nbsp;<\/strong>\u540c\u7b49\u4e8e<strong>@Controller<\/strong>\u52a0\u4e0a<strong>@ResponseBody<\/strong>  \u8868\u793a\u8fd9\u4e2acontrol\u4e0d\u4f1a\u6e32\u67d3\u9875\u9762\u800c\u662f\u8fd4\u56de\u6570\u636e<\/p>\n\n\n\n<p> <strong>@Value(&#8220;${}&#8221;)<\/strong> \u4f5c\u7528\u4e8e\u7c7b\u5c5e\u6027\uff0c\u8868\u793a\u4f7f\u7528\u81ea\u5b9a\u4e49\u914d\u7f6e\u9879\uff0c\u5373\u914d\u7f6e\u6587\u4ef6<strong>application.properties<\/strong> \u4e2d\u81ea\u5b9a\u4e49\u9879\u76ee \u5982user.name=&#8221;aa&#8221;<\/p>\n\n\n\n<p><strong>@Scope<\/strong> \u6307\u5b9abean\u7684\u4f5c\u7528\u57df<\/p>\n\n\n\n<p><strong>@CookieValue(&#8220;name&#8221;)<\/strong> \u4f5c\u7528\u4e8e \u53c2\u6570\uff0c\u901a\u8fc7\u5199\u5165cookie\u540d\u5b57\u4f20\u5165cookie<\/p>\n\n\n\n<p><strong>@NotNull<\/strong> \u4f5c\u7528\u4e8e\u7c7b\u7684\u5c5e\u6027\uff0c\u4e0d\u5141\u8bb8\u4e3anull\u5bf9\u8c61<\/p>\n\n\n\n<p><strong>@AssertTrue<\/strong> \u4f5c\u7528\u4e8e\u7c7b\u5c5e\u6027\u662f\u5426\u4e3a true<\/p>\n\n\n\n<p><strong>@Size(value=) <\/strong>\u4f5c\u7528\u4e8e\u7c7b\u5c5e\u6027\u7ea6\u5b9a\u5b57\u7b26\u4e32\u7684\u957f\u5ea6<\/p>\n\n\n\n<p><strong>@Min(value=) <\/strong>\u4f5c\u7528\u4e8e\u7c7b\u5c5e\u6027 \u5b57\u7b26\u4e32\u7684\u6700\u5c0f\u957f\u5ea6 <\/p>\n\n\n\n<p><strong>@Max(value=) <\/strong>\u4f5c\u7528\u4e8e\u7c7b\u5c5e\u6027 \u5b57\u7b26\u4e32\u7684\u6700\u5927\u957f\u5ea6  <\/p>\n\n\n\n<p><strong>@Email <\/strong>\u4f5c\u7528\u4e8e\u7c7b\u5c5e\u6027 \u662f\u5426\u662f\u90ae\u7bb1\u683c\u5f0f<\/p>\n\n\n\n<p><strong>@NotEmpty<\/strong>\u4f5c\u7528\u4e8e\u7c7b\u5c5e\u6027\uff0c\u4e0d\u5141\u8bb8\u4e3anull\u6216\u8005\u4e3a\u7a7a\uff0c\u53ef\u4ee5\u7528\u4e8e\u5224\u65ad\u5b57\u7b26\u4e32\u3001\u96c6\u5408\uff0c\u6bd4\u5982 Map\u3001\u6570\u7ec4\u3001List<\/p>\n\n\n\n<p><strong>@NotBlank<\/strong> \u4f5c\u7528\u4e8e\u7c7b\u5c5e\u6027\uff0c\u4e0d\u5141\u8bb8\u4e3a null \u548c \u7a7a\u683c<\/p>\n\n\n\n<p><strong>@Valid<\/strong> \u4f5c\u7528\u4e8e\u7c7b\u5c5e\u6027 \u8868\u793a\u68c0\u9a8c\u662f\u5426\u7b26\u5408\u8981\u6c42\uff0c\u4e0e\u4e0a\u9762\u7684\u6ce8\u89e3\u4e00\u8d77\u4f7f\u7528<\/p>\n\n\n\n<div style=\"height:49px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p><strong>@Mapper<\/strong> \u4f5c\u7528\u4e8e\u7c7b \u653e\u5728DAO\u5c42\u8868\u793a\u6620\u5c04\u81f3xml<\/p>\n\n\n\n<p><strong>@Param<\/strong> \u4f5c\u7528\u4e8e\u53c2\u6570 \u5f53DAO\u5c42\u63a5\u53d7\u666e\u901a\u53c2\u6570\uff08\u5373\u9664\u4e86DO\u5bf9\u8c61\uff09\u65f6\u5199\u6b64\u6ce8\u89e3<\/p>\n\n\n\n<p><strong>@Select(&#8220;&#8221;)<\/strong> \u4f5c\u7528\u4e8e\u65b9\u6cd5 \u9ed8\u8ba4\u53c2\u6570\u4e3aSQL \u8868\u793a\u4e3a select SQL\u65b9\u6cd5<\/p>\n\n\n\n<p><strong>@Insert(&#8220;&#8221;)<\/strong> \u4f5c\u7528\u4e8e\u65b9\u6cd5 \u9ed8\u8ba4\u53c2\u6570\u4e3aSQL \u8868\u793a\u4e3a Insert SQL\u65b9\u6cd5 <\/p>\n\n\n\n<p><strong>@Options(&#8220;&#8221;)<\/strong> \u4f5c\u7528\u4e8e\u65b9\u6cd5 \u4f5c\u7528\u4e8eInsert\u4e4b\u540e\uff0c\u8868\u793a\u4e3b\u952e\u8bbe\u7f6e \u4e09\u4e2a\u53c2\u6570  <strong>useGeneratedKeys=bool<\/strong>\uff1a\u662f\u5426\u8fd0\u884c\u4f7f\u7528\u81ea\u589e\u4e3b\u952e  <strong>     keyColumn=\u201c\u201d\uff1a<\/strong>\u8bbe\u7f6e\u8868\u7684\u4e3b\u952e       <strong>keyProperty=\u201c\u201d<\/strong>\uff1a\u8bbe\u7f6eDO\u6a21\u578b\u4e3b\u952e<\/p>\n\n\n\n<p><strong>@Update(&#8220;&#8221;)<\/strong> \u4f5c\u7528\u4e8e\u65b9\u6cd5 \u9ed8\u8ba4\u53c2\u6570\u4e3aSQL \u8868\u793a\u4e3a update SQL\u65b9\u6cd5<\/p>\n\n\n\n<p><strong>@Delete(&#8220;&#8221;)<\/strong> \u4f5c\u7528\u4e8e\u65b9\u6cd5 \u9ed8\u8ba4\u53c2\u6570\u4e3aSQL \u8868\u793a\u4e3a delete SQL\u65b9\u6cd5<\/p>\n\n\n\n<p><strong>@DateTimeFormat(pattern = &#8220;yyyy-MM-dd HH:mm:ss&#8221;)<\/strong> \u4f5c\u7528\u4e8e\u53c2\u6570\uff0c\u7528\u4e8e\u628a\u5b57\u7b26\u4e32\u53c2\u6570\u8f6c\u5316\u4e3a\u65e5\u671f\u7c7b\u578b\uff08\u672c\u8eab\u540e\u9762\u6dfb\u52a0\u7684\u53c2\u6570\u5c31\u662f LocalDateTime\u7c7b\u578b\uff09<\/p>\n\n\n\n<p><strong>@JsonSerialize(using = xxxxx.class) <\/strong>\u4f5c\u7528\u4e8e\u7c7b\u5c5e\u6027\uff0c\u5c06\u4f20\u5165\u7684\u6570\u636e\u8f6c\u6362\u6210\u76f8\u5e94\u7c7b\u578b\uff0c\u4e00\u822c\u4f7f\u7528 <strong>NullSerializer.class<\/strong> \u7528\u4e8e\u8fd4\u56deJSON\u7ed3\u679c\u65f6\uff0c\u5ffd\u7565\uff08\u5373\u4e0d\u51fa\u73b0\uff09\u6b64\u6570\u636e\uff08\u7528\u4e8e\u5982\u5bc6\u7801\uff09\u3002<\/p>\n\n\n\n<p><strong>@JsonFormat(pattern=)<\/strong> \u4f5c\u7528\u4e8e\u7c7b\u5c5e\u6027\uff0c\u5c06\u6570\u636e\u7ed3\u6784\u8f6c\u6362\uff0c\u591a\u4f5c\u7528\u4e8eDate\u7c7b\u578b\uff0c\u7528\u4e8e\u6539\u53d8\u65f6\u95f4\u683c\u5f0f\u5982 <strong>=\u201cyyyy-MM-dd\u201d<\/strong><\/p>\n\n\n\n<p><strong>@JsonProperty(&#8220;name&#8221;)<\/strong> \u4f5c\u7528\u4e8e\u7c7b\u5c5e\u6027\uff0c\u5f53JSON\u8f93\u51fa\u65f6\uff0c\u81ea\u5b9a\u4e49\u5b57\u6bb5\u540d\u79f0<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Java\u6ce8\u89e3\u672c\u8d28\u662f\u4e00\u4e2a\u7c7b\uff0c\u4f7f\u7528\u65f6\u4e5f\u9700\u8981import\u5f15\u5165\uff0c\u8fd9\u91cc\u53ea\u8bb0\u5f55\u4e86\u6ce8\u89e3\u4f5c\u7528\u4ee5\u53ca\u4f7f\u7528\uff0c\u65e0\u7279\u6b8a\u60c5\u51b5\u6982\u4e0d\u8bb0\u5f55\u5305\u4f4d\u7f6e<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","footnotes":""},"categories":[4],"tags":[],"class_list":["post-879","post","type-post","status-publish","format-standard","hentry","category-4"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/fireinsect.top\/index.php\/wp-json\/wp\/v2\/posts\/879"}],"collection":[{"href":"https:\/\/fireinsect.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fireinsect.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fireinsect.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fireinsect.top\/index.php\/wp-json\/wp\/v2\/comments?post=879"}],"version-history":[{"count":30,"href":"https:\/\/fireinsect.top\/index.php\/wp-json\/wp\/v2\/posts\/879\/revisions"}],"predecessor-version":[{"id":1357,"href":"https:\/\/fireinsect.top\/index.php\/wp-json\/wp\/v2\/posts\/879\/revisions\/1357"}],"wp:attachment":[{"href":"https:\/\/fireinsect.top\/index.php\/wp-json\/wp\/v2\/media?parent=879"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fireinsect.top\/index.php\/wp-json\/wp\/v2\/categories?post=879"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fireinsect.top\/index.php\/wp-json\/wp\/v2\/tags?post=879"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}