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

边栏推荐
- 快速下载JDK,除了官方Oracle下载,还有国内可以有最新版本的下载地址吗
- Problems with cat and dog queues
- Multithreading and high concurrency IV: varhandle, strong weak virtual reference and ThreadLocal
- 有大佬出现过mysql cdc用 datastream时,出现重复binlog消息的情况吗
- From meeting a big guy to becoming a big guy, shengteng AI developer creation day brings infinite possibilities to developers
- Flinkcdc collects Oracle, and the Oracle database is CDB's
- 测试/开发程序员真的是青春饭吗?世界是公平的,咱们都凭实力说话......
- 视频直播系统源码,倒计时显示,商品秒杀倒计时
- Matlab exercises -- routine operation of matrix
- 猫狗队列的问题
猜你喜欢

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

02 mongodb data types, important concepts and common shell instructions

How to clean the nozzle of Epson l3153 printer

first. Net core MVC project

With the transformation of automatic empowerment, Feihe dairy accelerates its move towards digitalization!

The growth summer challenge is coming | learn and create two major tracks, and start the tutor registration!

27年,微软IE结束了!

Introduction notes to machine learning

The coming wave of Web3

《性能之巅第2版》阅读笔记(二)--性能观察工具
随机推荐
leetcode - 329. Longest increasing path in matrix
RT thread bidirectional linked list (learning notes)
Aspnetcoreratelimit rate limit interface access limit current limit control
MSc 307 (88) (2010 FTPC code) Part 5 low flame spread test
What are the password requirements for waiting insurance 2.0? What are the legal bases?
Is it true that qiniu business school gives away securities accounts? Is it safe to open an account
The coming wave of Web3
《性能之巅第2版》阅读笔记(二)--CPU监测
03 summary of various additions, updates and deletions of mongodb documents
测试/开发程序员真的是青春饭吗?世界是公平的,咱们都凭实力说话......
Multithreading and high concurrency V: detailed explanation of wait queue, executor and thread pool (key)
抖音实战~关注博主
05 mongodb summary of various column operations
TFTLCD display experiment of mini plate based on punctual atom stm32
华为9年经验的软件测试总监工作感悟—写给还在迷茫的朋友
【Proteus仿真】定时器1外部计数中断
单一职责原则
Reading notes of top performance version 2 (II) -- CPU monitoring
一文详解|增长那些事儿
Zipkin service link tracking