File tree Expand file tree Collapse file tree
TjuFood/src/main/java/xyz/tjucomments/tjufood Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package xyz .tjucomments .tjufood .controller ;
2+
3+ import jakarta .annotation .Resource ;
4+ import org .springframework .web .bind .annotation .GetMapping ;
5+ import org .springframework .web .bind .annotation .PathVariable ;
6+ import org .springframework .web .bind .annotation .RequestMapping ;
7+ import org .springframework .web .bind .annotation .RestController ;
8+ import xyz .tjucomments .tjufood .entity .Favorite ;
9+ import xyz .tjucomments .tjufood .entity .RestBean ;
10+ import xyz .tjucomments .tjufood .service .FavoriteService ;
11+
12+ import java .util .List ;
13+
14+ @ RestController
15+ @ RequestMapping ("/api/favorite" )
16+ public class FavoriteController {
17+
18+ @ Resource
19+ FavoriteService service ;
20+
21+ @ GetMapping ("/user/{userId}" )
22+ public RestBean <List <Favorite >> listByUser (@ PathVariable long userId ) {
23+ return RestBean .success (service .listByUser (userId ));
24+ }
25+ }
Original file line number Diff line number Diff line change 1+ package xyz .tjucomments .tjufood .entity ;
2+
3+ import lombok .Data ;
4+
5+ import java .time .LocalDateTime ;
6+
7+ @ Data
8+ public class Favorite {
9+ private Long id ;
10+ private Long userId ;
11+ private Long favoriteId ;
12+ private Integer type ;
13+ private LocalDateTime createTime ;
14+ }
Original file line number Diff line number Diff line change 1+ package xyz .tjucomments .tjufood .mapper ;
2+
3+ import org .apache .ibatis .annotations .Mapper ;
4+ import org .apache .ibatis .annotations .Select ;
5+ import xyz .tjucomments .tjufood .entity .Favorite ;
6+
7+ import java .util .List ;
8+
9+ @ Mapper
10+ public interface FavoriteMapper {
11+ @ Select ("select * from tb_favorite where user_id = #{userId}" )
12+ List <Favorite > findByUser (long userId );
13+ }
Original file line number Diff line number Diff line change 1+ package xyz .tjucomments .tjufood .service ;
2+
3+ import xyz .tjucomments .tjufood .entity .Favorite ;
4+
5+ import java .util .List ;
6+
7+ public interface FavoriteService {
8+ List <Favorite > listByUser (long userId );
9+ }
Original file line number Diff line number Diff line change 1+ package xyz .tjucomments .tjufood .service .impl ;
2+
3+ import jakarta .annotation .Resource ;
4+ import org .springframework .stereotype .Service ;
5+ import xyz .tjucomments .tjufood .entity .Favorite ;
6+ import xyz .tjucomments .tjufood .mapper .FavoriteMapper ;
7+ import xyz .tjucomments .tjufood .service .FavoriteService ;
8+
9+ import java .util .List ;
10+
11+ @ Service
12+ public class FavoriteServiceImpl implements FavoriteService {
13+
14+ @ Resource
15+ FavoriteMapper mapper ;
16+
17+ @ Override
18+ public List <Favorite > listByUser (long userId ) {
19+ return mapper .findByUser (userId );
20+ }
21+ }
You can’t perform that action at this time.
0 commit comments