Skip to content

Instantly share code, notes, and snippets.

@A-pZ
Created May 26, 2015 07:08
Show Gist options
  • Save A-pZ/2712ab4978ea9c7b6d54 to your computer and use it in GitHub Desktop.
Save A-pZ/2712ab4978ea9c7b6d54 to your computer and use it in GitHub Desktop.
Struts2+Java8 Stream APIの利用例
@Namespace("/")
@ParentPackage("lumi-default")
@Results({
// location属性に指定したhtmlファイル名は、/WEB-INF/content 以下からの相対パス。
@Result(name = ActionSupport.SUCCESS, location = "index" , type="thymeleaf-spring"),
})
@Controller
@Scope("prototype")
@Log4j2
public class SampleAction extends LumiActionSupport {
/**
* デフォルトアクション。
*/
@Action("")
public String start() throws Exception {
// Serviceクラスの呼び出し
List<Map<String, Object>> receiveList = service.execute("param");
log.debug("result:" + receiveList.toString());
this.resultList = new ArrayList<Map<String,Object>>();
ProductFilter prodfilter = new ProductFilter();
receiveList.stream().filter(prodfilter).forEach(
s -> resultList.add(s)
);
// Result値。ActionSupportの定数値を返すか、別途定義した値を返すこと。
// この値は@Resultで指定したname値となる。
return SUCCESS;
}
/**
* Actionクラスから実行する業務ロジックのServiceクラス。Autowiredがついたフィールドが自動的に対象となる。
*/
@Blocked
@Autowired
@Getter @Setter
private SampleService service;
@Getter @Setter
private List<Map<String,Object>> resultList;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment