1,spring the location of the boot entry class (class with Main class)
The location of the Springboot entry class is placed in a package higher than the regular class, so that the project can be loaded into each Java configuration class under the package path when it is started.
1,spring boot Annotations
1, @RestController
@RestController is a stereotype annotation that combines @ResponseBody and @Controller.
This means: @RestController annotations are equivalent to the @responsebody + @Controller combined function.
2, @SpringBootApplication
Many spring Boot developers always use @Configuration , @EnableAutoConfiguration and @ComponentScan annotate their main class. Because these annotations are used so frequently (especially if you follow these best practices), Spring Boot provides a convenient @SpringBootApplication choice.
This @SpringBootApplication annotation is equivalent to using @Configuration , @EnableAutoConfiguration, and @ComponentScan with default properties .
@Configuration , @EnableAutoConfiguration and @ComponentScan [email protected]
the Entry class main() method for Springboot
3, @Configuration
Annotations are used in the Java configuration class to load during spring boot boot
4 , @Component:
We can use this annotation to annotate components when they are poorly categorized.
5, @Transactional annotations
The method used to implement transaction control on the service layer is only used by the external method bar to be captured by AOP, that is, methods within the class that call the other methods of this class do not cause transactional behavior, even if the called method is decorated with the @transactional annotation, @ The transactional should use the first method of invoking the service layer on the controller.
2, how to read configuration information from the APPLICATION.YML
For example, I configured a configuration message in the YML file message :
Massage: data: name:yy
I want to get in the class he needs to write this, directly into the name attribute:
@Value ("${message.data.name}") private String name;
BigDecimal:
1, the CompareTo method compares whether the data is equal, and does not see the difference between different decimal digits, such as 2 and 2.00 being equal.
The Equals method, in addition to comparing the values of the two, compares whether the decimal digits are equal, the above 2.equals (2.00), and returns false.
2, BigDecimal divided by one number, the result is reserved 2 decimal places
Sales.getrealprice (). Divide (New BigDecimal (Sales.getsaleamount ()), 2)
Number of double type, reserved two decimal places:
public static void Main (String args[]) { //reserved Two-bit valid number DecimalFormat df = new DecimalFormat ("# # #0.0#"); String format = Df.format (0.33333); SYSTEM.OUT.PRINTLN (format); Keep two valid digits, solve the form of double scientific notation String format1 = String.Format ("%.2f", 0.33333); System.out.println (FORMAT1);}
Beanutils.copyproperties():
Use the Copy object's properties, copy the first parameter value to the second parameter
cannot be used for copy of Java.utils.Date property
Spring boot annotations, bigdecimal comparison, beanutils.copyproperties () usage