You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

155 lines
6.7 KiB

package com.votesystem.ssl.dao;
import com.votesystem.ssl.pojo.Activity;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
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.Modifying;
import org.springframework.data.jpa.repository.Query;
import java.util.List;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import java.util.List;
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.Modifying;
import org.springframework.data.jpa.repository.Query;
import java.util.List;
public interface ActivityDAO extends JpaRepository<Activity,String>, JpaSpecificationExecutor<Activity> {
@Modifying
@Query(nativeQuery = true, value = "UPDATE `tb_acticity` SET `state` = '0' WHERE `id` = ?")
int deleteActivityByState(String activityId);
Activity findOneById(String activityId);
// Page<Activity> findAll(Pageable pageable);
@Query(value = "SELECT * FROM tb_activity a WHERE a.state != '-1'",nativeQuery = true)
Page<Activity> findAllValidActivity(Pageable pageable);
//@Query(value = "SELECT * FROM tb_activity a WHERE a.state != '-2'",nativeQuery = true)
@Modifying
@Query(nativeQuery = true, value = "UPDATE `tb_activity` SET `state` = '-1' WHERE `id` = ?")
int validActivityById(String activityId);
//由boolen改成了int
//分页列出案例
@Query(value = " select * from tb_activity a where a.state = '2'",nativeQuery = true)
List<Activity> findByState(Pageable pageable);
//这个不对
@Query(value = "SELECT * FROM tb_activity WHERE state != '-1' ",nativeQuery = true)
Page<Activity> findAllByAuthor(String author ,Pageable pageable);
}
//@Mapper
//public interface ActivityDAO {
//
// @Update("UPDATE `tb_acticity` SET `state` = '0' WHERE `id` = #{activityId,jdbcType=VARCHAR}")
// int deleteActivityByState(String activityId);
// @Select("SELECT * FROM tb_activity WHERE id = #{activityId}")
// Activity findOneById(String activityId);。
// @Select("SELECT * FROM tb_activity")
// Page<Activity> findAll(Pageable pageable);
// @Select( "select * from tb_activity a where a.state = '2'")
// List<Activity> findByState(Pageable pageable);
// @Select("SELECT * FROM tb_activity WHERE author = #{author}")
// Page<Activity> findAllByAuthor(String author ,Pageable pageable);
// @Insert("Insert into tb_activity (id,author,title,content,state,type,sign_in,verify_code,start_time,end_time,create_time,update_time)"
// + "values (#{id,jdbcType=VARCHAR},#{author,jdbcType=VARCHAR},"
// + "#{title,jdbcType=VARCHAR},#{content,jdbcType=VARCHAR},"
// + "#{state,jdbcType=VARCHAR},#{type,jdbcType=VARCHAR},#{sign_in,jdbcType=VARCHAR},"
// + "#{verify_code,jdbcType=BOOLEAN},#{start_time,jdbcType=VARCHAR},"
// + "#{end_time,jdbcType=VARCHAR},#{create_time,jdbcType=VARCHAR},#{update_time,jdbcType=VARCHAR});")
// boolean save(Activity activity);
//}
//import com.votesystem.ssl.pojo.Activity;
//import org.apache.ibatis.annotations.Insert;
//import org.apache.ibatis.annotations.Mapper;
//import org.apache.ibatis.annotations.Select;
//import org.apache.ibatis.annotations.Update;
//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.Modifying;
//import org.springframework.data.jpa.repository.Query;
//
//import java.util.List;
////
////public interface ActivityDAO extends JpaRepository<Activity,String>, JpaSpecificationExecutor<Activity> {
////
//// @Modifying
//// @Query(nativeQuery = true, value = "UPDATE `tb_acticity` SET `state` = '0' WHERE `id` = ?")
//// int deleteActivityByState(String activityId);
////
//// Activity findOneById(String activityId);
////
//// Page<Activity> findAll(Pageable pageable);
////
//// //分页列出案例
//// @Query(value = " select * from tb_activity a where a.state = '2'",nativeQuery = true)
//// List<Activity> findByState(Pageable pageable);
////
//// Page<Activity> findAllByAuthor(String author ,Pageable pageable);
////
////
////
////}
//@Mapper
//public interface ActivityDAO {
//
// @Update("UPDATE `tb_acticity` SET `state` = '0' WHERE `id` = #{activityId,jdbcType=VARCHAR}")
// int deleteActivityByState(String activityId);
//
// @Select("SELECT * FROM tb_activity WHERE id = #{activityId}")
// Activity findOneById(String activityId);
//
//// @Select("SELECT * FROM tb_activity LIMIT #{pageable.pageNumber}, #{pageable.pageSize}") //这样?你问我? 应该是这样吧
//// Page<Activity> findAll(Pageable pageable);
//
// // @Select("SELECT * FROM tb_activity") //这样? 先这样 不行再那样
//// List<Activity> findAll();
//// List<Activity> findAll(Pageable pageable);
// @Select("SELECT * FROM tb_activity")
// List<Activity> findAll();
//
//
// @Select("SELECT * FROM tb_activity WHERE state = '2'")
// List<Activity> findByState();
//// List<Activity> findByState(Pageable pageable);
//
// @Select("SELECT * FROM tb_activity WHERE author = #{author}")
// List<Activity> findAllByAuthor(String author);
//// List<Activity> findAllByAuthor(String author, Pageable pageable);
//
// @Insert("INSERT INTO tb_activity(id, author, title, content, state, type, sign_in, verify_code, start_time, end_time, create_time, update_time) VALUES (#{id}, #{author}, #{title}, #{content}, #{state}, #{type}, #{signIn}, #{verifyCode}, #{startTime}, #{endTime}, #{createTime}, #{updateTime})")
// boolean save(Activity activity);
//
// @Update("UPDATE tb_activity SET author = #{author}, title = #{title}, content = #{content}, state = #{state}, type = #{type}, signIn = #{sign_in}, verifyCode = #{verify_code}, startTime = #{start_time}, endTime = #{end_time}, createTime = #{create_time}, updateTime = #{update_time} WHERE id = #{id}")
// boolean updat(Activity activityFromDb);
//}