springboot入口類存放的位置,放到比常規類高一級的包內,這樣項目啓動時才能加載到包路徑下的各個java配置類。java
1, @RestControllerspring
@RestController is a stereotype annotation that combines @ResponseBody and @Controller.springboot
意思是:@RestController註解至關於@ResponseBody + @Controller合在一塊兒的做用。app
2, @SpringBootApplicationide
不少Spring Boot開發者老是使用 @Configuration , @EnableAutoConfiguration 和 @ComponentScan 註解他們的main類。因爲這些註解被如此頻繁地一塊使用(特別是你遵循以上最佳實踐時),Spring Boot提供一個方便的 @SpringBootApplication 選擇。spa
該 @SpringBootApplication 註解等價於以默認屬性使用 @Configuration , @EnableAutoConfiguration 和 @ComponentScan 。code
@Configuration , @EnableAutoConfiguration 和 @ComponentScan ==@SpringBootApplicationorm
用於springboot的入口類main()方法對象
3, @Configurationblog
註解用於java配置類,在spring boot啓動過程當中進行加載
4, @Component:
泛指組件,當組件很差歸類的時候,咱們可使用這個註解進行標註。
5,@Transactional註解
用在service層上須要實現事務控制的方法上面,只用外部的方法條用纔會被AOP捕獲,也就是類內部的方法調用本類的其餘方法並不會引發事務行爲,即便被調用方法使用@Transactional註解所修飾,@Transactional應該用在controller調用service層的第一個方法。
好比我在yml文件中配置了一個配置信息message:
massage: data: name: yy
我在類中想要獲取他 須要這樣去寫,直接注入到name屬性中:
@Value("${message.data.name}") private String name;
BigDecimal :
1, compareTo方法比較的是數據是否相等,不看區別不一樣的小數位,例如2與2.00是相等的。
Equals方法除了比較二者的數值是否相等,還比較小數位是否相等,以上2.equals(2.00),返回是false。
2, BigDecimal除以一個數,結果保留2位小數
sales.getRealPrice().divide(new BigDecimal(sales.getSaleAmount()), 2)
double類型的數,保留兩位小數:
public static void main(String args[]){ //保留兩位有效數字 DecimalFormat df = new DecimalFormat("###0.0#"); String format = df.format(0.33333); System.out.println(format); // 保留兩位有效數字,解決double科學計數法的形式 String format1 = String.format("%.2f", 0.33333); System.out.println(format1); }
BeanUtils.copyProperties() :
用法拷貝對象的屬性,拷貝第一參數值給第二個參數
不能用於java.utils.Date屬性的拷貝