zoukankan      html  css  js  c++  java
  • 微信点餐系统(四)-买家端类目

    章节感悟:

    1.单元测试类的使用

    2.IDEA中插件的使用

    买家端类目:

    DAO层设计与开发

    1.新增mysql的连接依赖包

    2.新增jpa的依赖包

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
    </dependency>
    
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    View Code

    3.配置mysql驱动,账号密码路径,以及jpasql语句是否显示

    spring:
      datasource:
        driver-class-name: com.mysql.jdbc.Driver
        username: root
        password: 123456
        url: jdbc:mysql://192.168.1.100/sell?characterEncoding=utf-8&useSSl=false
      jpa:
        show-sql: true
    View Code

    4.写设计一个ProductCategoty类放入dataobject包下,对应映射实习表以及字段,标明标签,写getset方法

    5.设计一个ProductCategoryRepository接口放入repository包下,继承JpaRepository接口

    6.单元测试

    7.增加一个lombok插件,这个插件的作用就是让我们不用写get,set,toString,然后在设置里面安装这个插件

    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
    </dependency>
    View Code

    Service层设计与开发

    1.创建ProductCategoryService接口,在接口中写四个方法

        /**
         * 查找一个商品类目
         * @param categoryId
         * @return
         */
        ProductCategory findOne(Integer categoryId);
    
        /**
         * 查找全部商品类目
         * @return
         */
        List<ProductCategory> findAll();
    
        /**
         * 通过多个商品属性查找商品类目
         * @param categoryTypeList
         * @return
         */
        List<ProductCategory> findByCategoryTypeIn(List<Integer> categoryTypeList);
    
        /**
         * 保存一个商品类目
         * @param productCategory
         * @return
         */
        ProductCategory save(ProductCategory productCategory);
    View Code

    2.编写ProductCategoryServiceImpl实现类(具体实现不用写)

    3.单元测试

    PS:这里出现了一个问题,@Autowired进行注入的类为空,原因是没有添加注解

    单元测试

    @BeforeClass 在所有测试方法前执行一次,一般在其中写上整体初始化的代码
    @AfterClass 在所有测试方法后执行一次,一般在其中写上销毁和释放资源的代码
    @Before 在每个测试方法前执行,一般用来初始化方法(比如我们在测试别的方法时,类中与其他测试方法共享的值已经被改变,为了保证测试结果的有效性,我们会在@Before注解的方法中重置数据)
    @After 在每个测试方法后执行,在方法执行完成后要做的事情
    @Test(timeout = 1000) 测试方法执行超过1000毫秒后算超时,测试将失败
    @Test(expected = Exception.class) 测试方法期望得到的异常类,如果方法执行没有抛出指定的异常,则测试失败
    @Ignore(“not ready yet”) 执行测试时将忽略掉此方法,如果用于修饰类,则忽略整个类
    @Test 编写一般测试用例
    @RunWith 在JUnit中有很多个Runner,他们负责调用你的测试代码,每一个Runner都有各自的特殊功能,你要根据需要选择不同的Runner来运行你的测试代码。
    View Code

    @SpringBootTest

    Annotation that can be specified on a test class that runs Spring Boot based tests. Provides the following features over and above the regular Spring TestContext Framework:
    Uses SpringBootContextLoader as the default ContextLoader when no specific @ContextConfiguration(loader=...) is defined.
    Automatically searches for a @SpringBootConfiguration when nested @Configuration is not used, and no explicit classes are specified.
    Allows custom Environment properties to be defined using the properties attribute.
    Provides support for different webEnvironment modes, including the ability to start a fully running web server listening on a defined or random port.
    Registers a TestRestTemplate and/or WebTestClient bean for use in web tests that are using a fully running web server.
    View Code
  • 相关阅读:
    轻松搭建CAS 5.x系列(1)-使用cas overlay搭建SSO SERVER服务端
    SpringCloud-技术专区-SSO单点登录之OAuth2.0登录认证云架构
    CAS实现单点登录原理
    CAS实现SSO单点登录原理
    使用Mmap系统调用进行硬件地址访问
    驱动阻塞模型
    Altium Designer如何批量修改名称,数值,封装
    驱动接口函数调用过程
    基本驱动模型
    从linux和ucos的比较中来看进程这个概念
  • 原文地址:https://www.cnblogs.com/xzmxddx/p/10281649.html
Copyright © 2011-2022 走看看