当前位置:网站首页>多线程实现 重写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,这个要怎么解决有知道的牛人

边栏推荐
- 03 summary of various additions, updates and deletions of mongodb documents
- 简单工厂模式
- Excel knowledge and skills summary
- Lamaba expression learning and common functional interfaces
- From zero to one, I will teach you to build a "search by text and map" search service (I)
- June 27, 2022: give a 01 string with a length of N. now please find two intervals so that the number of 1 and the number of 0 in the two intervals are equal. The two intervals can intersect, but not c
- 易周金融 | Q1手机银行活跃用户规模6.5亿;理财子公司布局新兴领域
- 阿里P8倾情推荐,Fiddler抓包工具实战篇(一)
- From zero to one, I will teach you to build a "search by text and map" search service (I)
- The company leader said that if the personal code exceeds 10 bugs, he will be dismissed. What is the experience?
猜你喜欢

Digital promising, easy to reach, Huawei accelerates the layout of the commercial market with "five pole" star products

Games104 operation 2-colorgrading

Meichuang data security management platform has obtained the evaluation certificate of "data security product capability verification plan" of the Institute
![[Matlab bp regression prediction] GA Optimized BP regression prediction (including comparison before optimization) [including source code 1901]](/img/73/1e4c605991189acc674d85618cf0ef.png)
[Matlab bp regression prediction] GA Optimized BP regression prediction (including comparison before optimization) [including source code 1901]

27 years, Microsoft IE is over!

Tiktok practice ~ pay attention to bloggers

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

有关函数模板的那些小知识-.-

Tiktok actual battle ~ take off the blogger

The company leader said that if the personal code exceeds 10 bugs, he will be dismissed. What is the experience?
随机推荐
2022年中國音頻市場年度綜合分析
27 years, Microsoft IE is over!
Difference between curdate() and now()
How to apply for ASTM E108 flame retardant test for photovoltaic panels?
Uncover the mystery of SSL and learn how to protect data with SSL
Password encryption MD5 and salt treatment
公司领导说,个人代码超10个Bug就开除,是什么体验?
Principle of event delegation
Little knowledge about function templates --
Short video platform development, click links and pictures to automatically jump to a new page
【Matlab红绿灯识别】红绿灯识别【含GUI源码 1908期】
Another option for ERP upgrade, MES system
Source code of live video system, countdown display, countdown of commodity spike
Are the two flame retardant standards of European furniture en 597-1 and en 597-2 the same?
The coming wave of Web3
inherit
设计一个有getMin功能的栈
由两个栈组成的队列
The second round of free public classes of the red team is coming ~ 8:00 tomorrow night!
如何遍历collections.OrderedDict,服了又忘记items