04 P2P互联网金融平台-阶段性测试

使用junit进行单元测试

创建测试类
在dataService工程下创建测试类
在这里插入图片描述
在这里插入图片描述
在java文件夹下再创建相应的package和class类。
在这里插入图片描述
ServiceTest测试类中的内容:

public class ServiceTest {

    private IBidInfoService bidInfoService;
    private ILoanInfoService loanInfoService;
    private IUserService userService;

    @Before
    public void before(){
        String conf1 = "spring-ds.xml";
        String conf2 = "spring-mybatis.xml";
        String conf3 = "spring-provider.xml";
        String conf4 = "spring-redis.xml";
        String conf5 = "spring-service.xml";
        String conf6 = "spring-tx.xml";
        String[] confs = {conf1, conf2, conf3, conf4, conf5, conf6};

        ApplicationContext ac = new ClassPathXmlApplicationContext(confs);

        bidInfoService = ac.getBean(IBidInfoService.class);
        loanInfoService = ac.getBean(ILoanInfoService.class);
        userService = ac.getBean(IUserService.class);
    }

    @Test
    public void test01(){
        //测试平台用户总人数
        Long totalUserCount = userService.findTotalUserCount();
        System.out.println(totalUserCount);
    }

    @Test
    public void test02() {
        //测试平均历史年化收益率
        Double historyAvgRate = loanInfoService.findHistoryAvgRate();
        System.out.println(historyAvgRate);
    }

    @Test
    public void test03() {
        //测试平台总成交额
        Double totalBidAmount = bidInfoService.findTotalBidAmount();
        System.out.println(totalBidAmount);
    }
}

开启Redis与Zookeeper虚拟机
在这里插入图片描述
在这里插入图片描述
移动dao层对应的映射文件的位置
将原本与dao层接口在一块的映射文件,移动到resources下。这样做的原因是:不移动的话会报出,MyBatis绑定错误:Invalid bound statement (not found)。
解决方法:参考博客在这里插入图片描述
指定移动后的映射文件的位置
在主配置文件mybatis.xml中添加这三个配置文件的位置。

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
    <!-- 注册实体类别名 -->
    <typeAliases>
        <package name="com.yanchuanyi.p2p.exterface.bean"/>
    </typeAliases>

    <!-- 注册Mapper -->
    <mappers>
        <!--<package name="com.yanchuanyi.p2p.dataService.dao"/>-->
        <mapper resource="IBidInfoDao.xml"/>
        <mapper resource="ILoanInfoDao.xml"/>
        <mapper resource="IUserDao.xml"/>
    </mappers>
</configuration>

对test02的测试结果。
在这里插入图片描述
阶段性的测试成功证明,项目搭建成功,与数据库交互无碍,接下来进行进一步测试。

web工程的测试

添加Tomcat服务器
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
选择Deployment,点击+号,选择Artiface…
在这里插入图片描述
选择dataService:wer,作为这个tomcat所运行的项目。
在这里插入图片描述
下面的Application context的值可自行设置,设置完毕点击Apply完成tomcat01的配置。
在这里插入图片描述
紧接着再添加另一个tomcat02,运行web工程。
在这里插入图片描述
修改端口号,避免多个服务器一起运行发生冲突。
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
IndexHandler处理器类

@Controller
public class IndexHandler {

    @Autowired
    private ILoanInfoService loanInfoService;
    @Autowired
    private IBidInfoService bidInfoService;
    @Autowired
    private IUserService userService;

