会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132850个问题
JAVA 全系列/第四阶段:网页编程和设计/HTML5(旧) 33286楼
JAVA 全系列/第四阶段:网页编程和设计/Jquery(旧) 33287楼
JAVA 全系列/(旧的隐藏)第七阶段:JAVA 高级技术/VSFTPD 33288楼

老师您好:

在做商品的上下架这个功能的时候,点击下架按钮,在服务的消费者的业务层里面调用服务提供者的方法的时候调用不会进入到方法里面去。

服务的消费者业务层代码:

public EgoResult instockItem(Long[] ids) {

    // 将ids数组转换为List集合
    List<Long> itemIds = Arrays.asList(ids);
    System.out.println("begin");
    EgoResult result = itemServiceProxy.updateItemStatus(itemIds, false);
    return result;
}

服务提供者业务层代码:

@Override
public EgoResult updateItemStatus(List<Long> itemIds, Boolean flag) {
    System.out.println("toUpdateItemStatus");

    // 创建TbItem对象
    TbItem item = new TbItem();

    if(flag){
        item.setStatus((byte) 1);
    }else{
        item.setStatus((byte) 2);
    }
    // 动态产生where条件
    TbItemExample example = new TbItemExample();
    TbItemExample.Criteria c = example.createCriteria();
    c.andIdIn(itemIds);

    // updateByExample()方法相当于where id in (1,2,3)
    tbItemMapper.updateByExample(item,example);
    // 该方法只能进行单条删除
    // tbItemMapper.updateByPrimaryKey();
    return EgoResult.ok();
}

点击下架按钮:

image.png

看这个打印是没有进入到服务的提供者的业务层里面去。

这是报错的内容:

SQL: update tb_item     set id = ?,       title = ?,       sell_point = ?,       price = ?,       num = ?,       barcode = ?,       image = ?,       cid = ?,       status = ?,       created = ?,       updated = ?                    WHERE (  id in                   (                     ?                   ,                     ?                   ,                     ?                   ) )
### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Column 'id' cannot be null
; SQL []; Column 'id' cannot be null; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Column 'id' cannot be null
	at org.springframework.jdbc.support.SQLExceptionSubclassTranslator.doTranslate(SQLExceptionSubclassTranslator.java:85)
	at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73)
	at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:82)
	at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:73)
	at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:371)
	at com.sun.proxy.$Proxy10.update(Unknown Source)
	at org.mybatis.spring.SqlSessionTemplate.update(SqlSessionTemplate.java:254)
	at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:54)
	at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52)
	at com.sun.proxy.$Proxy11.updateByExample(Unknown Source)
	at cn.wjx.ego.rpc.service.impl.ItemServiceImpl.updateItemStatus(ItemServiceImpl.java:69)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
	at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
	at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:282)
	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
	at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
	at com.sun.proxy.$Proxy14.updateItemStatus(Unknown Source)
	at com.alibaba.dubbo.common.bytecode.Wrapper0.invokeMethod(Wrapper0.java)
	at com.alibaba.dubbo.rpc.proxy.javassist.JavassistProxyFactory$1.doInvoke(JavassistProxyFactory.java:46)
	at com.alibaba.dubbo.rpc.proxy.AbstractProxyInvoker.invoke(AbstractProxyInvoker.java:72)
	at com.alibaba.dubbo.rpc.protocol.InvokerWrapper.invoke(InvokerWrapper.java:53)
	at com.alibaba.dubbo.rpc.filter.ExceptionFilter.invoke(ExceptionFilter.java:64)
	at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91)
	at com.alibaba.dubbo.monitor.support.MonitorFilter.invoke(MonitorFilter.java:75)
	at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91)
	at com.alibaba.dubbo.rpc.filter.TimeoutFilter.invoke(TimeoutFilter.java:42)
	at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91)
	at com.alibaba.dubbo.rpc.protocol.dubbo.filter.TraceFilter.invoke(TraceFilter.java:78)
	at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91)
	at com.alibaba.dubbo.rpc.filter.ContextFilter.invoke(ContextFilter.java:60)
	at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91)
	at com.alibaba.dubbo.rpc.filter.GenericFilter.invoke(GenericFilter.java:112)
	at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91)
	at com.alibaba.dubbo.rpc.filter.ClassLoaderFilter.invoke(ClassLoaderFilter.java:38)
	at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91)
	at com.alibaba.dubbo.rpc.filter.EchoFilter.invoke(EchoFilter.java:38)
	at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91)
	at com.alibaba.dubbo.rpc.protocol.dubbo.DubboProtocol$1.reply(DubboProtocol.java:108)
	at com.alibaba.dubbo.remoting.exchange.support.header.HeaderExchangeHandler.handleRequest(HeaderExchangeHandler.java:84)
	at com.alibaba.dubbo.remoting.exchange.support.header.HeaderExchangeHandler.received(HeaderExchangeHandler.java:170)
	at com.alibaba.dubbo.remoting.transport.DecodeHandler.received(DecodeHandler.java:52)
	at com.alibaba.dubbo.remoting.transport.dispatcher.ChannelEventRunnable.run(ChannelEventRunnable.java:82)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)


