-
service实现类要加service注解,同时注入repository
-
ctrl_alt_v 自动补全新对象的前缀
//自己写的对象
repository.findAll(pageable);
//使用快捷键后 补全了类名与变量名
Page<ProductInfo> all = repository.findAll(pageable);
- 包装类型间的相等判断应该用equals,而不是'=='
//修改前
if (productInfo.getProductStatus() == ProductStatusEnum.UP.getCode())
//修改后
if (productInfo.getProductStatus().equals(ProductStatusEnum.UP.getCode()))
-
Error:(4, 30) java: 找不到符号
符号: 类 ResultEnum
位置: 程序包 com.neusoft.sell.enums解决方法:使用maven清理掉之前打开的jar包即可
-
Inferred type 'S' for type parameter 'S' is not within its bound
查看代码,发现注入的repository正确。
所以排除了repository的问题
再次检查,发现是因为findOne()方法的问题。低版本支持该方法,但是高版本的不支持。
将findOne()方法改成findById()
后面引用的时候,在最后加上get()方法。不然返回的是列表,不是单个对象。
ProductInfo productInfo = repository.findById(productId).get();
//findById()的详细实现类
/**
* Retrieves an entity by its id.
*
* @param id must not be {@literal null}.
* @return the entity with the given id or {@literal Optional#empty()} if none found.
* @throws IllegalArgumentException if {@literal id} is {@literal null}.
*/
Optional<T> findById(ID id);
//get()的详细实现类
/**
* If a value is present in this {@code Optional}, returns the value,
* otherwise throws {@code NoSuchElementException}.
*
* @return the non-null value held by this {@code Optional}
* @throws NoSuchElementException if there is no value present
*
* @see Optional#isPresent()
*/
public T get() {
if (value == null) {
throw new NoSuchElementException("No value present");
}
return value;
}
-
快速查看类、接口、方法的详细实现
ctrl_鼠标左键
鼠标放到要查看的对象上,按住ctrl键,该对象下面会出现一条横线。
之后鼠标左键点击,就可以直接跳转过去了。