zoukankan      html  css  js  c++  java
  • 第三篇 -- IDEA 创建Springboot Web项目并用Jmeter测试

    上一节使用Django写的一个接口程序,这一节讲用IDEA配合Springboot创建web项目。一个是python,一个是java。

    参考链接:http://www.uxys.com/html/JavaKfjs/20191008/840.html

    一、使用IDEA创建Web项目

    这个例子用的是IDEA的社区版,不过企业版更好用。

    1. 首先安装spring插件,安装完成后会提示重启IDE,重启就行。

     

     2. 创建web项目

     

     

     

     

     3. 新建一个helloword.java

    package com.example.demo;
    
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    import org.springframework.web.bind.annotation.ResponseBody;
    import org.springframework.web.bind.annotation.RestController;
    
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    
    @RestController
    public class helloword {
        @RequestMapping(value = "/hello", method = RequestMethod.GET)
        public String helloWorld () {
            return "Hello World !";
        }
    
        @RequestMapping(value = "users", method = RequestMethod.GET)
        public @ResponseBody Object users(){
            List<String> userList = new ArrayList<>();
            userList.add("tom");
            userList.add("marry");
            userList.add("jack");
            System.out.println("get request, users api");
            return userList;
        }
    
        @RequestMapping(value = "login", method = RequestMethod.POST)
        public @ResponseBody Object login(String name, String pwd){
            Map<String, Object> map = new HashMap<>();
            if("123".equals(pwd) && "jack".equals(name)){
                map.put("status", 0);
            }else{
                map.put("status", -1);
            }
            System.out.println("get request, login api");
            return map;
        }
    
        @RequestMapping(value = "info", method = RequestMethod.GET)
        public @ResponseBody Object info(String name){
            List<String> userList = new ArrayList<>();
            userList.add(name);
            userList.add(name.length() + "");
            System.out.println("get request, info api");
            return userList;
        }
    }
    View Code

    4. 运行DemoApplication

    5. 在浏览器地址栏输入http://localhost:8080/hello,就可以看到页面显示Hello world!。 

    6. 如果出现8080端口冲突,可以修改端口号,在application.properties里面修改。

    修改端口号:server.port=8088

    修改上下文:server.servlet.context-path=/app

     然后在运行DemoApplication,在浏览器地址栏输入http://127.0.0.1:8088/app/hello。

    二、 Jmeter测试上述接口

  • 相关阅读:
    java object bean 转map
    常用css
    mysql 生成max+1编号
    MySql避免重复插入记录方法(ignore,Replace,ON DUPLICATE KEY UPDATE)
    cookie记住账户密码
    session有效时间
    常用jstl
    高性能MySQL--innodb中事务的隔离级别与锁的关系
    mysql8.0.11的坑早知道
    git进阶--你可能不知道的很好用git功能
  • 原文地址:https://www.cnblogs.com/smart-zihan/p/14456432.html
Copyright © 2011-2022 走看看