更改項(xiàng)目的端口號(hào)
server.port=8081
https://www.bootschool.net/ascii banner(橫幅廣告)
更改項(xiàng)目的端口號(hào)
server.port=8081
k=v
對(duì)空格的要求十分高
普通的key-value
person:
name: sunjina{random.int}
happy: false
birth: 2020/08/06
maps: {k1: sun,k2: jian}
hello: 小狗
lists:
- code
- music
- girl
dog:
name: ${person.hello:小皮}_哈哈
age: 2
@Component注解有什么作用----Springboot

為了妹子而奮斗 2018-04-24 20:53:49


分類專欄: Springboot學(xué)習(xí)與實(shí)戰(zhàn)
用一句話概括:
被@Component注解標(biāo)識(shí)的類,會(huì)被納入Spring容器中統(tǒng)一管理,好處是什么?一句話概括:你不用自己new了!嘿嘿嘿
- @component (把普通pojo實(shí)例化到spring容器中,相當(dāng)于配置文件中的
)
泛指各種組件,就是說當(dāng)我們的類不屬于各種歸類的時(shí)候(不屬于@Controller、@Services等的時(shí)候),我們就可以使用@Component來標(biāo)注這個(gè)類。
未使用yaml配置文件
1.直接在dog.java中賦值


2.讀取配置文件中的值


使用yaml配置文件
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>



使用properties配置文件怎么弄?



松散綁定:



JSR303校驗(yàn)
如果@email注解沒用,就導(dǎo)入
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.1.5.Final</version>
</dependency>
@NotNull(message="名字不能為空")
private String userName;
@Max(value=120,message="年齡最大不能超過120")
private int age;
@Email(message="郵箱格式錯(cuò)誤")
private String email;
-----------------------------------------------------------上面常用,下面了解即可
空檢查
@Null 驗(yàn)證對(duì)象是否為null
@NotNull 驗(yàn)證對(duì)象是否不為null, 無法查檢長(zhǎng)度為0的字符串
@NotBlank 檢查約束字符串是不是Null還有被Trim的長(zhǎng)度是否大于0,只對(duì)字符串,且會(huì)去掉前后空格.
@NotEmpty 檢查約束元素是否為NULL或者是EMPTY.
Booelan檢查
@AssertTrue 驗(yàn)證 Boolean 對(duì)象是否為 true
@AssertFalse 驗(yàn)證 Boolean 對(duì)象是否為 false
長(zhǎng)度檢查
@Size(min=, max=) 驗(yàn)證對(duì)象(Array,Collection,Map,String)長(zhǎng)度是否在給定的范圍之內(nèi)
@Length(min=, max=) string is between min and max included.
日期檢查
@Past 驗(yàn)證 Date 和 Calendar 對(duì)象是否在當(dāng)前時(shí)間之前
@Future 驗(yàn)證 Date 和 Calendar 對(duì)象是否在當(dāng)前時(shí)間之后
@Pattern 驗(yàn)證 String 對(duì)象是否符合正則表達(dá)式的規(guī)則
.......等等
除此以外,我們還可以自定義一些數(shù)據(jù)校驗(yàn)規(guī)則
配置文件位置以及多環(huán)境配置
yaml中端口號(hào)優(yōu)先級(jí)目錄



在同級(jí)目錄遇到多個(gè)配置文件.properties中都有端口號(hào)該如何選擇呢,
在配置文件中添加 spring.profiles.active= test選擇

那yaml中該怎么解決上面的問題呢?
很簡(jiǎn)單,只需要一個(gè)yaml文件,就不用創(chuàng)建多個(gè)propeties文件
spring:
profiles:
active: dev2
通過active選擇自己所寫的端口號(hào)
server:
port: 8081
spring:
profiles:
active: dev2
---
server:
port: 8082
spring:
profiles: dev
---
server:
port: 8083
spring:
profiles: dev2
Spring注解@Controller和的RestController的區(qū)別
@RestController注解相當(dāng)于控制器前加@Controller,方法前加@ResponseBody共同的作用效果。


如果第二段代碼不加@ResponseBody,返回的就是success.jsp頁面,加上之后返回的就是success字符串;而第一段代碼返回的也是success,不再經(jīng)過視圖解析器解析了。
連續(xù)點(diǎn)擊兩次shift 彈出search everywhere窗口即可搜索到WebMvc
導(dǎo)入jquery jar包 https://www.webjars.org/
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>3.5.1</version>
</dependency>
http://localhost:8080/webjars/jquery/3.5.1/jquery.js 查看
resources>static>public 包下放資源優(yōu)先級(jí)
spring.mvc.static-path-pattern=/hello/,classpath:/kuang/ 在配置文件中加了這個(gè),靜態(tài)資源則訪問不到
總結(jié):

? 2.優(yōu)先級(jí)
resources>static>public
spring.mvc.favicon.enabled=false 沒有 不搞了
首頁和圖標(biāo)定制
圖標(biāo)定制沒成功,應(yīng)該springboot的版本問題。算了,不搞了,反正也實(shí)用性不大
然后首頁的話就很簡(jiǎn)單了,直接在resources文件夾下建立一個(gè)public文件夾,然后新建一個(gè).html文件

