当前位置:网站首页>多线程实现 重写run(),怎么注入使用mapper文件操作数据库
多线程实现 重写run(),怎么注入使用mapper文件操作数据库
2022-06-28 03:55:00 【CSDN问答】
public class EchoThread implements Runnable{
private Socket client;
InputStream inputStream;private TestUtils testUtils;// @Autowired
// private EquipmentMapper equipmentMapper = SpringContextUtil.getBean(EquipmentMapper.class);
@Autowired
private EquipmentMapper equipmentMapper;
public EchoThread(Socket client){ this.client=client;}@[email protected] void run() { //this.equipmentMapper= BeanContext.getApplicationContext().getBean(EquipmentMapper.class); try { while (true){ inputStream=client.getInputStream(); byte[] bytes = new byte[1024]; inputStream.read(bytes); String string = new String(bytes); System.out.println("我是传过来的数"+string); String[] str = string.split("AAAA"); StringBuffer sb = new StringBuffer(); List<Equipment> equipmentList = new ArrayList<>(); List storage = new ArrayList(); Equipment equipment = new Equipment(); System.out.println("我是str"+str); //String sql = "INSERT INTO TABLE_NAME VALUES (?,?,?)";//插入sql for (int i=0; i<str.length;i++){ String dd =str[i].toString(); System.out.println("我是dd分隔后的数"+dd); String ee=dd.substring(0,6); System.out.println("我是ee分隔后的数"+ee); if(ee.equals("040302") ){ String ee1=dd.substring(6,10); // System.out.println("我是最新测试"+ee1); long put_Vlue = Long.parseLong(ee1, 16);//Long.parseLong(字符串,该字符串为几进制) storage.add("溶解氧:"+put_Vlue*0.001); // System.out.println(put_Vlue);//输出结果 //System.out.println("我我我我我我我我"+storage); System.out.println("溶解氧:"+put_Vlue); equipment.setDissolvedName("溶解氧"); equipment.setDissolvedValue(put_Vlue*0.001); equipmentList.add(equipment); System.out.println("我是是是是"+equipmentList); }else if(ee.equals("050404")){ String ee1=dd.substring(6,10); String ee2=dd.substring(10,14); //System.out.println("我是最新测试"+ee2); long put_Vlue = Long.parseLong(ee1, 16);//Long.parseLong(字符串,该字符串为几进制) long put_Vlue2 = Long.parseLong(ee2, 16); storage.add("土壤温湿度:"+put_Vlue*0.1+","+put_Vlue2*0.1); System.out.println("土壤温湿度"); equipment.setSoilName("土壤温湿度"); equipment.setSoilValue(put_Vlue*0.1); // equipment.setSoilValue(String.valueOf(put_Vlue2*0.1)); equipmentList.add(equipment); }else if(ee.equals("070302")){ String ee1=dd.substring(6,10); long put_Vlue = Long.parseLong(ee1, 16); storage.add("浊度:"+put_Vlue*0.01); System.out.println("浊度"); equipment.setTurbidityName("浊度"); equipment.setTurbidityValue(put_Vlue*0.01); equipmentList.add(equipment); }else if(ee.equals("030302")){ String ee1=dd.substring(6,10); long put_Vlue = Long.parseLong(ee1, 16); storage.add("水质PH:"+put_Vlue*0.01); System.out.println("水质PH"); equipment.setWaterName("水质PH"); equipment.setWaterValue(put_Vlue*0.01); equipmentList.add(equipment); }else if(ee.equals("060302")){ String ee1=dd.substring(6,10); long put_Vlue = Long.parseLong(ee1, 16); storage.add("土壤PH:"+put_Vlue*0.01); System.out.println("土壤PH"); equipment.setSoilPHName("土壤PH"); equipment.setSoilPHValue(put_Vlue*0.01); equipmentList.add(equipment); }else if(ee.equals("010302")){ String ee1=dd.substring(6,10); long put_Vlue = Long.parseLong(ee1, 16); storage.add("水温:"+put_Vlue*1); System.out.println("水温"); equipment.setTemperatureName("水温"); equipment.setTemperatureValue(put_Vlue*1); equipmentList.add(equipment); }else if(ee.equals("080304")){ String ee1=dd.substring(6,14); System.out.println("明渠流量计"); equipment.setChannelName("明渠流量计"); equipment.setChannelValue(30.2); equipmentList.add(equipment); }else if(ee.equals("020302")){ String ee1=dd.substring(6,10); long put_Vlue = Long.parseLong(ee1, 16);// storage.add("水位:"+put_Vlue0.001);
System.out.println("水位");
equipment.setWaterlevelNmae("水位");
equipment.setWaterlevelValue(put_Vlue0.001);
equipmentList.add(equipment);
}else{
System.out.println("没有数据");
}
}
System.out.println("我是最后传递的list"+equipmentList);
equipmentMapper.equipserter(equipmentList);
} } catch (IOException e) { e.printStackTrace(); }}}

我想调用mapper把数据存入数据库中,但是调用一直是null,这个要怎么解决有知道的牛人

边栏推荐
- Password encryption MD5 and salt treatment
- From zero to one, I will teach you to build a "search by text and map" search service (I)
- @Several scenarios of transactional failure
- 从零到一,教你搭建「以文搜图」搜索服务(一)
- Sum of squares of each bit of a number
- 简单工厂模式
- After launching the MES system, these changes have taken place in the enterprise
- How to apply for ASTM E108 flame retardant test for photovoltaic panels?
- Lingge leangoo agile Kanban tool adds the functions of exporting card documents and pasting shared brain map nodes
- Tiktok practice ~ pay attention to bloggers
猜你喜欢

RT thread bidirectional linked list (learning notes)

2022年中國音頻市場年度綜合分析

【Matlab红绿灯识别】红绿灯识别【含GUI源码 1908期】

27 years, Microsoft IE is over!

Uncover the mystery of SSL and learn how to protect data with SSL

2022-06-27:给出一个长度为n的01串,现在请你找到两个区间, 使得这两个区间中,1的个数相等,0的个数也相等, 这两个区间可以相交,但是不可以完全重叠,即两个区间的左右端点不可以完全一样。

Reading notes of top performance version 2 (II) -- Performance observation tool

27年,微软IE结束了!

Problems with cat and dog queues

MSc 307 (88) (2010 FTPC code) Part 2 smoke and toxicity test
随机推荐
Another option for ERP upgrade, MES system
Moonbeam integrates coin98, giving users more choices on the multi chain road
僅用遞歸函數和棧操作逆序一個棧
2022年中國音頻市場年度綜合分析
Are test / development programmers really young? The world is fair. We all speak by strength
leetcode - 329. Longest increasing path in matrix
Component splitting practice
【Matlab BP回归预测】GA优化BP回归预测(含优化前的对比)【含源码 1901期】
Short video platform development, click links and pictures to automatically jump to a new page
Multithreading and high concurrency six: source code analysis of thread pool
简单工厂模式
2022-06-27:给出一个长度为n的01串,现在请你找到两个区间, 使得这两个区间中,1的个数相等,0的个数也相等, 这两个区间可以相交,但是不可以完全重叠,即两个区间的左右端点不可以完全一样。
Moonbeam集成Coin98,给予用户在多链道路上的更多选择
Database garbled
Web3来临时的风口浪尖
Matlab exercises -- routine operation of matrix
Live online source code, JS dynamic effect, sidebar scrolling fixed effect
Password encryption MD5 and salt treatment
MSc 307 (88) (2010 FTPC code) Part 5 low flame spread test
How to clean the nozzle of Epson l3153 printer