TECH |
Engadget Japanese |
64やメガドラが遊べるNintendo Switch Online追加パックは10月26日開始。どうぶつの森DLCも |
https://japanese.engadget.com/nintendo-switch-online-024739272.html
|
nintendoswitchonline |
2021-10-16 02:47:39 |
python |
Pythonタグが付けられた新着投稿 - Qiita |
再帰関数の処理される順番 |
https://qiita.com/iguchan_4649/items/82a422dc4d87c91e328a
|
ここでついに引数dataがになったので、がreturnされ無限ループすることはない、引数がのtotal関数の変数valueの値はになる。 |
2021-10-16 11:44:52 |
js |
JavaScriptタグが付けられた新着投稿 - Qiita |
TypeScriptでuseRefを使う |
https://qiita.com/shunnami/items/04c2ed9d4434d78c9a3c
|
|
2021-10-16 11:07:15 |
Program |
[全てのタグ]の新着質問一覧|teratail(テラテイル) |
APIに乱数を用いることによるセキュリティー上のメリットについて |
https://teratail.com/questions/364664?rss=all
|
APIに乱数を用いることによるセキュリティー上のメリットについてこちら記事を読んでいた際に疑問な箇所があり質問させて頂ました。 |
2021-10-16 11:50:16 |
Program |
[全てのタグ]の新着質問一覧|teratail(テラテイル) |
Python3で拡張機能を有効化 |
https://teratail.com/questions/364663?rss=all
|
Pythonで拡張機能を有効化Pythonで拡張機能を有効化してその機能を自動的に使うプログラムを書いています。 |
2021-10-16 11:49:45 |
Program |
[全てのタグ]の新着質問一覧|teratail(テラテイル) |
ラジオボタンによる機能切替が上手くいきません |
https://teratail.com/questions/364662?rss=all
|
ラジオボタンによる機能切替が上手くいきませんquot機能ボタンの設定quotというコメント周辺にラジオボタンを実装しています。 |
2021-10-16 11:48:09 |
Program |
[全てのタグ]の新着質問一覧|teratail(テラテイル) |
Vagrant up するとStdoutだとかStderrとかいうエラーが出る |
https://teratail.com/questions/364661?rss=all
|
|
2021-10-16 11:39:55 |
Program |
[全てのタグ]の新着質問一覧|teratail(テラテイル) |
デスクトップアプリ SQLServer でデータを取得できません |
https://teratail.com/questions/364660?rss=all
|
自分の環境ではexeファイルは問題なくデータを取得できるのですが、友人のPCではデータ取得処理のところでエラーが出てしまうようです。 |
2021-10-16 11:27:04 |
Program |
[全てのタグ]の新着質問一覧|teratail(テラテイル) |
pythonでtfrecordsデータのレコードを選んでtfrecordsデータを再構成したい |
https://teratail.com/questions/364659?rss=all
|
pythonでtfrecordsデータのレコードを選んでtfrecordsデータを再構成したい前提・実現したいことtfrecordsデータから特定のレコードのみを選び、それらからなる新しいtfrecordsデータを作成したいと考えています。 |
2021-10-16 11:26:50 |
Program |
[全てのタグ]の新着質問一覧|teratail(テラテイル) |
突然、サイト表示に不具合発生。phpやcssが効いておらず、白背景に文字や画像が羅列される表示になってしまいました。 |
https://teratail.com/questions/364658?rss=all
|
昨日、突然、サイト表示がおかしくなり、phpやcssが効いておらず、白背景に文字や画像が羅列される表示になっております。 |
2021-10-16 11:08:06 |
Program |
[全てのタグ]の新着質問一覧|teratail(テラテイル) |
ゲームのマテリアルアイコンの変え方について知りたい |
https://teratail.com/questions/364657?rss=all
|
|
2021-10-16 11:06:15 |
Git |
Gitタグが付けられた新着投稿 - Qiita |
git diff コメント行無視で変更行数を数える |
https://qiita.com/na_210/items/9c71cc7bfe750a8c6b57
|
gitdiffコメント行無視で変更行数を数える自分用メモ。 |
2021-10-16 11:01:44 |
海外TECH |
DEV Community |
Spring Boot Exception Handling example |
https://dev.to/tienbku/spring-boot-exception-handling-example-241c
|
Spring Boot Exception Handling exampleIn this tutorial we re gonna look at an Spring Boot Exception Handling example that uses ControllerAdvice and ExceptionHandler You can also handle Restful API exception with RestControllerAdvice kindly visit RestControllerAdvice example in Spring BootThis article is originally posted at Bezkoder Rest API exception handlingWe ve created Rest Controller for CRUD Operations and finder method Let look at the code step by step to build the Rest APIs is in Spring Boot Data JPA H CRUD exampleSpring Boot Data JPA MySQL CRUD exampleSpring Boot Data JPA PostgreSQL CRUD exampleSpring Boot Data JPA SQL ServerSpring Boot Data JPA Oracle exampleSpring Boot MongoDB CRUD exampleSpring Boot Cassandra CRUD example RestControllerpublic class TutorialController Autowired TutorialRepository tutorialRepository GetMapping tutorials public ResponseEntity amp lt List amp lt Tutorial gt gt getAllTutorials RequestParam required false String title try return new ResponseEntity amp lt gt tutorials HttpStatus OK catch Exception e return new ResponseEntity amp lt gt null HttpStatus INTERNAL SERVER ERROR GetMapping tutorials id public ResponseEntity amp lt Tutorial gt getTutorialById PathVariable id long id Optional amp lt Tutorial gt tutorialData tutorialRepository findById id if tutorialData isPresent return new ResponseEntity amp lt gt tutorialData get HttpStatus OK else return new ResponseEntity amp lt gt HttpStatus NOT FOUND PutMapping tutorials id public ResponseEntity amp lt Tutorial gt updateTutorial PathVariable id long id RequestBody Tutorial tutorial Optional amp lt Tutorial gt tutorialData tutorialRepository findById id if tutorialData isPresent return new ResponseEntity amp lt gt tutorialRepository save tutorial HttpStatus OK else return new ResponseEntity amp lt gt HttpStatus NOT FOUND DeleteMapping tutorials id public ResponseEntity amp lt HttpStatus gt deleteTutorial PathVariable id long id try tutorialRepository deleteById id return new ResponseEntity amp lt gt HttpStatus NO CONTENT catch Exception e return new ResponseEntity amp lt gt HttpStatus INTERNAL SERVER ERROR DeleteMapping tutorials public ResponseEntity amp lt HttpStatus gt deleteAllTutorials try and catch GetMapping tutorials published public ResponseEntity amp lt List amp lt Tutorial gt gt findByPublished try and catch You can see that we use try catch many times for similar exception INTERNAL SERVER ERROR and there are also many cases that return NOT FOUND Is there any way to keep them simple any way to attach the error response message smartly and flexibility Let s solve the problem now Exception Handling with Controller Advice in SpringSpring supports exception handling by a global Exception Handler ExceptionHandler with Controller Advice ControllerAdvice This enables a mechanism that makes ResponseEntity work with the type safety and flexibility of ExceptionHandler ControllerAdvicepublic class ControllerExceptionHandler ExceptionHandler value ResourceNotFoundException class CertainException class public ResponseEntity amp lt ErrorMessage gt resourceNotFoundException ResourceNotFoundException ex WebRequest request ErrorMessage message new ErrorMessage status date ex getMessage description return new ResponseEntity amp lt ErrorMessage gt message HttpStatus NOT FOUND The ControllerAdvice annotation is specialization of Component annotation so that it is auto detected via classpath scanning A Controller Advice is a kind of interceptor that surrounds the logic in our Controllers and allows us to apply some common logic to them Its methods annotated with ExceptionHandler are shared globally across multiple Controller components to capture exceptions and translate them to HTTP responses The ExceptionHandler annotation indicates which type of Exception we want to handle The exception instance and the request will be injected via method arguments By using two annotations together we can control the body of the response along with status code handle several exceptions in the same method ResponseStatusIn the example above we use ControllerAdvice for REST web services and return ResponseEntity object additionally Spring also provides ResponseBody annotation which tells a controller that the object returned is automatically serialized into JSON and passed it to the HttpResponse object This way does not require ResponseEntity but you need to use ResponseStatus to set the HTTP status code for that exception ControllerAdvice ResponseBodypublic class ControllerExceptionHandler ExceptionHandler ResourceNotFoundException class ResponseStatus value HttpStatus NOT FOUND public ErrorMessage resourceNotFoundException ResourceNotFoundException ex WebRequest request ErrorMessage message new ErrorMessage return message Setup Spring Boot ProjectYou can follow step by step or get source code in one of following posts Spring Boot Data JPA H CRUD exampleSpring Boot Data JPA MySQL CRUD exampleSpring Boot Data JPA PostgreSQL CRUD exampleSpring Boot Data JPA SQL ServerSpring Boot Data JPA Oracle exampleSpring Boot MongoDB CRUD exampleSpring Boot Cassandra CRUD exampleThe Spring Project contains structure that we only need to add some changes to make the pagination work well Or you can get the new Github source code at the end of this tutorial The final project structure will be like this Define Error Response MessageWe want to create a our own message response structure instead of using default error response provided by Spring Boot Let s define a specific error response structure exception ErrorMessage javapackage com bezkoder spring exhandling exception import java util Date public class ErrorMessage private int statusCode private Date timestamp private String message private String description public ErrorMessage int statusCode Date timestamp String message String description this statusCode statusCode this timestamp timestamp this message message this description description public int getStatusCode return statusCode public Date getTimestamp return timestamp public String getMessage return message public String getDescription return description Create Custom ExceptionWe re gonna throw an exception for Resource not found in Spring Boot controller Lets create a ResourceNotFoundException class that extends RuntimeException exception ResourceNotFoundException javapackage com bezkoder spring exhandling exception public class ResourceNotFoundException extends RuntimeException private static final long serialVersionUID L public ResourceNotFoundException String msg super msg Create Controller Advice with ExceptionHandlerNow we re gonna create a special class which is annotated by ControllerAdvice annotation This class handles specific exception ResoureNotFoundException and global Exception in only one place exception ControllerExceptionHandler javapackage com bezkoder spring exhandling exception import java util Date import org springframework http HttpStatus import org springframework http ResponseEntity import org springframework web bind annotation ControllerAdvice import org springframework web bind annotation ExceptionHandler import org springframework web context request WebRequest import com bezkoder spring exhandling exception ErrorMessage import com bezkoder spring exhandling exception ResourceNotFoundException ControllerAdvicepublic class ControllerExceptionHandler ExceptionHandler ResourceNotFoundException class public ResponseEntity amp lt ErrorMessage gt resourceNotFoundException ResourceNotFoundException ex WebRequest request ErrorMessage message new ErrorMessage HttpStatus NOT FOUND value new Date ex getMessage request getDescription false return new ResponseEntity amp lt ErrorMessage gt message HttpStatus NOT FOUND ExceptionHandler Exception class public ResponseEntity amp lt ErrorMessage gt globalExceptionHandler Exception ex WebRequest request ErrorMessage message new ErrorMessage HttpStatus INTERNAL SERVER ERROR value new Date ex getMessage request getDescription false return new ResponseEntity amp lt ErrorMessage gt message HttpStatus INTERNAL SERVER ERROR Modify Controller for using ControllerAdviceOur Rest Controller now doesn t have try catch block and it will throw ResourceNotFoundException where we want to send NOT FOUND notification in response message controller TutorialController javapackage com bezkoder spring exhandling controller import java util ArrayList import java util List import org springframework beans factory annotation Autowired import org springframework http HttpStatus import org springframework http ResponseEntity import org springframework web bind annotation CrossOrigin import org springframework web bind annotation DeleteMapping import org springframework web bind annotation GetMapping import org springframework web bind annotation PathVariable import org springframework web bind annotation PostMapping import org springframework web bind annotation PutMapping import org springframework web bind annotation RequestBody import org springframework web bind annotation RequestMapping import org springframework web bind annotation RequestParam import org springframework web bind annotation RestController import com bezkoder spring exhandling exception ResourceNotFoundException import com bezkoder spring exhandling model Tutorial import com bezkoder spring exhandling repository TutorialRepository CrossOrigin origins http localhost RestController RequestMapping api public class TutorialController Autowired TutorialRepository tutorialRepository GetMapping tutorials public ResponseEntity amp lt List amp lt Tutorial gt gt getAllTutorials RequestParam required false String title List amp lt Tutorial gt tutorials new ArrayList amp lt Tutorial gt if title null tutorialRepository findAll forEach tutorials add else tutorialRepository findByTitleContaining title forEach tutorials add if tutorials isEmpty return new ResponseEntity amp lt gt HttpStatus NO CONTENT return new ResponseEntity amp lt gt tutorials HttpStatus OK GetMapping tutorials id public ResponseEntity amp lt Tutorial gt getTutorialById PathVariable id long id Tutorial tutorial tutorialRepository findById id orElseThrow gt new ResourceNotFoundException Not found Tutorial with id id return new ResponseEntity amp lt gt tutorial HttpStatus OK PostMapping tutorials public ResponseEntity amp lt Tutorial gt createTutorial RequestBody Tutorial tutorial Tutorial tutorial tutorialRepository save new Tutorial tutorial getTitle tutorial getDescription false return new ResponseEntity amp lt gt tutorial HttpStatus CREATED PutMapping tutorials id public ResponseEntity amp lt Tutorial gt updateTutorial PathVariable id long id RequestBody Tutorial tutorial Tutorial tutorial tutorialRepository findById id orElseThrow gt new ResourceNotFoundException Not found Tutorial with id id tutorial setTitle tutorial getTitle tutorial setDescription tutorial getDescription tutorial setPublished tutorial isPublished return new ResponseEntity amp lt gt tutorialRepository save tutorial HttpStatus OK DeleteMapping tutorials id public ResponseEntity amp lt HttpStatus gt deleteTutorial PathVariable id long id tutorialRepository deleteById id return new ResponseEntity amp lt gt HttpStatus NO CONTENT DeleteMapping tutorials public ResponseEntity amp lt HttpStatus gt deleteAllTutorials tutorialRepository deleteAll return new ResponseEntity amp lt gt HttpStatus NO CONTENT GetMapping tutorials published public ResponseEntity amp lt List amp lt Tutorial gt gt findByPublished List amp lt Tutorial gt tutorials tutorialRepository findByPublished true if tutorials isEmpty return new ResponseEntity amp lt gt HttpStatus NO CONTENT return new ResponseEntity amp lt gt tutorials HttpStatus OK Run and TestWe finish implementing CRUD REST APIs and exception handling for it Run Spring Boot application with command mvn spring boot run Get a non existent tutorial Update a non existent tutorial Create tutorial with wrong fields Delete a non existent tutorial ConclusionToday we ve built a Exception Handling class for Spring Boot Rest APIs using ControllerAdvice and ExceptionHandler Now you can create your own custom exception handler class or handle global exception in single place at ease If you want to add Pagination to this Spring project you can find the instruction at Spring Boot Pagination amp Filter example Spring JPA PageableTo sort order by multiple fields Spring Data JPA Sort Order by multiple Columns Spring BootOr way to write Unit Test for the JPA Repository Spring Boot Unit Test for JPA Repositiory with DataJpaTestYou can also know how to deploy this Spring Boot App on AWS for free with this tutorial Or Dockerize with Docker Compose Spring Boot and MySQL exampleHappy learning See you again Further ReadingRelated Posts Spring Boot Spring Data JPA Rest CRUD API exampleSpring Boot Pagination amp Filter exampleSpring Boot Sort Order by multiple ColumnsMore Practice Spring Boot Multipart File upload exampleSpring Boot Token based Authentication with Spring Security amp JWTSource CodeYou can find the complete source code for this tutorial on Github |
2021-10-16 02:05:12 |
海外ニュース |
Japan Times latest articles |
Suspect in deadly stabbing of Hyogo woman still on the run |
https://www.japantimes.co.jp/news/2021/10/16/national/crime-legal/amagasaki-woman-stabbing/
|
Suspect in deadly stabbing of Hyogo woman still on the runPolice were searching for a suspect believed to be in his s or s over the murder of Sayaka Morimoto a year old medical clerk living |
2021-10-16 11:43:11 |
LifeHuck |
ライフハッカー[日本版] |
無駄遣い・衝動買いをやめる3つの質問 |
https://www.lifehacker.jp/2021/10/before-you-buy-something-new-shop-your-own-stuff.html
|
無駄遣い |
2021-10-16 12:00:00 |
LifeHuck |
ライフハッカー[日本版] |
【Amazonタイムセール祭り】オークリーのサングラスが50%オフ、1本あたり62円の強炭酸水など目玉商品をお見逃しなく |
https://www.lifehacker.jp/2021/10/amazon-timesale-fes-2021-1016-1.html
|
amazon |
2021-10-16 11:15:00 |
北海道 |
北海道新聞 |
「交際断られた」と少年、甲府 事件後は「人いない所へ」 |
https://www.hokkaido-np.co.jp/article/600645/
|
甲府事件 |
2021-10-16 11:00:56 |
コメント
コメントを投稿