私のSpringコントローラーでは、サービスからアイテムのリストを受け取り、コントローラー内でカスタムコードを使用して、サービスから返されたリストのサブセットである新しいフィルタリングされたリストを作成しています。
このフィルタリング コードをコントローラーで実行する必要はないと思いますか?
これが私のコントローラーです:
@Controller
public class MyController {
@Autowired
private MyService myService;
@RenderMapping
public String getValues(ModelMap modelMap){
List<String> = myService.getNewValues();
List<String> filteredList = ......
/**
Code here to process the List and convert it to
specific List
*/
modelMap.addAttribute("values", filteredList);
}
}
フィルタリングはサービス実装層で行うべきですか?
myService.getNewValues();
したがって、結果をフィルタリングする新しいメソッドを使用する代わりに: myService.getNewFilteredValues();
?
注 : メソッドmyService.getNewFilteredValues()
は新しいメソッドになり、で指定されたフィルタリング コードと同じコードが含まれます。MyController