JAVA 全系列/(旧的隐藏)第八阶段:电商高级项目_架构/编码/电商ego-基于SOA架构_Dubbo使用_逆向工程_分页插件完成商品查询 33289楼
WEB前端全系列/第十九阶段:Vue2知识体系(旧)/Vue基础知识 33291楼

# coding=utf-8
"""
新增功能:
    左上角文字绘制:
    左上角输出敌方坦克的数量6
"""
#导入pygame模块
import pygame
SCREEN_WIDTH=700      #窗口的大小是常量
SCREEN_HEIGHT=500
BG_COLOR=pygame.Color(0,0,0)    #窗口填充色:黑色
TEXT_COLOR=pygame.Color(255,0,0)        #字体颜色;红色
class MainGame():
    window=None     #定义窗口对象,初始化为None,属于类对象
    def __init__(self):
        pass
    #开始游戏
    def startGame(self):
        #加载主窗口
        pygame.display.init()   #初始化窗口(显示窗口)
        #设置窗口的大小及显示
        MainGame.window=pygame.display.set_mode([SCREEN_WIDTH,SCREEN_HEIGHT])
        #窗口大小作为列表传进去,返回一个对象surface,传给窗口对象
        #MainGame.window 调用用类名.类属性
        # 设置窗口标题
        pygame.display.set_caption("坦克大战1.03")
        while True:
            # 给窗口设置填充色,用surface里面的fill方法
            MainGame.window.fill(BG_COLOR)
            #获取事件
            self.getEvent()
            #绘制文字
            MainGame.window.blit(self.getTextSurface("敌方坦克剩余数量%d"%6),(10,10))
            #(10,10)表示小的surface在窗口window中的位置
            pygame.display.update()  # 窗口一直显示
            #点击x窗口关闭不了

    #结束游戏
    def endGame(self):
        print("谢谢使用,欢迎再次使用")
        exit()
    #左上角文字的绘制
    def getTextSurface(self,text):   #text指敌方坦克数量,变化量
        #初始化字体模块
        pygame.font.init()
        #查看所有的字体名称
        #print(pygame.font.get_fonts())
        #获取字体Font对象
        font=pygame.font.SysFont("kaiti",18)
        #绘制文本信息
        textSurface=font.render(text,True,TEXT_COLOR)
        return textSurface

    #获取事件
    def getEvent(self):
        #获取所有事件
        eventList = pygame.event.get()
        #遍历事件
        for event in eventList:
            #判断按下的键是关闭还是键盘按下
            #如果按的是退出,关闭窗口
            if event.type == pygame.QUIT:
                self.endGame()
            #如果是键盘的按下
            if event.type == pygame.KEYDOWN:
                #判断按下的是上、下、左、右
                if event.key == pygame.K_LEFT:
                    print("按下左键,坦克向左移动")
                elif event.key == pygame.K_RIGHT:
                    print("按下右键,坦克向右移动")
                elif event.key == pygame.K_UP:
                    print("按下上键,坦克向上移动")
                elif event.key == pygame.K_DOWN:
                    print("按下下键,坦克向下移动")




class Tank():
    def __init__(self):
        pass
    #移动
    def move(self):
        pass
    #射击
    def shot(self):
        pass
    #展示坦克的方法
    def dispaliTank(self):
        pass
#我方坦克
class MyTank(Tank):
    def __init__(self):
        pass
#敌方坦克
class EnemyTank(Tank):
    def __init__(self):
        pass

class Bullet():
    def __init__(self):
        pass
    #移动类
    def move(self):
        pass
    #展示子弹的方法
    def displayBullet(self):
        pass

class Wall():
    def __init__(self):
        pass
    #展示墙壁的方法
    def displayWall(self):
        pass

class Explode():
    def __init__(self):
        pass
    #展示爆炸的方法
    def displayExplode(self):
        pass

class Music():
    def __init__(self):
        pass
    #播放音乐的方法
    def play(self):
        pass

if __name__=="__main__":
    #MainGame().startGame()       #调用startGame()方法显示窗口对象
    #窗口对象只显示一次就关闭
    MainGame().getTextSurface()


老师,我上面的代码为什么出现以下报错

Traceback (most recent call last):
  File "F:/py/tank/tank05.py", line 134, in <module>
Hello from the pygame community. https://www.pygame.org/contribute.html
    MainGame().getTextSurface()
TypeError: getTextSurface() missing 1 required positional argument: 'text'


Python 全系列/第二阶段:Python 深入与提高/游戏开发-坦克大战 33294楼
JAVA 全系列/第四阶段:网页编程和设计/HTML5(旧) 33295楼
JAVA 全系列/(旧的隐藏)第七阶段:JAVA 高级技术/MyCat 33296楼
Python 全系列/第十三阶段:高并发性能怪兽-Tornado 框架/Tornado 数据库操作(旧) 33297楼
JAVA 全系列/第一阶段:JAVA 快速入门/变量、数据类型、运算符 33298楼
Python 全系列/第二阶段:Python 深入与提高/异常机制 33299楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637