1、@controller 控制器(注入服務)
用於標註控制層,相當於struts中的action層
2、@service 服務(注入service )
用於標註服務層,主要用來進行業務的邏輯處理
3、@repository(實現dao訪問)
用於標註數據訪問層,也可以說用於標註數據訪問組件,即DAO組件.
4、@component (把普通pojo實例化到spring容器中,相當於配置文件中的
<bean id="" class=""/>)
泛指各種組件,就是說當我們的類不屬於各種歸類的時候(不屬於@Controller、@Services等的時候),我們就可以使用@Component來標註這個類。
案例:
<context:component-scan base-package=”com.*”> 其中base-package爲需要掃描的包(含所有子包)
上面的這個例子是引入Component組件的例子,其中base-package表示爲需要掃描的所有子包。
共同點:被@controller 、@service、@repository 、@component 註解的類,都會把這些類納入進spring容器中進行管理
5、@RestController
相當於@Controller 和ResponseBody
6、@Autowired
注入
7、@GetMapping(vlue="")
相當於RequestMapping(Method = {RequestMethod.GET}) get請求 用於查詢、添加
8、@PostMapping(vlue="")
相當於RequestMapping(Method = {RequestMethod.POST}) post請求 用於添加、數據比較敏感
9、@PutMappring(vlue="")
相當於RequestMapping(Method = {RequestMethod.PUT}) 更新
10、@DeleteMapping(vlue="")
相當於RequestMapping(Method = {RequestMethod.DELETE}) 刪除
11、@PathVariable("id") Integer id
從路徑中獲取id值
12、@RequestParam(value="id", required="false", default="0") Integer myId
註解將請求參數綁定至方法參數
required:是否必需,默認爲 true,即 請求中必須包含該參數,如果沒有包含,將會拋出異常(可選配置)
defaultValue:默認值,如果設置了該值,required 將自動設爲 false,無論你是否配置了required,配置了什麼值,都是 false(可選配置)
13、entity類
@Entity
@Id
@GenerateValue
@NorBlank(message = "這個字段必傳")
@Min(value="18", message = "未成年人禁止入內") 作用於Inreger字段 小於18 提示後面的message
@NotNull(message="金額必傳")
14、啓動項
@SpringBootApplication
15、test相關
@Runwith 作用類上
@SpringBootTest 作用類上
@Test 作用在方法上