質問するログイン新規登録

質問編集履歴

3

インデント修正

2018/09/24 15:14

投稿

tt2
tt2

スコア14

title CHANGED
File without changes
body CHANGED
@@ -44,7 +44,7 @@
44
44
  public String home() {
45
45
  Foo foo = new Foo();
46
46
  foo.setName("テスト01");
47
-     request.getSession().setAttribute("foo" , foo);
47
+ request.getSession().setAttribute("foo" , foo);
48
48
  return "menu";
49
49
  }
50
50
  }

2

前回の修正時に転記漏れがあったため修正

2018/09/24 15:14

投稿

tt2
tt2

スコア14

title CHANGED
File without changes
body CHANGED
@@ -44,6 +44,7 @@
44
44
  public String home() {
45
45
  Foo foo = new Foo();
46
46
  foo.setName("テスト01");
47
+     request.getSession().setAttribute("foo" , foo);
47
48
  return "menu";
48
49
  }
49
50
  }

1

コードの書き方を修正

2018/09/24 15:11

投稿

tt2
tt2

スコア14

title CHANGED
File without changes
body CHANGED
@@ -37,7 +37,26 @@
37
37
  spring.session.jdbc.initialize-schema=always
38
38
 
39
39
  ◆実行プログラム
40
+ ```Java
40
- Controller内で以下の処理を記述
41
+ @Controller
42
+ public class WelcomeController {
43
+ RequestMapping("/")
44
+ public String home() {
41
- Foo foo = new Foo();
45
+ Foo foo = new Foo();
42
- foo.setName("テスト01");
46
+ foo.setName("テスト01");
47
+ return "menu";
48
+ }
49
+ }
50
+
51
+ @Component
43
- request.getSession().setAttribute("foo" , foo);
52
+ @Scope(value="session", proxyMode=ScopedProxyMode.TARGET_CLASS)
53
+ public class Foo {
54
+ private String name;
55
+ public String getName() {
56
+ return name;
57
+ }
58
+ public void setName(String name) {
59
+ this.name = name;
60
+ }
61
+ }
62
+ ```