springboot的入门请参考:https://blog.csdn.net/hanjun0612/article/details/81538449

这里就简单看下搭建:

一,看一下项目结构:

创建一个 Maven项目

App.class的代码如下:

package com.App;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}

二,创建application.properties

#修改tomcat默认端口号
server.port=8090 #修改context path
server.context-path=/test #配置数据源信息
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/testdb
spring.datasource.username=root
spring.datasource.password=root #配置jpa
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jackson.serialization.indent_output=true

三,model

package com.App.model;

import javax.persistence.*;

@Entity
@Table(name="user")
public class User { @Id @GeneratedValue(strategy= GenerationType.AUTO)
private Integer id;
private String userName;
private String password;
private Integer age; public Integer getId() {
return id;
} public void setId(Integer id) {
this.id = id;
} public String getUserName() {
return userName;
} public void setUserName(String userName) {
this.userName = userName;
} public String getPassword() {
return password;
} public void setPassword(String password) {
this.password = password;
} public Integer getAge() {
return age;
} public void setAge(Integer age) {
this.age = age;
}
}

四,dao

package com.App.dao;

import com.App.model.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param; public interface UserDao extends JpaRepository<User, Integer> {
@Query("from User where id =:id ")
User getUser(@Param("id") Integer id);
}

五,

①  service

service文件夹下,还有一个imp文件夹,用来实现

package com.App.service;

import com.App.model.User;

/**
* Created by Tyler on 2018/8/9
*/
public interface UserService {
void save(User user); User getabc(Integer id);
}

② Impl

package com.App.service.Impl;

import com.App.dao.UserDao;
import com.App.model.User;
import com.App.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; @Service
public class UserServiceImpl implements UserService {
@Autowired
UserDao userDao; public void save(User user){
userDao.save(user);
} @Override
public User getabc(Integer id) { return userDao.getUser(id);
}
}

六 controller

package com.App.controller;

import com.App.model.User;
import com.App.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController; @RestController
@RequestMapping("hello")
public class HelloController { @Autowired
UserService userService; @RequestMapping(value = "say",method = RequestMethod.GET)
public String sayHello(User user) {
// user.setUserName("he");
// user.setPassword("he1");
// user.setAge(20);
// userService.save(user); User u=userService.getabc(1);
return "hello ,spring boot";
}
}

springboot 简单搭建的更多相关文章

  1. springboot 简单搭建(thymeleaf 视图显示)

    接口访问参考:https://blog.csdn.net/hanjun0612/article/details/81625395 PS:调用接口和跳转网页 主要区别是 1 调用接口是 @RestCon ...

  2. 简单的SpringBoot环境搭建

    开始搭建前请确认您的计算机中的Maven已正确配置 一:使用IDEA创建一个Maven项目,图中第一个指针请选择自己正在使用的JDK版本,指针二请打勾,选中指针三所指向的类型并点击Next 二:填写G ...

  3. 超详细,新手都能看懂 !使用SpringBoot+Dubbo 搭建一个简单的分布式服务

    来自:JavaGuide Github 地址:https://github.com/Snailclimb/springboot-integration-examples 目录: 使用 SpringBo ...

  4. 使用 SpringBoot+Dubbo 搭建一个简单分布式服务

    实战之前,先来看几个重要的概念 开始实战之前,我们先来简单的了解一下这样几个概念:Dubbo.RPC.分布式.由于本文的目的是带大家使用SpringBoot+Dubbo 搭建一个简单的分布式服务,所以 ...

  5. 零配置简单搭建SpringMVC 项目

    SpringMVC是比较常用的JavaWeb框架,非常轻便强悍,能简化Web开发,大大提高开发效率,在各种Web程序中广泛应用.本文采用Java Config的方式搭建SpringMVC项目,并对Sp ...

  6. springboot +mybatis 搭建完整项目

    springboot + mybatis搭建完整项目 1.springboot整合mybatis注解版 转:https://blog.csdn.net/u013187139/article/detai ...

  7. 使用Springboot快速搭建SSM框架

    Spring Boot设计目的是用来简化Spring应用的初始搭建以及开发过程.该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的配置. 一.环境准备 Idea 2017 或 201 ...

  8. idea+springboot+Mybatis搭建web项目

    使用idea+springboot+Mybatis搭建一个简单的web项目. 首先新建一个项目: 在这里选择Maven项目也可以,但是IDEA为我们提供了一种更方便快捷的创建方法,即Spring In ...

  9. springboot简单介绍

    1.springboot简单介绍 微服务架构 Spring Boot 是由 Pivotal 团队提供的全新框架,其设计目的是用来简化新 Spring 应用的初始搭建以及开发过程. 该框架使用了特定的方 ...

随机推荐

  1. 【C#复习总结】多线程编程

    1 基本概念 前一篇文章做了铺垫,详见:http://www.cnblogs.com/mhq-martin/p/9035640.html 2 多线程 多线程的优点:可以同时完成多个任务:可以使程序的响 ...

  2. python读取/创建XML文件

    Python中定义了很多处理XML的函数,如xml.dom,它会在处理文件之前,将根据xml文件构建的树状数据存在内存.还有xml.sax,它实现了SAX API,这个模块牺牲了便捷性,换取了速度和减 ...

  3. 百度软件开发实习生c++方向面经(一面)

    百度2017实习生软件开发(cpp方向) 首先说一下岗位.分为软件开发,开发测试,前端,机器学习数据挖掘,移动开发,据我观察,报的人数来看,软件开发最多,移动开发和开发测试较少.百度前台还准备了吃的喝 ...

  4. H5 31-CSS元素显示模式转换

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. super关键字访问父类成员

    1.super只能出现在子类的方法和构造方法中: 2.super调用构造方法时只能是第一句: 3.super不能访问父类的private成员.

  6. Codeforces Round #534 (Div. 2)D. Game with modulo-1104-D(交互+二分+构造)

    D. Game with modulo time limit per test 1 second memory limit per test 256 megabytes input standard ...

  7. CodeIgniter框架中尝试使用swoole

    ci框架版本:3.1.7.     swoole版本:1.7.      php版本:5.6 相关文档: 以cli方式运行ci框架 swoole官方手册 创建一个TestSwoole和Hello控制器 ...

  8. js判断一个对象{}是否为空对象,没有任何属性

    // js如何判断一个对象{}是否为空对象,没有任何属性 if (typeof model.rows === "object" && !(model.rows in ...

  9. 编写自己的composer项目

    编写自己的composer项目   composer的出现给php开发带来极大的便利, 配合phpunit的测试工具, 也可以更好的规范php开发. 尽管这些标准不是官方提供的, 但现在大部分的php ...

  10. C# Note34: 异常机制相关小点

    1.使用throw和throw ex抛出异常的区别 通常,我们使用try/catch/finally语句块来捕获异常,那么在抛出异常的时候,使用throw和throw ex有什么区别呢? 假如,按顺序 ...