nari基于osp平台的后端简单curd案例

本片主要描述了基于osp平台的简单的增删改查的小案例。便于记忆。
以table表格的前后端拿数据为例子!

在table中展示数据
@Controller
@RequestMapping("/getMessage")
public class TestController {
	@Autowired
	private IDBAccess dbacess;  // osp平台封装的数据库工具

// 方法一:拿取数据到前端表格	
	@RequestMapping(value = "/showList")
	@ResponseBody
     public JSONObject showList(Integer page,Integer limit){
		if(page==null){
			page = 1;
		}
		if(limit==null){
			limit = 10;
		}
		JSONObject jsonObject = new JSONObject();
		String[] cols = {"UUID","SEND_TIME","ISSUCCESSFUL","VERSIONNUM","SENDNOTES"};
		String listSql = " SELECT UUID,SEND_TIME,ISSUCCESSFUL,VERSIONNUM,SENDNOTES FROM sg_his_zpy_testtable";
		List<Object> list = dbacess.executeSqlQuery(listSql);
		String result = DeviceUtil.getJsonResult(cols, list);
		JSONArray rows = JSONArray.parseArray(result);
		try {
			jsonObject.put("code", 0);
			jsonObject.put("msg", "");
			jsonObject.put("data", rows);
		} catch (JSONException e) {
			e.printStackTrace();
		}
        return jsonObject;
	}
	/*	作用:删除单条信息
	 *	参数:uuid
	 *	返回值: 
	 * */
	@RequestMapping("/deleteOne")
	@ResponseBody
	public JSONObject  deleteData(@RequestParam String uuid){
		JSONObject jsonObject = new JSONObject();
		String deleteSql = "DELETE FROM SG_HIS_ZPY_TESTTABLE WHERE UUID = '"+uuid+"'";
		int executeSqlUpdate = dbacess.executeSqlUpdate(deleteSql);
		if(executeSqlUpdate>0){
			jsonObject.put("result", true);
		}else{
			jsonObject.put("result", false);
		}		
		return jsonObject;	
	}
	
	/*	作用:
	 *	参数:uuid
	 *	返回值: 
	 * */
	@RequestMapping("deleteChecked")
	@ResponseBody
	public JSONObject  deleteByUUID(String[] uuids){
		JSONObject jsonObject = new JSONObject();
		//String deleteSql = "DELETE FROM SG_HIS_ZPY_TESTTABLE WHERE UUID in (";
		StringBuffer stringBuffer = new StringBuffer("DELETE FROM SG_HIS_ZPY_TESTTABLE WHERE UUID in (");
		for (int i = 0; i < uuids.length; i++) {
			if (i==uuids.length-1){
				stringBuffer.append("\'"+uuids[i]+"\'"+")");
			}else{
				stringBuffer.append("\'"+uuids[i]+"\'"+",");
			}
		}	
		int executeSqlUpdate = dbacess.executeSqlUpdate(stringBuffer.toString());
		if(executeSqlUpdate>0){
			jsonObject.put("result",true);
		}else{
			jsonObject.put("result",false);
		}
		return jsonObject;
	}
	
	/*	作用:添加数据
	 *	参数:uuid,sendTime,issuccessful,versionnum,sendnates
	 *	返回值: 
	 * */
	@RequestMapping("/addData")
	@ResponseBody
	public JSONObject addData(String uuid,String sendTime,String issuccessful,String versionnum,String sendnates){
		Timestamp ts = new Timestamp(System.currentTimeMillis());  
		String tsStr = sendTime;  
        try {  
            ts = Timestamp.valueOf(tsStr);  
        } catch (Exception e) {  
            e.printStackTrace();  
        }  
		String insertSql = "insert into sg_his_zpy_testtable" +"(UUID,SEND_TIME,ISSUCCESSFUL,VERSIONNUM,SENDNOTES,OPERATIONIP)"
		                    +"values(?,?,?,?,?,'192.168.1.1')";
		
		JSONObject jsonObject = new JSONObject();
		int i = dbacess.executeSqlUpdate(insertSql,new Object[]{uuid,ts,issuccessful,versionnum,sendnates});//executeSqlUpdate添加方法
		if(i>0){
			jsonObject.put("result", true);
		}else{
			jsonObject.put("result", false);
		}
		System.out.println(jsonObject);
  
		return jsonObject;
	}
	/*	作用:修改数据
	 *	参数:uuid,sendTime,issuccessful,versionnum,sendnates
	 *	返回值: 
	 * */
	@RequestMapping("/editData")
	@ResponseBody
	public JSONObject editData(String uuid,String sendTime,String issuccessful,String versionnum,String sendnates){
		Timestamp ts = new Timestamp(System.currentTimeMillis());  
        String tsStr = sendTime;  
        try {  
            ts = Timestamp.valueOf(tsStr);  
        } catch (Exception e) {  
            e.printStackTrace();  
        }  
		String updateSql = "update sg_his_zpy_testtable set SEND_TIME = ?,ISSUCCESSFUL = ?,VERSIONNUM = ?,SENDNOTES = ? where uuid = ?";
		JSONObject jsonObject = new JSONObject();
		int executeSqlUpdate = dbacess.executeSqlUpdate(updateSql, new Object[]{ts,issuccessful,versionnum,sendnates,uuid});
		if(executeSqlUpdate>0){
			jsonObject.put("result", true);
		}else{
			jsonObject.put("result", false);
		}	
		return jsonObject;
	}	
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值