1.生成查询模版后,就可以初步实现实体对应属性多条件查询,这个只能初步实现等于查询,其他复杂查询需要queryDSL对应API来实现。
Controller层:
import com.five.fiveeducation.entity.Student;
import com.five.fiveeducation.service.EducationService;
import com.querydsl.core.types.Predicate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.querydsl.binding.QuerydslPredicate;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
@PostMapping(value = "findSearch")
public List<Student> findSearch(@QuerydslPredicate(root = Student.class) Predicate predicate,Pageable pageable){
return educationService.findSearch(predicate,pageable).getContent();
}
Service层:
public Page<Student> findSearch(Predicate predicate, Pageable pageable) {
return educationDao.findAll(predicate,pageable);
}
实现多条件and查询