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, JpaSpecificationExecutor { @Modifying @Query(nativeQuery = true, value = "UPDATE `tb_acticity` SET `state` = '0' WHERE `id` = ?") int deleteActivityByState(String activityId); Activity findOneById(String activityId); // Page findAll(Pageable pageable); @Query(value = "SELECT * FROM tb_activity a WHERE a.state != '-1'",nativeQuery = true) Page 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 findByState(Pageable pageable); //这个不对 // @Query(value = "SELECT * FROM tb_activity WHERE state = 1 ",nativeQuery = true) Page 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); // // 你这几句都没写对应的SQL语句。 // @Select("SELECT * FROM tb_activity") // Page findAll(Pageable pageable); // @Select( "select * from tb_activity a where a.state = '2'") // List findByState(Pageable pageable); // @Select("SELECT * FROM tb_activity WHERE author = #{author}") // Page 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, JpaSpecificationExecutor { //// //// @Modifying //// @Query(nativeQuery = true, value = "UPDATE `tb_acticity` SET `state` = '0' WHERE `id` = ?") //// int deleteActivityByState(String activityId); //// //// Activity findOneById(String activityId); //// //// Page findAll(Pageable pageable); //// //// //分页列出案例 //// @Query(value = " select * from tb_activity a where a.state = '2'",nativeQuery = true) //// List findByState(Pageable pageable); //// //// Page 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 findAll(Pageable pageable); // // // @Select("SELECT * FROM tb_activity") //这样? 先这样 不行再那样 //// List findAll(); //// List findAll(Pageable pageable); // @Select("SELECT * FROM tb_activity") // List findAll(); // // // @Select("SELECT * FROM tb_activity WHERE state = '2'") // List findByState(); //// List findByState(Pageable pageable); // // @Select("SELECT * FROM tb_activity WHERE author = #{author}") // List findAllByAuthor(String author); //// List 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); //}