javaweb实现测试用例管理系统

package com.example.first.hello;

import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class DbController {
@RequestMapping("/users/demos")
public String data() {
String result = “\r\n” +
“<html lang=“zh-CN”>\r\n” +
“\r\n” +
“\r\n” +
" <meta charset=“utf-8”>\r\n" +
" <meta http-equiv=“x-ua-compatible” content=“ie=edge”>\r\n" +
" HTML模板文件\r\n" +
" <meta name=“viewport” content=“width=device-width, initial-scale=1”>\r\n" +
“\r\n” +
“\r\n” +
“\r\n” +
"

\r\n" +
" <tr style=“color:red”>\r\n" +
" \r\n" +
" \r\n" +
" \r\n" +
" \r\n" +
" \r\n" +
"
11121
\r\n" +
“\r\n” +
“\r\n” +
“\r\n” +
“”;
return result;
}
@Autowired
private JdbcTemplate jdbcTemplate;

@RequestMapping("/getUsers")
public List<Map<String, Object>> getDbType(){
    String sql = "select * from users";
    List<Map<String, Object>> list =  jdbcTemplate.queryForList(sql);
    for (Map<String, Object> map : list) {
        Set<Entry<String, Object>> entries = map.entrySet( );
            if(entries != null) {
                Iterator<Entry<String, Object>> iterator = entries.iterator( );
                while(iterator.hasNext( )) {
                Entry<String, Object> entry =(Entry<String, Object>) iterator.next( );
                Object key = entry.getKey( );
                Object value = entry.getValue();
                System.out.println(key+":"+value);
            }
        }
    }
    return list;
}

@RequestMapping("/user/{id}")
public Map<String,Object> getUser(@PathVariable String id){
    Map<String,Object> map = null;
    
    List<Map<String, Object>> list = getDbType();
    
    for (Map<String, Object> dbmap : list) {
        
        Set<String> set = dbmap.keySet();
        
        for (String key : set) {
            if(key.equals("id")){    
                if(dbmap.get(key).equals(id)){
                    map = dbmap;
                }
            }
        }
    }
    
    if(map==null)
        map = list.get(0);
    return map;
}
@RequestMapping("/list")
public List<Map<String, Object>> itemsList() {
	String sql = "select * from casetable";
	List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
	return list;
}
@RequestMapping("/add")
public @ResponseBody String  addUser(User user) {
	String sql = "insert into casetable  values (?,?,?,?,?)";
	Object args[] = {3,"金融科技","sxf",3,0};  
	int temp = jdbcTemplate.update(sql, args); 
	if(temp > 0) {
		return "文章新增成功";
	}
	return "新增出现错误";
}
@RequestMapping("/del")
public @ResponseBody String  delItems(User items) {
	String sql = "delete from casetable where id = ?";
	Object args[] = {1};  
	int temp = jdbcTemplate.update(sql, args); 
	if(temp > 0) {
		return "文章删除成功";
	}
	return "删除出现错误";
}
@RequestMapping("/upd")
public @ResponseBody String  updItems(User items) {
	String sql = "update casetable set casename = ?,testbug = ? where id = ?";
	Object args[] = {"edc",55,1};  
	int temp = jdbcTemplate.update(sql, args); 
	if(temp > 0) {
		return "文章修改成功";
	}
	return "修改出现错误";
}

@RequestMapping("delete/user/{id}")
public Map<String,Object> deleteUser(@PathVariable String id){
    Map<String,Object> map = null;
    
    List<Map<String, Object>> list = getDbType();
    
    for (Map<String, Object> dbmap : list) {
        
        Set<String> set = dbmap.keySet();
        
        for (String key : set) {
            if(key.equals("id")){    
                if(dbmap.get(key).equals(id)){
                    map = dbmap;
                }
            }
        }
    }
    
    if(map==null)
        map = list.get(0);
    return map;
}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值