-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
148 additions
and
13 deletions.
There are no files selected for viewing
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
31 changes: 31 additions & 0 deletions
31
src/main/java/com/example/demo/controller/FriendController.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.example.demo.controller; | ||
|
||
import com.example.demo.entity.Friend; | ||
import com.example.demo.service.FriendService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.ui.Model; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.List; | ||
|
||
|
||
@Controller | ||
@RequestMapping(path = "/friendlist") | ||
public class FriendController { | ||
|
||
@Autowired | ||
FriendService service; | ||
|
||
@RequestMapping(value="/{userid}",method=RequestMethod.GET) | ||
public String selectAll(@PathVariable("userid") String userid, Model model) { | ||
int userId = Integer.parseInt(userid); | ||
List<Friend> friends = service.selectAll(userId); | ||
model.addAttribute("friends", friends); | ||
return "friendlist.html"; | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.example.demo.dao; | ||
|
||
import com.example.demo.entity.Emolog; | ||
import com.example.demo.entity.Friend; | ||
import org.seasar.doma.Dao; | ||
import org.seasar.doma.Select; | ||
import org.seasar.doma.boot.ConfigAutowireable; | ||
|
||
import java.util.List; | ||
|
||
@Dao | ||
@ConfigAutowireable | ||
public interface FriendDao { | ||
|
||
@Select | ||
List<Friend> selectAll(int userid); | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.example.demo.entity; | ||
|
||
|
||
|
||
import lombok.Data; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.seasar.doma.Entity; | ||
import org.seasar.doma.GeneratedValue; | ||
import org.seasar.doma.GenerationType; | ||
import org.seasar.doma.Id; | ||
|
||
import javax.validation.constraints.Max; | ||
import javax.validation.constraints.NotNull; | ||
import javax.validation.constraints.Size; | ||
import java.io.Serializable; | ||
import java.time.LocalDateTime; | ||
|
||
|
||
@Entity | ||
@Data | ||
@Getter | ||
@Setter | ||
public class Friend implements Serializable { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Integer id; | ||
|
||
@NotNull | ||
@Size(max=30) | ||
private Integer userid; | ||
|
||
@NotNull | ||
@Size(max=30) | ||
private String name; | ||
|
||
@Max(30) | ||
private String latestemolog; | ||
|
||
private LocalDateTime updated_at; | ||
|
||
|
||
|
||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/example/demo/repository/FriendRepository.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.example.demo.repository; | ||
|
||
import com.example.demo.dao.FriendDao; | ||
import com.example.demo.entity.Friend; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.List; | ||
|
||
@Repository | ||
public class FriendRepository { | ||
|
||
@Autowired | ||
FriendDao dao; | ||
|
||
public List<Friend> selectAll(int user) { // (4) | ||
return dao.selectAll(user); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.example.demo.service; | ||
|
||
import com.example.demo.entity.Friend; | ||
import com.example.demo.repository.FriendRepository; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
|
||
@Service | ||
public class FriendService { | ||
|
||
@Autowired | ||
FriendRepository repository; | ||
|
||
public List<Friend> selectAll(int user){ | ||
return repository.selectAll(user); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/resources/META-INF/com/example/demo/dao/FriendDao/selectAll.sql
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
select * | ||
from friend | ||
where userid = /* userid */1 | ||
order by updated_at |