tensquare_article,tensquare_qa,tensquare_recruit模块的相关业务实现

tensquare_article模块

所有的模块需要注意一下:

  1. 注意一下这个 @Query注解是用来进行复杂的业务增删改查的,多表的操作需要用到这个nativeQuery=true表示纯的sql语句的查询
  2. 进行update和delete的时候需要加上 @Modifying 这个注解
  3. 必须在 @Service的实现中加上 @Transactional这个注解
  4. id=?1 表示多个参数的时候取第一个
package com.tensquare.article.dao;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;

import com.tensquare.article.pojo.Article;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

/**
 * 数据访问接口
 * @author Administrator
 *
 */
public interface ArticleDao extends JpaRepository<Article,String>,JpaSpecificationExecutor<Article>{
    
    

    /*文章审核功能
    * @Modifying 用于修改和删除的操作,一定要加上这个注解,然后在service层加上@Transition这个注解
    *
    * @parm id
    * where id=?1 表示多个id取第一个
    *
    *
    * */
    @Modifying
    @Query(value = "update tb_article set state=1 where id=?1",nativeQuery = true)
    public void examine(String id);

    /*
    * 点赞功能
    * */
    @Modifying
    @Query(value="update tb_article set thumbup=thumbup+1 where id=?1",nativeQuery=true)
    public int updateThumbup(String id);
	
}

tensquare_qa模块:

package com.tensquare.qa.dao;

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 com.tensquare.qa.pojo.Problem;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * 数据访问接口
 * @author Administrator
 *
 */
public interface ProblemDao extends JpaRepository<Problem,String>,JpaSpecificationExecutor<Problem>{
    
    



    @Query(value="SELECT *from tb_problem,tb_pl where id=problemid and labelid=? ORDER BY replytime DESC",nativeQuery=true)
    public Page<Problem> newList(String labelid, Pageable pageable);
//不加nativeQuery=true JQL 语句面向实体类的  加上变为Sql语句 面向关系数据库的
    @Query(value="SELECT *from tb_problem,tb_pl where id=problemid and labelid=? ORDER BY reply DESC",nativeQuery=true)
    public Page<Problem> hotList(String labelid,Pageable pageable);


    @Query(value="select *from tb_pl,tb_problem  where id=problemid and labelid=? AND reply=0 order by createtime DESC",nativeQuery=true)
    public Page<Problem> waitList(String labelid,Pageable pageable);
}







RecruitDao:

package com.tensquare.recruit.dao;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;

import com.tensquare.recruit.pojo.Recruit;

import java.util.List;

/**
 * 数据访问接口
 * @author Administrator
 *
 */
public interface RecruitDao extends JpaRepository<Recruit,String>,JpaSpecificationExecutor<Recruit>{
    
    

    /*查询推荐职位表,按照时间的倒序排列
    state 状态: 0:关闭 1:开启 2:推荐  查询前四条记录,并且按照创建的时间降序排序
    *
    */

    public List<Recruit> findTop4ByStateOrderByCreatetime(String state);

    /*
    * 查询最新职位信息
    * state!=0 和按照时间的倒序排序
    * findTopBy12StateNotOOrderByCreatetimeDesc 这个约定的语句可以表示这个意思
    * */
    public List<Recruit> findTopBy12StateNotOrderByCreatetimeDesc(String state);


}

猜你喜欢

转载自blog.csdn.net/houzhicongone/article/details/119960802
QA
今日推荐