spring boot中使用关键字搜索的问题

最近在用spring boot框架做一个项目。做到使用关键字搜索的时候出现以下报错:

org.springframework.dao.InvalidDataAccessApiUsageException: Parameter with that position [1] did not exist; nested exception is java.lang.IllegalArgumentException: Parameter with that position [1] did not exist

我的repository类如下:(关于@RepositoryRestResource可以参考http://www.jianshu.com/p/3423fa97d185)

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
import org.springframework.transaction.annotation.Transactional;

import edu.dgut.supervision.domain.VDuchadian;

@RepositoryRestResource(collectionResourceRel = "VDuchadian", path = "vDuchadian")
public interface DuchadianRepository extends PagingAndSortingRepository<VDuchadian, String>{//String代表主键的数据类型

	
	List<VDuchadian> findByProjectNo(@Param("projectNo") String projectNo);
	
	@Transactional(readOnly=true)
	@Query("select u from VDuchadian u where u.number = ?1")
	VDuchadian findByNumber(@Param("number") String number);
	
	@Transactional(readOnly=true)
	@Query("select u from VDuchadian u where u.name like '%?1%'")
	Page<VDuchadian> findByKeyWords(@Param("keywords") String keywords,Pageable pageable);
}

其中findByKeyWords是我写的模糊查询的接口

经过多次测试发现将模糊查询语句中like后面的单引号去掉就行了,但是sql语句中like后面是要加单引号的,可能这是spring boot中的一种设计吧,后面有待深入研究


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值