    @RequestMapping("/index.do")  //从web.xml文件中注册的中央调度器规定的*.do为后缀
    public String indexHandler(Model model){

        Map<String,Object> map = new HashMap<>();
        map.put("pageStartIndex", 0);

        //查询新手宝产品(产品类型:0,页面大小:1),并将其存放到Model中
        map.put("productType",0);
        map.put("pageSize",1);
        List<LoanInfo> xinLoanInfos = loanInfoService.findLoanInfoByProductTypeAndPage(map);
        model.addAttribute("xinLoanInfos",xinLoanInfos);
        for (LoanInfo loaninfo : xinLoanInfos) {
            System.out.println(loaninfo);
        }
        System.out.println("----------------------");

        //查询优选类产品(产品类型:1,页面大小:4),并将其存放到Model中
        map.put("productType",1);
        map.put("pageSize",4);
        List<LoanInfo> youLoanInfos = loanInfoService.findLoanInfoByProductTypeAndPage(map);
        model.addAttribute("youLoanInfos",youLoanInfos);
        for (LoanInfo loaninfo : youLoanInfos) {
            System.out.println(loaninfo);
        }
        System.out.println("----------------------");

        //查询散标类产品(产品类型:2,页面大小:8),并将其存放到Model中
        map.put("productType",2);
        map.put("pageSize",8);
        List<LoanInfo> sanLoanInfos = loanInfoService.findLoanInfoByProductTypeAndPage(map);
        model.addAttribute("sanLoanInfos",sanLoanInfos);
        for (LoanInfo loaninfo : sanLoanInfos) {
            System.out.println(loaninfo);
        }
        System.out.println("----------------------");

        //查询平台历史年化收益率
        Double historyAvgRate = loanInfoService.findHistoryAvgRate();
        model.addAttribute("historyAvgRate",historyAvgRate);
        System.out.println("historyAvgRate = " + historyAvgRate);

        //查询平台总人数
        Long totalUserCount = userService.findTotalUserCount();
        model.addAttribute("totalUserCount",totalUserCount);
        System.out.println("totalUserCount = " + totalUserCount);

        //查询平台总成交额
        Double totalBidAmount = bidInfoService.findTotalBidAmount();
        model.addAttribute("totalBidAmount",totalBidAmount);
        System.out.println("totalBidAmount = " + totalBidAmount);

        return "/index.jsp";
    }
}

这个测试的目的是tomcat服务器是否能正常使用,查询的结果在控制台上输出。
当然Redis、Zookeeper还是正常启动的。
在这里插入图片描述
在这里插入图片描述
为避免数据库中有空数据报错,所以,需要修改一下spring-ds.xml这个配置文件中的内容。将url的值进行修改。

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

    <!-- 注册数据源 -->
    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
        <property name="url" value="jdbc:mysql:///p2p?zeroDateTimeBehavior=convertToNull"/>
        <property name="username" value="root"/>
        <property name="password" value="991018"/>
    </bean>
</beans>

启动tomcat
先选中tomcat01,然后点击右边的绿色启动按钮。
在这里插入图片描述
启动完成后,会显示dataService工程中默认的index页面。
在这里插入图片描述
然后再选中tomcat02,再进行启动。
在这里插入图片描述
启动成功后,会显示web工程中静态页面的内容。
在这里插入图片描述
此时控制台中会出现查询的查询的结果,就说明测试成功。
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
P2P信贷系统,专为基于互联网的借贷而开发的一套应用系统,通过网络为个人与个人提供个人小额贷款、无抵押贷款的网上借款,从而借款者解决缺少资金周转、创业问题,同时也给投资者带来可观的回报。P2P信贷,指有资金并且有理财投资想法的个人,通过第三方网络平台牵线搭桥,使用信用贷款的方式将资金贷给其他有借款需求的人。其中,中介 机构负责对借款方的经济效益、经营管理水平、发展前景等情况进行详细的考察,并收取账户管理费和服务费等收入。这种操作模式依据的是《合同 法》,其实就是一种民间借贷方式,只要贷款利率不超过银行同期贷款利率的4倍,就是合法的。 P2P是一种个人对个人的信贷模式,是小额信贷模 式的创新。 P2P是一种原始的信贷模式,其产生应该是基于个人和个人之间的信任或实物抵押,既个人信用和商业信用。基于个人信用的P2P天生就是一种小额 信用贷款。随着信贷需求的不断增加,原始的P2P不再能满足发展的需要,因此产生了专业金融机构,将个人的资金集合成起来提供给需要信贷的 人们,将资金在余缺双方进行资源分配,这样就提高了交易的效率,降低了交易成本。但由于金融机构切断了供需双方个人之间的信息联系,因此 产生了金融风险。为克服风险,银行往往采用抵押担保等措施防止和减少拖欠带来的损失。也因此将无法提供抵押担保条件的借款人排斥在金融服 务的门外。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

坚定你坚定的步伐

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值