zoukankan      html  css  js  c++  java
  • 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();
        }
    
    }
  • 相关阅读:
    C#在与java对接时候的UrlEncode的坑
    sql server 删除大量数据的一次坑爹之旅
    js实现黑客帝国文字下落效果
    第一个SignalR案例
    简单的放天灯动画
    计量单位符号的书写规范【转】
    阿里云OSS搭建移动应用直传服务的.Net C#示例
    UWP Windows10开发更新磁贴和动态更新磁贴
    UWP Windows10开发获取设备位置(经纬度)
    Asp.Net识别手机访问
  • 原文地址:https://www.cnblogs.com/ohmydenzi/p/10089870.html
Copyright © 2011-2022 走看看