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

边栏推荐
- From zero to one, I will teach you to build a "search by text and map" search service (I)
- 01 overview, application scenarios, Download methods, connection methods and development history of mongodb
- Database garbled
- What is the process of en 1101 flammability test for curtains?
- Has any boss ever seen repeated binlog messages when MySQL CDC uses datastream
- Go语言学习教程(十四)
- With the transformation of automatic empowerment, Feihe dairy accelerates its move towards digitalization!
- 有人用cdc同步到mysql发生过死锁吗?
- The development of the Internet has promoted the emergence of a series of new models such as unbounded retail, digital retail and instant retail
- If mysqlcdc sets multiple parallelism, will the incremental data repeat?
猜你喜欢

From zero to one, I will teach you to build a "search by text and map" search service (I)

Visualization of loss using tensorboard

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

mysql导入文本文件时的pager

Meichuang data security management platform has obtained the evaluation certificate of "data security product capability verification plan" of the Institute

10: 00 interview, came out at 10:02, the question is really too

10:00面试,10:02就出来了 ,问的实在是太...

@Several scenarios of transactional failure

Little knowledge about function templates --

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
随机推荐
一文详解|增长那些事儿
僅用遞歸函數和棧操作逆序一個棧
华为9年经验的软件测试总监工作感悟—写给还在迷茫的朋友
单一职责原则
Introduction notes to machine learning
Is it true that qiniu business school gives away securities accounts? Is it safe to open an account
公司领导说,个人代码超10个Bug就开除,是什么体验?
Establishment of SSH Framework (Part 2)
Lamaba expression learning and common functional interfaces
Conversion between decimal and BCD codes in C language
Iso8191 test is mentioned in as 3744.1. Are the two tests the same?
Go language -select statement
用一个栈实现另一个栈的排序
Bitlock recovery occurs in win 10, and the blue screen error code is 0x1600007e
易周金融 | Q1手机银行活跃用户规模6.5亿;理财子公司布局新兴领域
Excel knowledge and skills summary
Reading notes of top performance version 2 (II) -- CPU monitoring
视频直播系统源码,倒计时显示,商品秒杀倒计时
02 mongodb data types, important concepts and common shell instructions
[MySQL] multi table connection query