当前位置:网站首页>Multi thread implementation rewrites run (), how to inject and use mapper file to operate database
Multi thread implementation rewrites run (), how to inject and use mapper file to operate database
2022-06-28 04:39:00 【CSDN Q & A】
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(" I am the number that comes from "+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(" I am a str"+str); //String sql = "INSERT INTO TABLE_NAME VALUES (?,?,?)";// Insert sql for (int i=0; i<str.length;i++){ String dd =str[i].toString(); System.out.println(" I am a dd Number after separation "+dd); String ee=dd.substring(0,6); System.out.println(" I am a ee Number after separation "+ee); if(ee.equals("040302") ){ String ee1=dd.substring(6,10); // System.out.println(" I am the latest test "+ee1); long put_Vlue = Long.parseLong(ee1, 16);//Long.parseLong( character string , The string is hexadecimal ) storage.add(" Dissolved oxygen (do) :"+put_Vlue*0.001); // System.out.println(put_Vlue);// Output results //System.out.println(" I, I, I, I, I, I "+storage); System.out.println(" Dissolved oxygen (do) :"+put_Vlue); equipment.setDissolvedName(" Dissolved oxygen (do) "); equipment.setDissolvedValue(put_Vlue*0.001); equipmentList.add(equipment); System.out.println(" I am yes yes yes "+equipmentList); }else if(ee.equals("050404")){ String ee1=dd.substring(6,10); String ee2=dd.substring(10,14); //System.out.println(" I am the latest test "+ee2); long put_Vlue = Long.parseLong(ee1, 16);//Long.parseLong( character string , The string is hexadecimal ) long put_Vlue2 = Long.parseLong(ee2, 16); storage.add(" Soil temperature and humidity :"+put_Vlue*0.1+","+put_Vlue2*0.1); System.out.println(" Soil temperature and humidity "); equipment.setSoilName(" Soil temperature and humidity "); 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(" turbidity :"+put_Vlue*0.01); System.out.println(" turbidity "); equipment.setTurbidityName(" turbidity "); 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(" The water quality PH:"+put_Vlue*0.01); System.out.println(" The water quality PH"); equipment.setWaterName(" The water quality 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(" soil PH:"+put_Vlue*0.01); System.out.println(" soil PH"); equipment.setSoilPHName(" soil 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(" The water temperature :"+put_Vlue*1); System.out.println(" The water temperature "); equipment.setTemperatureName(" The water temperature "); equipment.setTemperatureValue(put_Vlue*1); equipmentList.add(equipment); }else if(ee.equals("080304")){ String ee1=dd.substring(6,14); System.out.println(" Open channel flowmeter "); equipment.setChannelName(" Open channel flowmeter "); 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(" The water level :"+put_Vlue0.001);
System.out.println(" The water level ");
equipment.setWaterlevelNmae(" The water level ");
equipment.setWaterlevelValue(put_Vlue0.001);
equipmentList.add(equipment);
}else{
System.out.println(" No data ");
}
}
System.out.println(" I am the last one to pass list"+equipmentList);
equipmentMapper.equipserter(equipmentList);
} } catch (IOException e) { e.printStackTrace(); }}
}
I want to call mapper Put the data into the database , But the call is always null, How to solve this problem for those who know
边栏推荐
- Excel knowledge and skills summary
- 【Matlab BP回归预测】GA优化BP回归预测(含优化前的对比)【含源码 1901期】
- 11_ Deliberate practice and elaboration
- 简单工厂模式
- Are test / development programmers really young? The world is fair. We all speak by strength
- Google Earth Engine(GEE)——全球洪水数据库 v1 (2000-2018年)
- Annual comprehensive analysis of China's audio market in 2022
- [matlab traffic light identification] traffic light identification [including GUI source code 1908]
- How do I get the STW (pause) time of a GC (garbage collector)?
- Matlab exercises -- basic data processing
猜你喜欢
论文详读:IMPROVING CONVOLUTIONAL MODELS FOR HANDWRITTEN TEXT RECOGNITION
Introduction to multi project development, basic design class library project use
CUPTI error: CUPTI could not be loaded or symbol could not be found.
first. Net core MVC project
Matlab exercises -- basic data processing
In the era of video explosion, who is supporting the high-speed operation of video ecological network?
测试开发必备技能:安全测试漏洞靶场实战
The company leader said that if the personal code exceeds 10 bugs, he will be dismissed. What is the experience?
抖音实战~取关博主
Why are cloud vendors targeting this KPI?
随机推荐
100+数据科学面试问题和答案总结 - 机器学习和深度学习
Resolve cross domain
[MySQL] multi table connection query
2022年中國音頻市場年度綜合分析
Establishment of SSH Framework (Part 2)
Learning about DC-DC step-down chip of sy8120i (12V reduced to 3.3V)
请问下,mysqlcdc设置多并行度的话,增量数据是不是会重复?
Matlab exercises -- basic data processing
CUPTI error: CUPTI could not be loaded or symbol could not be found.
Array method
2022年中国音频市场年度综合分析
Audio and video technology development weekly
Is the securities account opened by qiniu safe? How to open an account
With favorable policies, more than 20 provinces and cities have launched the yuanuniverse development plan
Password encryption MD5 and salt treatment
After launching the MES system, these changes have taken place in the enterprise
Reverse a stack with recursive functions and stack operations only
To quickly download JDK, in addition to the official Oracle download, is there a download address for the latest version available in China
抖音实战~取关博主
RT-Thread 双向链表(学习笔记)