springboot搭建教程

 之前一直在搜索教程搭ssh环境,结果一大堆配置文件搞的我很烦。特别是集成hibernate的时候。。遂室友荐springboot搭建之,结果不到10分钟就搭完了,分享一下心得。


目录结构

springboot搭建教程_第1张图片

package com.angry.controller;

/**
 * Created by Angry on 2017/9/26.
 */
import com.angry.domain.User;
import com.angry.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;

@RestController
public class helloController {

    @Autowired
    UserRepository userRepository;


    @RequestMapping("/")
    public String index() {
        System.out.println(userRepository.getClass());
        return "succeed";
    }

    @RequestMapping("/save")
    public boolean testsave() {
        User user =new  User();
        //user.setId(3);
        user.setName("test");
        user.setPassword("123");
        user.setDefaultAddress("111");
        user.setRole(2);
        userRepository.save(user);
        return true;
    }
}
controller

package com.angry.domain;

import java.sql.Timestamp;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
/**
 * Created by Angry on 2017/9/27.
 */
@Entity
@Table(name = "user")
public class User {
    @Id
    @GeneratedValue
    private int id;

    private String name;
    private String password;
    private String defaultAddress;
    private String defaultPhone;
    private String mail;
    private Integer money;
    private Timestamp regTime;
    private int role;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getDefaultAddress() {
        return defaultAddress;
    }

    public void setDefaultAddress(String defaultAddress) {
        this.defaultAddress = defaultAddress;
    }

    public String getDefaultPhone() {
        return defaultPhone;
    }

    public void setDefaultPhone(String defaultPhone) {
        this.defaultPhone = defaultPhone;
    }

    public String getMail() {
        return mail;
    }

    public void setMail(String mail) {
        this.mail = mail;
    }

    public Integer getMoney() {
        return money;
    }

    public void setMoney(Integer money) {
        this.money = money;
    }

    public Timestamp getRegTime() {
        return regTime;
    }

    public void setRegTime(Timestamp regTime) {
        this.regTime = regTime;
    }

    public int getRole() {
        return role;
    }

    public void setRole(int role) {
        this.role = role;
    }
}
实体类





你可能感兴趣的:(毕业设计)