买家类目功能模块实现之注意细节
1:让包名分级显示的设置方法如下:在项目的导航栏右上角有一个小齿轮,点击小齿轮,第二行菜单,【Hide Empty Middle Packages】不分层级显示,去掉前面的√
2:一般实体类类型要和数据库中表名对应,也就是说比如我的商品分类表为product_category,那么实体类应该就是ProductCategory(这里采用的是驼峰命名法)。我再举一个反例子,如果数据库中商品分类的表名为s_product_category,如果我不想让实体类类名和数据库表表名一样(因为s_product_category太难听了,又难看。如果实体类类名和数据库表名,那么实体类类名就是SProductCategory),那么我需要在实体类上面使用@Table注解,具体如下:
@Table(name="s_product_category")
public class ProductCategory {
}
3:在进行测试的时候repository.findOne(1)一直报错,原因就是repository.findOne(1)在低版本的时候支持,但是在springboot高版本的时候步支持。springboot2.0以下的版本都能良好的支持findOne(String id)方法,而springboot2.0及其以上版本就只有findOne(Example example)方法,所以解决此问题的一种方法就是修改springboot的版本,在gradle工程里面修改build.gradle文件。然后在maven里面修改版本信息。
@Autowired
private ProductCategoryRepository repository;
@Test
public void findOneTest() {
ProductCategory productCategory = repository.findOne(1);
System.out.println(productCategory.toString());
}
第一种方法:修改maven配置信息,就是在pom.xml里面进行修改。
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
第二种方法就是,不用findOne(1),因为在2的版本中已经没有了findOne(1),出现了findById(1).get();
@Test
public void findOneTest() {
ProductCategory productCategory = repository.findOne(1);
System.out.println(productCategory.toString());
}
改为:
@Test
public void findByIdTest() {
ProductCategory productCategory = repository.findById(1).get();
System.out.println(productCategory.toString());
}
4:来一个小插曲,机械键盘分为游戏模式和普通模式。如果win+R组合键使用不了,那么就是游戏模式了。可以通过FN_+win键切换到普通模式。