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
import com.fasterxml.jackson.databind.ObjectMapper; | |
import com.fasterxml.jackson.databind.SerializationFeature; | |
... | |
import org.springframework.http.converter.HttpMessageConverter; | |
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; | |
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; | |
@Configuration |
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
@Configuration | |
@EnableWebMvc | |
public class MvcConfig implements WebMvcConfigurer { | |
... | |
@Override | |
public void extendMessageConverters(final List<HttpMessageConverter<?>> converters) { | |
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder | |
.json() |
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
@Configuration | |
@EnableWebMvc | |
public class MvcConfig implements WebMvcConfigurer { | |
... | |
@Override | |
public void extendMessageConverters(final List<HttpMessageConverter<?>> converters) { | |
DateTimeFormatter formatter = DataTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
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
import org.springframework.web.bind.annotation.RequestBody; | |
import org.springframework.web.bind.annotation.RestController; | |
@RestController | |
public class RestMemberController { | |
private MemberDao memberDao; | |
private MemberRegisterService registerService; | |
... |
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
@JsonFormat(pattern = "yyyyMMddHHmmss") | |
private LocalDateTime birthDateTime; | |
@JsonFormat(pattern = "yyyMMddHHmmss") | |
private Date birthDate; |
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
@Configuration | |
@EnableWebMvc | |
public class MvcConfig implements WebMvcConfigurer { | |
... | |
@Override | |
public void extendMessageConverters(final List<HttpMessageConverter<?>> converters) { | |
DateTimeFormatter formatter = DataTimeFormatter.ofPattern("yyyyMMddHHmmss"); |
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
@GetMapping("/api/members/{id}") | |
public Member member(@PathVariable Long id, HttpServletResponse response) throws IOException { | |
Member member = memberDao.selectById(id); | |
if (member == null) { | |
response.sendError(HttpServletResponse.SC_NOT_FOUND); | |
return null; | |
} | |
return member; | |
} |
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
import org.springframework.http.HttpStatus; | |
import org.springframework.http.ResponseEntity; | |
@RestController | |
public class RestMemberController { | |
private MemberDao memberDao; | |
private MemberRegisterService registerService; | |
... |
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 controller; | |
public class ErrorResponse { | |
private String message; | |
public ErrorResponse(String message) { | |
this.message = message; | |
} |
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
@GetMapping("/api/members/{id}") | |
public ResponseEntity<Object> member(@PathVariable Long id, HttpServletResponse response) throws IOException { | |
Member member = memberDao.selectById(id); | |
if (member == null) { | |
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(new ErrorResponse("no member")); | |
} | |
return ResponseEntity.status(HttpStatus.OK).body(member); | |
} |
OlderNewer