• springBoot【01】


    /*
        使用spring官网的 http://start.spring.io/ 来建立项目包
        生成入口文件,入口文件中对类注释@SpringBootApplication,这个注释是唯一的,标明这个类是入口类
        可以直接启动该类,发现项目是通过内置的Tomcat启动的,端口号8080
        
        因为还没有配置数据库,所以先用注释标明先不启动DataSource
    
     */
    @SpringBootApplication
    @EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class})
    public class XcxloginApplication {
    
        public static void main(String[] args) {
            SpringApplication.run(XcxloginApplication.class, args);
        }
    }
    /**
     * 访问控制器需要用@RestController来声明,表示告诉Spring直接渲染返回string给调用者
     * 路由通过@RequestMapping来声明
     */
    
    @RestController
    public class HelloWorldController {
        @RequestMapping(value = "/index", method = RequestMethod.GET)
        public String index(){
            return "HelloWorld";
        }
    }
    实体类、JPA、控制类
    
    @Entity
    @Table(name = "t_user")
    public class UserEntity implements Serializable {
        @Id
        @GeneratedValue
        @Column(name = "t_id")
        private Long id;
    
        @Column(name = "t_name")
        private String name;
    
        @Column(name = "t_age")
        private int age;
    
        @Column(name = "t_address")
        private String address;
    
        public Long getId() {
            return id;
        }
    
        public void setId(Long id) {
            this.id = id;
        }
    
        public String getName() {
            return name;
        }
    
        public void setName(String name) {
            this.name = name;
        }
    
        public int getAge() {
            return age;
        }
    
        public void setAge(int age) {
            this.age = age;
        }
    
        public String getAddress() {
            return address;
        }
    
        public void setAddress(String address) {
            this.address = address;
        }
    
    
    }
    
    
    public interface UserJPA extends JpaRepository<UserEntity, Long>,
            JpaSpecificationExecutor<UserEntity>, Serializable {
    }
    
    
    @RestController
    @RequestMapping(value = "/user")
    public class UserController {
    
        @Autowired
        private UserJPA userJPA;
    
        /**
         * 查询用户列表
         */
        @RequestMapping(value = "/list", method = RequestMethod.GET)
        public List<UserEntity> list(){
            return userJPA.findAll();
        }
    
    }
  • 相关阅读:
    计算两个经纬度之间的距离,单位米
    PHP获取汉字首字母函数
    tp3.2 上传文件及下载文件
    最少知识原则
    单一职责原则
    接口和面向接口编程
    开放-封闭原则
    设计原则
    websrom编译器
    头条笔试题2018后端第二批-用户喜好
  • 原文地址:https://www.cnblogs.com/ohmydenzi/p/10089870.html
Copyright © 2020-2023  润新知