Created
August 19, 2016 04:06
-
-
Save verydapeng/14a423e87e313ae74d6b41ec0419a5b6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.verydapeng; | |
import com.fasterxml.jackson.annotation.JsonCreator; | |
import com.fasterxml.jackson.annotation.JsonProperty; | |
import org.springframework.boot.ApplicationRunner; | |
import org.springframework.boot.SpringApplication; | |
import org.springframework.boot.autoconfigure.SpringBootApplication; | |
import org.springframework.context.annotation.Bean; | |
import org.springframework.data.jpa.repository.JpaRepository; | |
import org.springframework.data.rest.core.annotation.RepositoryRestResource; | |
import org.springframework.web.bind.annotation.RequestBody; | |
import org.springframework.web.bind.annotation.RequestMapping; | |
import org.springframework.web.bind.annotation.RestController; | |
import javax.persistence.Entity; | |
import javax.persistence.GeneratedValue; | |
import javax.persistence.Id; | |
import javax.validation.Valid; | |
import javax.validation.constraints.Size; | |
import java.util.stream.Stream; | |
@SpringBootApplication | |
@RestController | |
public class BootApplication { | |
public static void main(String[] args) { | |
SpringApplication.run(BootApplication.class, args); | |
} | |
@RequestMapping("/") | |
String hello(@RequestBody @Valid User user) { | |
return "hello " + user; | |
} | |
} | |
@Entity | |
class User { | |
@Id | |
@GeneratedValue | |
private long id; | |
@Size(min = 6) | |
private String username; | |
@Size(min = 6) | |
private String password; | |
public User() { | |
} | |
@JsonCreator | |
public User(@JsonProperty("username") String username, | |
@JsonProperty("password") String password) { | |
this.username = username; | |
this.password = password; | |
} | |
public long getId() { | |
return id; | |
} | |
public String getUsername() { | |
return username; | |
} | |
public String getPassword() { | |
return password; | |
} | |
@Override | |
public String toString() { | |
return "User{" + | |
"id=" + id + | |
", username='" + username + '\'' + | |
'}'; | |
} | |
} | |
@RepositoryRestResource | |
interface UserRepo extends JpaRepository<User, Long> { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment