error URI templete ID
This commit is contained in:
parent
e238ee257a
commit
97c666e832
@ -2,6 +2,7 @@ package com.chantha.mini.controller
|
||||
|
||||
import com.chantha.mini.dto.UserDto
|
||||
import com.chantha.mini.service.UserService
|
||||
import com.fasterxml.jackson.annotation.JsonRootName
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.stereotype.Controller
|
||||
import org.springframework.web.bind.annotation.GetMapping
|
||||
@ -11,14 +12,20 @@ import org.springframework.web.bind.annotation.RestController
|
||||
@RestController
|
||||
class UserController @Autowired constructor(private val userService: UserService){
|
||||
|
||||
@GetMapping("/api/user/{firstName}/{lastName}")
|
||||
@GetMapping("/api/user/name/{firstName}/{lastName}")
|
||||
fun findByFirstNameAndLastName(@PathVariable firstName:String ?="",@PathVariable lastName:String?=""):UserDto{
|
||||
println(lastName+" "+firstName)
|
||||
return userService.findByFirstNameAndLastName(firstName,lastName)
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/api/user")
|
||||
fun findAllRecord():List<UserDto>{
|
||||
return userService.findAllRecord().orEmpty()
|
||||
}
|
||||
|
||||
@GetMapping("/api/user/id/{id}")
|
||||
fun findById(@PathVariable Id:Long ):UserDto{
|
||||
return userService.findById(Id)
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package com.chantha.mini.dto
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty
|
||||
import com.fasterxml.jackson.annotation.JsonRootName
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
|
||||
import org.intellij.lang.annotations.Identifier
|
||||
import java.util.*
|
||||
@ -10,6 +11,7 @@ import javax.persistence.*
|
||||
|
||||
@Entity
|
||||
@Table(name="tb_user")
|
||||
@JsonRootName("Person")
|
||||
data class UserDto
|
||||
(
|
||||
@Id
|
||||
|
@ -12,4 +12,6 @@ interface UserRepo : JpaRepository<UserDto,Long> {
|
||||
fun findByFirstnameAndLastname(firstName:String?="",lastName:String?=""):UserDto
|
||||
@Query("SELECT * FROM user_dto",nativeQuery = true)
|
||||
fun findAllRecord():List<UserDto>
|
||||
@Query("SELECT * FROM user_dto WHERE id=?1",nativeQuery = true)
|
||||
fun findById(Id :Long ?= 0):UserDto
|
||||
}
|
@ -2,8 +2,11 @@ package com.chantha.mini.service
|
||||
|
||||
import com.chantha.mini.dto.UserDto
|
||||
import com.chantha.mini.repo.UserRepo
|
||||
import com.fasterxml.jackson.annotation.JsonFilter
|
||||
import com.fasterxml.jackson.annotation.JsonRootName
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.stereotype.Service
|
||||
import java.util.*
|
||||
|
||||
@Service
|
||||
class UserService @Autowired constructor(private val userRepo: UserRepo) {
|
||||
@ -11,7 +14,12 @@ class UserService @Autowired constructor(private val userRepo: UserRepo) {
|
||||
fun findByFirstNameAndLastName(firstName: String? = "", lastName: String? = ""):UserDto {
|
||||
return userRepo.findByFirstnameAndLastname(firstName,lastName)
|
||||
}
|
||||
|
||||
fun findAllRecord():List<UserDto>{
|
||||
return userRepo.findAllRecord()
|
||||
}
|
||||
|
||||
fun findById(Id : Long? = 0): UserDto {
|
||||
return userRepo.findById(Id)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user