https://docs.spring.io/spring-boot/docs/2.0.3.RELEASE/reference/htmlsingle/
https://docs.spring.io/spring-boot/docs/2.0.3.RELEASE/reference/htmlsingle/#using-boot-starter
| <dependency> | |
| ------------ | --------------------------------------------------- |
| | <groupId>org.thymeleaf</groupId> |
| | <artifactId>thymeleaf-spring5</artifactId> |
| | </dependency> |
| | <dependency> |
| | <groupId>org.thymeleaf.extras</groupId> |
| | <artifactId>thymeleaf-extras-java8time</artifactId> |
| | </dependency> |
我導(dǎo)入這個(gè)兩個(gè)依賴還是找不到templates文件夾中的.html
怎么解決呢?
導(dǎo)入以下依賴
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
ctrl+i 快速提出方法
http://sc.chinaz.com/moban/200511241330.htm 模板查找
<html lang="en" xmlns:th="http://www.thymeleaf.org" >
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
@Repository注解作用/?
dao層的注解,表示數(shù)據(jù)訪問,對(duì)應(yīng)存儲(chǔ)層的bean,可以將標(biāo)注層中類拋出的數(shù)據(jù)訪問異常封裝為 Spring 的數(shù)據(jù)訪問異常類型。
@Component, @Repository, @Service的三個(gè)spring注解的區(qū)別
https://blog.csdn.net/RAVEEE/article/details/89879698
<link th:href="@{/css/bootstrap.min.css}" rel="stylesheet">
springMVC的注解@RequestParam與@PathVariable的區(qū)別

薛宇Chelly 2017-09-29 21:54:45


收藏 1
分類專欄: Java
版權(quán)
<article class="baidu_pl" style="box-sizing: inherit; outline: 0px; margin: 0px; padding: 16px 0px 0px; display: block; position: relative; color: rgba(0, 0, 0, 0.75); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 14px; font-style: normal; font-variant-ligatures: common-ligatures; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">
1、在SpringMVC后臺(tái)控制層獲取參數(shù)的方式主要有兩種,
一種是request.getParameter(“name”),另外一種是用注解@RequestParam直接獲取。
這里主要講這個(gè)注解 @RequestParam
接下來我們看一下@RequestParam注解主要有哪些參數(shù):
value:參數(shù)名字,即入?yún)⒌恼?qǐng)求參數(shù)名字,如username表示請(qǐng)求的參數(shù)區(qū)中的名字為username的參數(shù)的值將傳入;
required:是否必須,默認(rèn)是true,表示請(qǐng)求中一定要有相應(yīng)的參數(shù),否則將報(bào)404錯(cuò)誤碼;
defaultValue:默認(rèn)值,表示如果請(qǐng)求中沒有同名參數(shù)時(shí)的默認(rèn)值,例如:
public List getItemTreeNode(@RequestParam(value=”id”,defaultValue=”0”)long parentId)
2、@PathVariable綁定URI模板變量值
@PathVariable用于將請(qǐng)求URL中的模板變量映射到功能處理方法的參數(shù)上。
//配置url和方法的一個(gè)關(guān)系
@RequestMapping(“item/{itemId}”)
/* @RequestMapping 來映射請(qǐng)求,也就是通過它來指定控制器可以處理哪些URL請(qǐng)求,類似于struts的.action請(qǐng)求-
- @responsebody表示該方法的返回結(jié)果直接寫入HTTP response body中
一般在異步獲取數(shù)據(jù)時(shí)使用,在使用@RequestMapping后,返回值通常解析為跳轉(zhuǎn)路徑,加上@responsebody后返回結(jié)果不會(huì)被解析為跳轉(zhuǎn)路徑,而是直接寫入HTTP response body中。
比如異步獲取json數(shù)據(jù),加上@responsebody后,會(huì)直接返回json數(shù)據(jù)。*
@Pathvariable注解綁定它傳過來的值到方法的參數(shù)上
用于將請(qǐng)求URL中的模板變量映射到功能處理方法的參數(shù)上,即取出uri模板中的變量作為參數(shù)
*/
@ResponseBody
public TbItem getItemById(@PathVariable Long itemId){
</article>



談?wù)?Spring IOC 的 @Primary、@Qualifier 注解用法和區(qū)別。
https://mp.weixin.qq.com/s?src=11×tamp=1597219007&ver=2517&signature=LZHkUeP54cxY0Z2O4z1iGeSZI8lM0JW4smMgr5GyxUyZu4MiB4vbU6oLI5DiqGLvQTQnC4eOx1StSjCWPL8OafhTCZC6d3YxkHboW45z04oNGm4pLQs*ekrEJu&new=1
解決org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)問題
https://blog.csdn.net/sundacheng1989/article/details/81630370?utm_medium=distribute.pc_relevant.none-task-blog-baidulandingword-1&spm=1001.2101.3001.4242