zoukankan      html  css  js  c++  java
  • Spring boot 梳理

    1. Spring boot 对代码结构无特殊要求,但有个套最佳实践的推荐
      1. 不要使用没有包名的类。没有包名时,@ComponentScan, @EntityScan, or @SpringBootApplication 可能会有问题。
      2. Main类在包路径中的位置:强烈建议main类放在包的根路径上。We generally recommend that you locate your main application class in a root package above other classes. The @SpringBootApplication annotation is often placed on your main class, and it implicitly defines a base “search package” for certain items. For example, if you are writing a JPA application, the package of the @SpringBootApplication annotated class is used to search for @Entity items. Using a root package also allows component scan to apply only on your project.
        1. com
           +- example
               +- myapplication
                   +- Application.java
                   |
                   +- customer
                   |   +- Customer.java
                   |   +- CustomerController.java
                   |   +- CustomerService.java
                   |   +- CustomerRepository.java
                   |
                   +- order
                       +- Order.java
                       +- OrderController.java
                       +- OrderService.java
                       +- OrderRepository.java
      3. The Application.java file would declare the main method, along with the basic @SpringBootApplication, as follows:
        1. package com.example.myapplication;
          
          import org.springframework.boot.SpringApplication;
          import org.springframework.boot.autoconfigure.SpringBootApplication;
          
          @SpringBootApplication
          public class Application {
          
              public static void main(String[] args) {
                  SpringApplication.run(Application.class, args);
              }
          
          }
      4. @RestController
        @EnableAutoConfiguration
        public class App 
        {
            @RequestMapping("/hello")
            public HashMap<String,String> hello(){
                HashMap<String,String> result=new HashMap<String,String>();
                result.put("name", "jt");
                return result;
                
            }
            public static void main( String[] args )
            {
                SpringApplication.run(App.class, args);
            }
        }
  • 相关阅读:
    常见hash算法的原理
    【学习干货】给coder的10个读书建议
    htc one x刷机记录
    Linux 搭建SVN server
    javascript
    USACO comehome Dijkstra
    当设计师、产品经理和程序员去交友站点找女朋友
    Spring3.0 AOP 具体解释
    慕课网Hibernate初探之一对多映射实验及总结
    C++数组引用
  • 原文地址:https://www.cnblogs.com/jiangtao1218/p/10159349.html
Copyright © 2011-2022 走看看