提交 a97fedfc authored 作者: wzj's avatar wzj

kkkk

上级 4046c0f9
......@@ -2,15 +2,18 @@ package com.example.demo.controller;
import com.example.demo.pojo.HomePage;
import com.example.demo.pojo.Sub;
import com.example.demo.service.ContainService;
import com.example.demo.service.HomePageService;
import com.example.demo.service.SubService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.text.ParseException;
import java.util.List;
/**
......@@ -25,12 +28,10 @@ public class HomeController {
@Autowired
private SubService subService;
@Autowired
private ContainService containService;
@GetMapping("/honePage")
@ApiOperation(value = "帖子主页")
public ResponseEntity findAll(){
List<HomePage>homePages =homePageService.findAll();
List<HomePage>homePages =homePageService.findfuAll();
return ResponseEntity.ok(homePages);
}
......@@ -47,13 +48,13 @@ public class HomeController {
return homePageService.saveAll(homePage);
}
@PostMapping("/userSub")
@ApiOperation(value = "保存回复贴子")
@ApiOperation(value = "保存回复评论贴子")
public Sub saveOne(@RequestBody Sub sub){
return subService.saveOne(sub);
}
@PostMapping("/saveUser")
@ApiOperation(value ="自己回复帖子" )
@ApiOperation(value ="用户本人回复帖子" )
public Sub saveUser(@RequestBody Sub sub){
return subService.saveUser(sub);
}
......@@ -61,10 +62,27 @@ public class HomeController {
@GetMapping("/ziHonePage")
@ApiOperation(value = "用户帖子")
public ResponseEntity finAll(){
List<HomePage> contains =homePageService.finAll();
List<HomePage> contains =homePageService.findziAll();
return ResponseEntity.ok(contains);
}
@GetMapping("/findByIdHomePage")
@ApiOperation(value = "主贴分页查询")
public Page<HomePage> findByIdHomePage(Integer page, Integer pageSize) {
Page<HomePage> homePages =homePageService.findByIdHomePage(page,pageSize);
return homePages;
}
@DeleteMapping("/deleteZhuTie")
@ApiOperation(value = "主贴删除")
public void deleteHomePage(HomePage homePage){
homePageService.deleteZhu(homePage);
}
@DeleteMapping("/deleteZiTie")
@ApiOperation(value = "子贴删除")
public void deleteSub(Sub sub){
subService.deleteZi(sub);
}
}
......
package com.example.demo.dao;
import com.example.demo.pojo.HomePage;
import com.example.demo.pojo.Sub;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import java.util.List;
/**
* @author wen
*/
public interface HomePageDao extends JpaRepository<HomePage,Integer> {
public interface HomePageDao extends JpaRepository<HomePage,Integer>, JpaSpecificationExecutor<HomePage>
{
@Query(value="select * from user where id > (:id)",nativeQuery = true)
Page<HomePage> findById(@Param("id") Integer id, Pageable pageable);
HomePage findByUsername(HomePage username);
/**
* 根据用户姓名,分页查询用户列表(使用原生SQL语句)
*/
@Query(value = "SELECT * FROM tb_user WHERE user_name LIKE %:name%", nativeQuery = true)
public Page<HomePage> getUserPageByNameSQL(@Param("name")String userName, Pageable pageable);
List<HomePage> findHomePageById(Integer id);
List<HomePage> findByResponderId(Integer id);
}
package com.example.demo.service;
/**
* @author wen
*/
public interface ContainService {
//List<Contain> finAll();
}
......@@ -2,7 +2,10 @@ package com.example.demo.service;
import com.example.demo.pojo.HomePage;
import com.example.demo.pojo.Sub;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import javax.persistence.criteria.Root;
import java.util.Collection;
import java.util.List;
......@@ -10,11 +13,16 @@ import java.util.List;
* @author wen
*/
public interface HomePageService {
List<HomePage> finAll();
List<HomePage> findAll();
/**分页查询+条件查询*/
Page<HomePage> findByIdHomePage(Integer page, Integer pageSize);
List<HomePage> findfuAll();
List<HomePage> findziAll();
HomePage saveAll(HomePage homePage);
void deleteZhu(HomePage homePage);
}
......@@ -13,4 +13,6 @@ public interface SubService {
List<Sub> findByResponder(Integer id);
Sub saveOne(Sub sub);
Sub saveUser(Sub sub);
void deleteZi(Sub sub);
}
......@@ -6,9 +6,17 @@ import com.example.demo.pojo.HomePage;
import com.example.demo.pojo.Sub;
import com.example.demo.service.HomePageService;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import javax.persistence.criteria.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
......@@ -17,6 +25,7 @@ import java.util.List;
*/
@Service
@Slf4j
public class HomePageServiceImpl implements HomePageService {
@Autowired
......@@ -24,11 +33,26 @@ public class HomePageServiceImpl implements HomePageService {
@Autowired
private SubDao subDao;
@Override
public List<HomePage> finAll() {
// List<HomePage> homePages=homePageDao.findByResponderId(1);
public Page<HomePage> findByIdHomePage(Integer page, Integer pageSize) {
PageRequest pageable =PageRequest.of(page,pageSize);
Page<HomePage> pageDetails =homePageDao.findAll(pageable);
List<HomePage> user =pageDetails.getContent();
for (HomePage p: user){
System.out.println(p);
}
return pageDetails;
}
@Override
public List<HomePage> findfuAll() {
// List<S// List<HomePage> homePages=homePageDao.fin
//
// List<Sub> ljSub=subDao.findByResponder(0);
// dByResponderId(1);
////ub> ljSub=subDao.findByResponder(0);
// for (Sub sub : ljSub) {
// Integer integer = sub.getId();
// List<Sub> subs1 = subDao.findByResponder(integer);
......@@ -42,12 +66,11 @@ public class HomePageServiceImpl implements HomePageService {
List<Sub> allByResponderId = subDao.findAllByResponderId(homePage.getId());
homePage.setSubList(allByResponderId);
});
return homePages;
}
@Override
public List<HomePage> findAll() {
public List<HomePage> findziAll() {
return homePageDao.findAll();
}
......@@ -56,6 +79,13 @@ public class HomePageServiceImpl implements HomePageService {
HomePage homePages =homePageDao.save(homePage);
return homePages;
}
@Override
public void deleteZhu(HomePage homePage) {
homePageDao.delete(homePage);
}
}
......
......@@ -46,4 +46,9 @@ public class SubServiceImpl implements SubService {
Sub sub1=subDao.save(sub);
return sub1;
}
@Override
public void deleteZi(Sub sub) {
subDao.delete(sub);
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论