Mapper.xml 中的 update 方法一直报sql语句的错。

Mapper.xml 中的 update 方法一直报sql语句的错。

这是报错信息:
Loading XML bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml]
SQLErrorCodes loaded: [DB2, Derby, H2, HDB, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase]

<update id="update" parameterType="com.pacypay.aliwc.common.domain.PMerInfoDO">
        update P_MER_INFO
        <set>
            <if test="merId != null">MER_ID = #{merId,jdbcType=VARCHAR} </if>
            <if test="brhId != null">BRH_ID = #{brhId,jdbcType=VARCHAR}, </if>
            <if test="merNm != null">MER_NM = #{merNm,jdbcType=VARCHAR}, </if>
            <if test="merShortNm != null">MER_SHORT_NM = #{merShortNm,jdbcType=VARCHAR}, </if>
            <if test="merType != null">MER_TYPE = #{merType,jdbcType=VARCHAR}, </if>
            <if test="holderName != null">HOLDER_NAME = #{holderName,jdbcType=VARCHAR}, </if>
            <if test="idType != null">ID_TYPE = #{idType,jdbcType=VARCHAR}, </if>
            <if test="idNo != null">ID_NO = #{idNo,jdbcType=VARCHAR}, </if>
            <if test="licenceNo != null">LICENCE_NO = #{licenceNo,jdbcType=VARCHAR}, </if>
            <if test="merLevel != null">MER_LEVEL = #{merLevel,jdbcType=VARCHAR}, </if>
            <if test="mccCd != null">MCC_CD = #{mccCd,jdbcType=VARCHAR}, </if>
            <if test="tradeTypeWx != null">TRADE_TYPE_WX = #{tradeTypeWx,jdbcType=VARCHAR}, </if>
            <if test="supMerId != null">SUP_MER_ID = #{supMerId,jdbcType=VARCHAR}, </if>
            <if test="mgrBrhId != null">MGR_BRH_ID = #{mgrBrhId,jdbcType=VARCHAR}, </if>
            <if test="acqBrhId != null">ACQ_BRH_ID = #{acqBrhId,jdbcType=VARCHAR}, </if>
            <if test="locNation != null">LOC_NATION = #{locNation,jdbcType=VARCHAR}, </if>
            <if test="locProv != null">LOC_PROV = #{locProv,jdbcType=VARCHAR}, </if>
            <if test="locCity != null">LOC_CITY = #{locCity,jdbcType=VARCHAR}, </if>
            <if test="locArea != null">LOC_AREA = #{locArea,jdbcType=VARCHAR}, </if>
            <if test="addr != null">ADDR = #{addr,jdbcType=VARCHAR}, </if>
            <if test="contactPerson != null">CONTACT_PERSON = #{contactPerson,jdbcType=VARCHAR}, </if>
            <if test="contactTel != null">CONTACT_TEL = #{contactTel,jdbcType=VARCHAR}, </if>
            <if test="contactEmail != null">CONTACT_EMAIL = #{contactEmail,jdbcType=VARCHAR}, </if>
            <if test="csEmail != null">CS_EMAIL = #{csEmail,jdbcType=VARCHAR}, </if>
            <if test="csTel != null">CS_TEL = #{csTel,jdbcType=VARCHAR}, </if>
            <if test="stlmtLev != null">STLMT_LEV = #{stlmtLev,jdbcType=VARCHAR}, </if>
            <if test="stlmtPeriod != null">STLMT_PERIOD = #{stlmtPeriod,jdbcType=BIGINT}, </if>
            <if test="stlmtPeriodUnit != null">STLMT_PERIOD_UNIT = #{stlmtPeriodUnit,jdbcType=VARCHAR}, </if>
            <if test="stlmtMin != null">STLMT_MIN = #{stlmtMin,jdbcType=VARCHAR}, </if>
            <if test="stlmtPeriodAdvance != null">STLMT_PERIOD_ADVANCE = #{stlmtPeriodAdvance,jdbcType=BIGINT}, </if>
            <if test="stlmtMinAdvance != null">STLMT_MIN_ADVANCE = #{stlmtMinAdvance,jdbcType=VARCHAR}, </if>
            <if test="stlmtApplyFeeAdvance != null">STLMT_APPLY_FEE_ADVANCE = #{stlmtApplyFeeAdvance,jdbcType=VARCHAR}, </if>
            <if test="stlmtRemark != null">STLMT_REMARK = #{stlmtRemark,jdbcType=VARCHAR}, </if>
            <if test="currency != null">CURRENCY = #{currency,jdbcType=VARCHAR}, </if>
            <if test="inAcctId != null">IN_ACCT_ID = #{inAcctId,jdbcType=VARCHAR}, </if>
            <if test="inAcctNm != null">IN_ACCT_NM = #{inAcctNm,jdbcType=VARCHAR}, </if>
            <if test="inAcctType != null">IN_ACCT_TYPE = #{inAcctType,jdbcType=VARCHAR}, </if>
            <if test="openBankId != null">OPEN_BANK_ID = #{openBankId,jdbcType=VARCHAR}, </if>
            <if test="openBankNm != null">OPEN_BANK_NM = #{openBankNm,jdbcType=VARCHAR}, </if>
            <if test="sta != null">STA = #{sta,jdbcType=VARCHAR}, </if>
            <if test="chkSta != null">CHK_STA = #{chkSta,jdbcType=VARCHAR}, </if>
            <if test="crtDt != null">CRT_DT = #{crtDt,jdbcType=VARCHAR}, </if>
            <if test="lastUpdBrhId != null">LAST_UPD_BRH_ID = #{lastUpdBrhId,jdbcType=VARCHAR}, </if>
            <if test="lastUpdOprId != null">LAST_UPD_OPR_ID = #{lastUpdOprId,jdbcType=VARCHAR}, </if>
            <if test="lastUpdTs != null">LAST_UPD_TS = #{lastUpdTs,jdbcType=TIMESTAMP}, </if>
            <if test="rejectMsg != null">REJECT_MSG = #{rejectMsg,jdbcType=VARCHAR}, </if>
            <if test="smsCheck != null">SMS_CHECK = #{smsCheck,jdbcType=VARCHAR}, </if>
            <if test="logoFileId != null">LOGO_FILE_ID = #{logoFileId,jdbcType=BIGINT}, </if>
            <if test="qrcodeFixedAmt != null">QRCODE_FIXED_AMT = #{qrcodeFixedAmt,jdbcType=VARCHAR}, </if>
            <if test="qrcodeFixedAmtFlg != null">QRCODE_FIXED_AMT_FLG = #{qrcodeFixedAmtFlg,jdbcType=VARCHAR}, </if>
            <if test="feeRateFlag != null">FEE_RATE_FLAG = #{feeRateFlag,jdbcType=VARCHAR}, </if>
            <if test="checkTimestamp != null">CHECK_TIMESTAMP = #{checkTimestamp,jdbcType=TIMESTAMP}, </if>
            <if test="checkOperator != null">CHECK_OPERATOR = #{checkOperator,jdbcType=VARCHAR}, </if>
            <if test="placeholder1Fileid != null">PLACEHOLDER_1_FILEID = #{placeholder1Fileid,jdbcType=BIGINT}, </if>
            <if test="placeholder2Fileid != null">PLACEHOLDER_2_FILEID = #{placeholder2Fileid,jdbcType=BIGINT}, </if>
            <if test="placeholder3Fileid != null">PLACEHOLDER_3_FILEID = #{placeholder3Fileid,jdbcType=BIGINT}, </if>
            <if test="placeholder4Fileid != null">PLACEHOLDER_4_FILEID = #{placeholder4Fileid,jdbcType=BIGINT}, </if>
            <if test="placeholder5Fileid != null">PLACEHOLDER_5_FILEID = #{placeholder5Fileid,jdbcType=BIGINT}, </if>
            <if test="placeholder6Fileid != null">PLACEHOLDER_6_FILEID = #{placeholder6Fileid,jdbcType=BIGINT}, </if>
            <if test="placeholder7Fileid != null">PLACEHOLDER_7_FILEID = #{placeholder7Fileid,jdbcType=BIGINT}, </if>
            <if test="agentSetTbank != null">AGENT_SET_TBANK = #{agentSetTbank,jdbcType=VARCHAR}, </if>
            <if test="licenceExpiration != null">LICENCE_EXPIRATION = #{licenceExpiration,jdbcType=VARCHAR}, </if>
            <if test="refundMark != null">REFUND_MARK = #{refundMark,jdbcType=VARCHAR}, </if>
            <if test="txnInfoType != null">TXN_INFO_TYPE = #{txnInfoType,jdbcType=VARCHAR}, </if>
            <if test="idExpiration != null">ID_EXPIRATION = #{idExpiration,jdbcType=VARCHAR}, </if>
            <if test="refundFeeMark != null">REFUND_FEE_MARK = #{refundFeeMark,jdbcType=VARCHAR}, </if>
            <if test="itsChnlidAlipay != null">ITS_CHNLID_ALIPAY = #{itsChnlidAlipay,jdbcType=VARCHAR}, </if>
            <if test="itsChnlidWechat != null">ITS_CHNLID_WECHAT = #{itsChnlidWechat,jdbcType=VARCHAR}</if>
            <if test="storeType != null">STORE_TYPE = #{storeType,jdbcType=VARCHAR}, </if>
            <if test="storeSupMerId != null">STORE_SUP_MER_ID = #{storeSupMerId,jdbcType=VARCHAR}</if>
        </set>
        where MER_ID = #{merId}
    </update>
这是实体
//商户号
    private String merId;
    //机构号
    private String brhId;
    //商户名称
    private String merNm;
    //商户简称
    private String merShortNm;
    //商户属性
    private String merType;
    //法人姓名
    private String holderName;
    //证件类型
    private String idType;
    //证件编号
    private String idNo;
    //营业执照编号
    private String licenceNo;
    //商户级别
    private String merLevel;
    //MCC
    private String mccCd;
    //微信经营类目
    private String tradeTypeWx;
    //上级商户号
    private String supMerId;
    //$column.comments
    private String mgrBrhId;
    //机构号
    private String acqBrhId;
    //国家
    private String locNation;
    //省
    private String locProv;
    //市
    private String locCity;
    //区
    private String locArea;
    //详细地址
    private String addr;
    //联系人
    private String contactPerson;
    //联系电话
    private String contactTel;
    //联系邮箱
    private String contactEmail;
    //客服邮箱
    private String csEmail;
    //客服电话
    private String csTel;
    //结算级别
    private String stlmtLev;
    //结算周期
    private Long stlmtPeriod;
    //结算周期参数
    private String stlmtPeriodUnit;
    //起始结算金额
    private String stlmtMin;
    //提前结算周期
    private Long stlmtPeriodAdvance;
    //提前结算最小金额
    private String stlmtMinAdvance;
    //提前结算手续费
    private String stlmtApplyFeeAdvance;
    //stlmt remark
    private String stlmtRemark;
    //币种
    private String currency;
    //结算卡号
    private String inAcctId;
    //结算户名
    private String inAcctNm;
    //结算卡类型
    private String inAcctType;
    //开户行号
    private String openBankId;
    //开户行名
    private String openBankNm;
    //状态
    private String sta;
    //审核状态
    private String chkSta;
    //创建日期
    private String crtDt;
    //最后更新机构号
    private String lastUpdBrhId;
    //最后更新操作员
    private String lastUpdOprId;
    //最后更新时间
//    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date lastUpdTs;
    //审核拒绝原因
    private String rejectMsg;
    //$column.comments 机构号(+1)
    private String smsCheck;
    //logo
    private Long logoFileId;
    //码牌固定金额
    private String qrcodeFixedAmt;
    //码牌固定金额标识
    private String qrcodeFixedAmtFlg;
    //费率标识
    private String feeRateFlag;
    //审核时间
//    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date checkTimestamp;
    //审核操作员
    private String checkOperator;
    //文件一
    private Long placeholder1Fileid;
    //文件二
    private Long placeholder2Fileid;
    //文件三
    private Long placeholder3Fileid;
    //文件四
    private Long placeholder4Fileid;
    //文件五
    private Long placeholder5Fileid;
    //文件六
    private Long placeholder6Fileid;
    //文件七
    private Long placeholder7Fileid;
    //代理结算银行
    private String agentSetTbank;
    //营业执照过期时间
    private String licenceExpiration;
    //退款标识
    private String refundMark;
    //商户(交易)类型
    private String txnInfoType;
    //身份证过期时间
    private String idExpiration;
    //退款标识
    private String refundFeeMark;
    //支付宝渠道编号
    private String itsChnlidAlipay;
    //微信渠道编号
    private String itsChnlidWechat;
    //店铺类型
    private String storeType;
    //店铺所属客户
    private String storeSupMerId;

2个回答

建议将你的方法上的try-catch捕获异常,自定义异常信息抛掉,在控制台打印出真正的异常信息。从而判断出错误处在哪里。
你的开始

<if test="merId != null">MER_ID = #{merId,jdbcType=VARCHAR} </if>
```   /if前面是不是少了个逗号。
dl521357
稷下学宫榆树 谢了,已经解决了
2 个月之前 回复

第一个插入语句后面没有逗号,而后面中间又有一些没有。正常的来说,应该每一个都需要加的,set if 会智能去掉最后一个逗号的。

dl521357
稷下学宫榆树 谢了,已经解决了
2 个月之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
Spring mvc 中的mapper.xml的SQL语句报错
### Error updating database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'interval=2,conn_timeout=1,resp_timeout=1,test_retry=1,freq=2,monit_conn_timeout=' at line 1 ### The error may involve com.security.dao.TemplateNetworkDao.updateTempNetwork-Inline ### The error occurred while setting parameters ### SQL: update conf_template_network set interval=?,conn_timeout=?,resp_timeout=?,test_retry=?,freq=?,monit_conn_timeout=?,monit_resp_timeout=?,monit_retry=? where id=? ### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'interval=2,conn_timeout=1,resp_timeout=1,test_retry=1,freq=2,monit_conn_timeout=' at line 1 ; bad SQL grammar []; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'interval=2,conn_timeout=1,resp_timeout=1,test_retry=1,freq=2,monit_conn_timeout=' at line 1_ 我的SQL语句是 ``` <update id="updateTempNetwork" parameterType="int"> update conf_template_network set interval=#{interval},conn_timeout=#{conn_timeout},resp_timeout=#{resp_timeout},test_retry=#{test_retry},freq=#{freq},monit_conn_timeout=#{monit_conn_timeout},monit_resp_timeout=#{monit_resp_timeout},monit_retry=#{monit_retry} where id=#{id} </update> ``` 找了半天也没找到哪写错了,而且也没有使用mysql的关键字,提示说monit_conn_timeout附近的错误 # ## ——————————————————————————————————** # ## 更新:好像是SQL语句太长了,把前边的字段改短后,前边的字段就能正确显示,但是后边超出长度的部分还是会报错 我把前边长的字段用a,b替代之后,变短了: ``` <update id="updateTempNetwork" parameterType="com.security.entity.TemplateNetwork"> update conf_template_network set interval=#{interval},conn_timeout=#{conn_timeout},resp_timeout=#{resp_timeout},test_retry=#{test_retry},freq=#{freq},a=#{a},b=#{b},monit_retry=#{monit_retry} where id=#{id} </update> ``` 错误就移到了后边: Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'interval=3,conn_timeout=3,resp_timeout=3,test_retry=3,freq=1,a=2,b=1,monit_retry' at line 1 ; bad SQL grammar []; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'interval=3,conn_timeout=3,resp_timeout=3,test_retry=3,freq=1,a=2,b=1,monit_retry' at line 1 好像跟长度又没关系 把后边的字段都砍掉了之后 ``` <update id="updateTempNetwork" parameterType="com.security.entity.TemplateNetwork"> update conf_template_network set interval=#{interval},conn_timeout=#{conn_timeout},resp_timeout=#{resp_timeout},test_retry=#{test_retry},freq=#{freq} where id=#{id} </update> ``` 还是会报错: 移到了最后: ### SQL: update conf_template_network set interval=?,conn_timeout=?,resp_timeout=?,test_retry=?,freq=? where id=? ### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'interval=1,conn_timeout=2,resp_timeout=2,test_retry=1,freq=1 where id=1' at line 1 ; bad SQL grammar []; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'interval=1,conn_timeout=2,resp_timeout=2,test_retry=1,freq=1 where id=1' at line 1 at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:231) at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73) at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:73) at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446) at $Proxy29.update(Unknown Source) at org.mybatis.spring.SqlSessionTemplate.update(SqlSessionTemplate.java:294) at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:62) at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59) at $Proxy37.updateTempNetwork(Unknown Source) at com.security.service.impl.TemplateNetworkImpl.updateTempNetwork(TemplateNetworkImpl.java:35) at com.security.service.impl.TemplateNetworkImpl$$FastClassBySpringCGLIB$$16455d80.invoke(<generated>) at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:738) 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.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:673) at com.security.service.impl.TemplateNetworkImpl$$EnhancerBySpringCGLIB$$a87fea1.updateTempNetwork(<generated>) at com.security.controller.TemplateNetworkController.updateTempNetwork(TemplateNetworkController.java:47) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:97) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738) at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:967) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872) at javax.servlet.http.HttpServlet.service(HttpServlet.java:646) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) at javax.servlet.http.HttpServlet.service(HttpServlet.java:727) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449) at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365) at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90) at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83) at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383) at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362) at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125) at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346) at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.logging.log4j.web.Log4jServletFilter.doFilter(Log4jServletFilter.java:71) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Unknown Source) Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'interval=1,conn_timeout=2,resp_timeout=2,test_retry=1,freq=1 where id=1' at line 1 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at com.mysql.jdbc.Util.handleNewInstance(Util.java:408) at com.mysql.jdbc.Util.getInstance(Util.java:383) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1062) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4226) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4158) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2615) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2776) at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2840) at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2082) at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1302) at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.execute(NewProxyPreparedStatement.java:67) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.java:59) at $Proxy48.execute(Unknown Source) at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:46) at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:74) at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:50) at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117) at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:76) at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:198) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:433) # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # 结贴啦结帖啦! # 休息两天果然脑细胞就活过来了,周一一大早就找到了bug # interval是mySQL的关键字,用作变量名,所以报错了,换个名字就好了。已经是第二次撞到关键字了,以后起变量名要小心了。 # 非常感谢各位的帮助!!
Mybatis小练习 报错 求大神指导,信息详尽
# UserMapper ``` public interface UserMapper { //根据id查询用户信息 public User findUserById(int id) throws Exception; //根据用户名列查询用户列表 public List<User> findUserByName(String name)throws Exception; //插入用户 public void insertUser(User user)throws Exception; } ``` # UserMapper.xml ``` <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!-- namespace命名空间,作用就是对sql进行分类化管理,理解sql隔离 注意:使用mapper代理方法开发,namespace有特殊重要的作用,namespace等于mapper接口地址 --> <mapper namespace="com.neuedu.mapper.UserMapper"> <!-- 在 映射文件中配置很多sql语句 --> <!-- 需求:通过id查询用户表的记录 --> <!-- 通过 select执行数据库查询 id:标识 映射文件中的 sql 将sql语句封装到mappedStatement对象中,所以将id称为statement的id parameterType:指定输入 参数的类型,这里指定int型 #{}表示一个占位符号 #{id}:其中的id表示接收输入 的参数,参数名称就是id,如果输入 参数是简单类型,#{}中的参数名可以任意,可以value或其它名称 resultType:指定sql输出结果 的所映射的java对象类型,select指定resultType表示将单条记录映射成的java对象。 --> <select id="findUserById" parameterType="int" resultType="user"> SELECT * FROM user WHERE id=#{value} </select> <!-- 根据用户名称模糊查询用户信息,可能返回多条 resultType:指定就是单条记录所映射的java对象 类型 ${}:表示拼接sql串,将接收到参数的内容不加任何修饰拼接在sql中。 使用${}拼接sql,引起 sql注入 ${value}:接收输入 参数的内容,如果传入类型是简单类型,${}中只能使用value --> <select id="findUserByName" parameterType="java.lang.String" resultType="com.neuedu.pojo.User"> SELECT * FROM user WHERE username LIKE '%${value}%' </select> <!-- 添加用户 parameterType:指定输入 参数类型是pojo(包括 用户信息) #{}中指定pojo的属性名,接收到pojo对象的属性值,mybatis通过OGNL获取对象的属性值 --> <insert id="insertUser" parameterType="com.neuedu.pojo.User"> <!-- 将插入数据的主键返回,返回到user对象中 SELECT LAST_INSERT_ID():得到刚insert进去记录的主键值,只适用与自增主键 keyProperty:将查询到主键值设置到parameterType指定的对象的哪个属性 order:SELECT LAST_INSERT_ID()执行顺序,相对于insert语句来说它的执行顺序 resultType:指定SELECT LAST_INSERT_ID()的结果类型 --> insert into user(id,username,birthday,sex,address) values (seq_user.nextval,#{username},#{birthday},#{sex},#{address}) <!-- 插入数据后,返回自动增长列的ID值,将sql语句的返回值赋给parameterType绑定对象的ID属性 MySQL中使用: select LAST_INSERT_ID() --> <selectKey keyProperty="id" order="AFTER" resultType="int"> SELECT LAST_INSERT_ID() <!--select seq_user.currval from dual--> </selectKey> <!-- 使用mysql的uuid()生成主键 执行过程: 首先通过uuid()得到主键,将主键设置到user对象的id属性中 其次在insert执行时,从user对象中取出id属性值 --> <!-- <selectKey keyProperty="id" order="BEFORE" resultType="java.lang.String"> SELECT uuid() </selectKey> insert into user(id,username,birthday,sex,address) value(#{id},#{username},#{birthday},#{sex},#{address}) --> </insert> <!-- 删除 用户 根据id删除用户,需要输入 id值 --> <delete id="deleteUser" parameterType="java.lang.Integer"> delete from user where id=#{id} </delete> <!-- 根据id更新用户 分析: 需要传入用户的id 需要传入用户的更新信息 parameterType指定user对象,包括 id和更新信息,注意:id必须存在 #{id}:从输入 user对象中获取id属性值 --> <update id="updateUser" parameterType="com.neuedu.pojo.User"> update user set username=#{username},birthday=#{birthday},sex=#{sex},address=#{address} where id=#{id} </update> </mapper> ``` # Tset ``` public class UserMapperTest { private SqlSessionFactory sqlSessionFactory; // 此方法是在执行testFindUserById之前执行 @Before public void setUp() throws Exception { // 创建sqlSessionFactory // mybatis配置文件 String resource = "config/SqlMapConfig.xml"; // 得到配置文件流 InputStream inputStream = Resources.getResourceAsStream(resource); // 创建会话工厂,传入mybatis的配置文件信息 sqlSessionFactory = new SqlSessionFactoryBuilder() .build(inputStream); } @Test public void testFindUserById() throws Exception { SqlSession sqlSession = sqlSessionFactory.openSession(); //创建UserMapper对象,mybatis自动生成mapper代理对象 UserMapper userMapper = sqlSession.getMapper(UserMapper.class); //调用userMapper的方法 User user = userMapper.findUserById(1); System.out.println(user); } @Test public void testFindUserByName() throws Exception { SqlSession sqlSession = sqlSessionFactory.openSession(); //创建UserMapper对象,mybatis自动生成mapper代理对象 UserMapper userMapper = sqlSession.getMapper(UserMapper.class); //调用userMapper的方法 List<User> list = userMapper.findUserByName("袁超"); sqlSession.close(); System.out.println(list); } } ``` # 报错信息 ``` DEBUG [main] - Logging initialized using 'class org.apache.ibatis.logging.slf4j.Slf4jImpl' adapter. DEBUG [main] - Class not found: org.jboss.vfs.VFS DEBUG [main] - JBoss 6 VFS API is not available in this environment. DEBUG [main] - Class not found: org.jboss.vfs.VirtualFile DEBUG [main] - VFS implementation org.apache.ibatis.io.JBoss6VFS is not valid in this environment. DEBUG [main] - Using VFS adapter org.apache.ibatis.io.DefaultVFS DEBUG [main] - Find JAR URL: file:/C:/Users/95638/Desktop/mybatis/ch02-mybatis01/ch02-mybatis01/target/classes/com/neuedu/pojo DEBUG [main] - Not a JAR: file:/C:/Users/95638/Desktop/mybatis/ch02-mybatis01/ch02-mybatis01/target/classes/com/neuedu/pojo DEBUG [main] - Reader entry: User.class DEBUG [main] - Listing file:/C:/Users/95638/Desktop/mybatis/ch02-mybatis01/ch02-mybatis01/target/classes/com/neuedu/pojo DEBUG [main] - Find JAR URL: file:/C:/Users/95638/Desktop/mybatis/ch02-mybatis01/ch02-mybatis01/target/classes/com/neuedu/pojo/User.class DEBUG [main] - Not a JAR: file:/C:/Users/95638/Desktop/mybatis/ch02-mybatis01/ch02-mybatis01/target/classes/com/neuedu/pojo/User.class DEBUG [main] - Reader entry: ���� 1 N DEBUG [main] - Checking to see if class com.neuedu.pojo.User matches criteria [is assignable to Object] DEBUG [main] - PooledDataSource forcefully closed/removed all connections. DEBUG [main] - PooledDataSource forcefully closed/removed all connections. DEBUG [main] - PooledDataSource forcefully closed/removed all connections. DEBUG [main] - PooledDataSource forcefully closed/removed all connections. DEBUG [main] - Find JAR URL: file:/C:/Users/95638/Desktop/mybatis/ch02-mybatis01/ch02-mybatis01/target/test-classes/com/neuedu/mapper DEBUG [main] - Not a JAR: file:/C:/Users/95638/Desktop/mybatis/ch02-mybatis01/ch02-mybatis01/target/test-classes/com/neuedu/mapper DEBUG [main] - Reader entry: UserMapperTest.class DEBUG [main] - Listing file:/C:/Users/95638/Desktop/mybatis/ch02-mybatis01/ch02-mybatis01/target/test-classes/com/neuedu/mapper DEBUG [main] - Find JAR URL: file:/C:/Users/95638/Desktop/mybatis/ch02-mybatis01/ch02-mybatis01/target/test-classes/com/neuedu/mapper/UserMapperTest.class DEBUG [main] - Not a JAR: file:/C:/Users/95638/Desktop/mybatis/ch02-mybatis01/ch02-mybatis01/target/test-classes/com/neuedu/mapper/UserMapperTest.class DEBUG [main] - Reader entry: ���� 1 a DEBUG [main] - Find JAR URL: file:/C:/Users/95638/Desktop/mybatis/ch02-mybatis01/ch02-mybatis01/target/classes/com/neuedu/mapper DEBUG [main] - Not a JAR: file:/C:/Users/95638/Desktop/mybatis/ch02-mybatis01/ch02-mybatis01/target/classes/com/neuedu/mapper DEBUG [main] - Reader entry: UserMapper.class DEBUG [main] - Reader entry: UserMapper.xml DEBUG [main] - Listing file:/C:/Users/95638/Desktop/mybatis/ch02-mybatis01/ch02-mybatis01/target/classes/com/neuedu/mapper DEBUG [main] - Find JAR URL: file:/C:/Users/95638/Desktop/mybatis/ch02-mybatis01/ch02-mybatis01/target/classes/com/neuedu/mapper/UserMapper.class DEBUG [main] - Not a JAR: file:/C:/Users/95638/Desktop/mybatis/ch02-mybatis01/ch02-mybatis01/target/classes/com/neuedu/mapper/UserMapper.class DEBUG [main] - Reader entry: ���� 1    findUserById (I)Lcom/neuedu/pojo/User; DEBUG [main] - Find JAR URL: file:/C:/Users/95638/Desktop/mybatis/ch02-mybatis01/ch02-mybatis01/target/classes/com/neuedu/mapper/UserMapper.xml DEBUG [main] - Not a JAR: file:/C:/Users/95638/Desktop/mybatis/ch02-mybatis01/ch02-mybatis01/target/classes/com/neuedu/mapper/UserMapper.xml DEBUG [main] - Reader entry: <?xml version="1.0" encoding="UTF-8" ?> DEBUG [main] - Checking to see if class com.neuedu.mapper.UserMapperTest matches criteria [is assignable to Object] DEBUG [main] - Checking to see if class com.neuedu.mapper.UserMapper matches criteria [is assignable to Object] DEBUG [main] - Opening JDBC Connection DEBUG [main] - Created connection 209833425. DEBUG [main] - Setting autocommit to false on JDBC Connection [com.mysql.jdbc.JDBC4Connection@c81cdd1] DEBUG [main] - ==> Preparing: SELECT * FROM T_USER WHERE username LIKE '%袁超%' DEBUG [main] - ==> Parameters: org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'mybatis.t_user' doesn't exist ### The error may exist in com/neuedu/mapper/UserMapper.xml ### The error may involve com.neuedu.mapper.UserMapper.findUserByName-Inline ### The error occurred while setting parameters ### SQL: SELECT * FROM T_USER WHERE username LIKE '%袁超%' ### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'mybatis.t_user' doesn't exist at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:150) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141) at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:137) at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:75) at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59) at com.sun.proxy.$Proxy3.findUserByName(Unknown Source) at com.neuedu.mapper.UserMapperTest.testFindUserByName(UserMapperTest.java:68) 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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) at org.junit.runners.ParentRunner.run(ParentRunner.java:309) at org.junit.runner.JUnitCore.run(JUnitCore.java:160) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68) at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70) Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'mybatis.t_user' doesn't exist at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at com.mysql.jdbc.Util.handleNewInstance(Util.java:400) at com.mysql.jdbc.Util.getInstance(Util.java:383) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:980) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3847) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3783) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2447) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2594) at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2545) at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1901) at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1193) 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.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.java:59) at com.sun.proxy.$Proxy5.execute(Unknown Source) at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:63) at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:79) at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:63) at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:324) at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156) at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109) at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:83) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:148) ... 29 more ``` # SqlMapConfig.xml ``` <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> <!-- 加载属性文件 --> <properties resource="db.properties"> <!--properties中还可以配置一些属性名和属性值 --> <!-- <property name="jdbc.driver" value=""/> --> </properties> <!-- 全局配置参数,需要时再设置 --> <!-- <settings> </settings> --> <!-- 别名定义 --> <typeAliases> <!-- 针对单个别名定义 type:类型的路径 alias:别名 --> <!-- <typeAlias type="com.neuedu.mybatis.po.User" alias="user"/> --> <!-- 批量别名定义 指定包名,mybatis自动扫描包中的po类,自动定义别名,别名就是类名(首字母大写或小写都可以) --> <package name="com.neuedu.pojo"/> </typeAliases> <!-- 和spring整合后 environments配置将废除--> <environments default="development"> <environment id="development"> <!-- 使用jdbc事务管理,事务控制由mybatis--> <transactionManager type="JDBC" /> <!-- 数据库连接池,由mybatis管理--> <dataSource type="POOLED"> <property name="driver" value="${jdbc.driver}" /> <property name="url" value="${jdbc.url}" /> <property name="username" value="${jdbc.username}" /> <property name="password" value="${jdbc.password}" /> </dataSource> </environment> </environments> <!-- 加载 映射文件 --> <mappers> <mapper resource="sqlmap/User.xml"/> <!--通过resource方法一次加载一个映射文件 --> <!-- <mapper resource="sqlmap/User.xml"/> --> <!-- 通过mapper接口加载单个 映射文件 遵循一些规范:需要将mapper接口类名和mapper.xml映射文件名称保持一致,且在一个目录 中 上边规范的前提是:使用的是mapper代理方法 --> <!-- <mapper class="com.neuedu.mapper.UserMapper"/> --> <!-- 批量加载mapper 指定mapper接口的包名,mybatis自动扫描包下边所有mapper接口进行加载 遵循一些规范:需要将mapper接口类名和mapper.xml映射文件名称保持一致,且在一个目录 中 上边规范的前提是:使用的是mapper代理方法 --> <package name="com.neuedu.mapper"/> </mappers> </configuration> ``` # User ``` public class User { //属性名和数据库表的字段对应 private int id; private String username;// 用户姓名 private String sex;// 性别 private Date birthday;// 生日 private String address;// 地址 public int getId() { return id; } public void setId(int id) { this.id = id; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getSex() { return sex; } public void setSex(String sex) { this.sex = sex; } public Date getBirthday() { return birthday; } public void setBirthday(Date birthday) { this.birthday = birthday; } public String getAddress() { return address; } public void setAddress(String address) { this.address = address; } @Override public String toString() { return "User [id=" + id + ", username=" + username + ", sex=" + sex + ", birthday=" + birthday + ", address=" + address + "]"; } } ``` 也不知道为什么,明明已经在UserMapper.xml里面把表名改了,但是报错信息里查找的还是T-user表 求大神指导!感恩! # 问题已解决 在maven文件里加上下面的代码 ``` <resources> <resource> <directory>src/main/java</directory> <includes> <include>**/*Mapper.xml</include> </includes> </resource> </resources> ```
javaweb小项目,写添加功能时出错了检查了几遍sql没找到错误,但从报错信息来看是sql写错了?
在写emp这张表的添加功能时遇到错误了,但是找不到解决的办法。。。。 sql语句检查好几遍了,也找不到是哪里错了。 下面是图和错误信息。 ![图片说明](https://img-ask.csdn.net/upload/201912/09/1575894627_921952.png)![图片说明](https://img-ask.csdn.net/upload/201912/09/1575894635_586062.png)![图片说明](https://img-ask.csdn.net/upload/201912/09/1575894640_845708.png)![图片说明](https://img-ask.csdn.net/upload/201912/09/1575894648_593949.png)![图片说明](https://img-ask.csdn.net/upload/201912/09/1575894656_691023.png)![图片说明](https://img-ask.csdn.net/upload/201912/09/1575894666_634817.png)![图片说明](https://img-ask.csdn.net/upload/201912/09/1575894683_320059.png)![图片说明](https://img-ask.csdn.net/upload/201912/09/1575894687_712206.png)![图片说明](https://img-ask.csdn.net/upload/201912/09/1575894695_287559.png)![图片说明](https://img-ask.csdn.net/upload/201912/09/1575894700_310688.png) 错误信息:在表单页面点击立即提交就报错 ``` [2019-12-09 08:10:13,721] Artifact 人事工资管理系统(psms):war exploded: Artifact is being deployed, please wait... 09-Dec-2019 20:10:14.925 信息 [RMI TCP Connection(3)-127.0.0.1] org.apache.jasper.servlet.TldScanner.scanJars 至少有一个JAR被扫描用于TLD但尚未包含TLD。 为此记录器启用调试日志记录,以获取已扫描但未在其中找到TLD的完整JAR列表。 在扫描期间跳过不需要的JAR可以缩短启动时间和JSP编译时间。 [2019-12-09 08:10:15,033] Artifact 人事工资管理系统(psms):war exploded: Artifact is deployed successfully [2019-12-09 08:10:15,033] Artifact 人事工资管理系统(psms):war exploded: Deploy took 1,312 milliseconds DEBUG [http-nio-555-exec-5] - Logging initialized using 'class org.apache.ibatis.logging.log4j.Log4jImpl' adapter. DEBUG [http-nio-555-exec-5] - PooledDataSource forcefully closed/removed all connections. DEBUG [http-nio-555-exec-5] - PooledDataSource forcefully closed/removed all connections. DEBUG [http-nio-555-exec-5] - PooledDataSource forcefully closed/removed all connections. DEBUG [http-nio-555-exec-5] - PooledDataSource forcefully closed/removed all connections. DEBUG [http-nio-555-exec-5] - Opening JDBC Connection DEBUG [http-nio-555-exec-5] - Created connection 1428244206. DEBUG [http-nio-555-exec-5] - Setting autocommit to false on JDBC Connection [com.mysql.jdbc.JDBC4Connection@552146ee] DEBUG [http-nio-555-exec-5] - ==> Preparing: select * from emp where username=? and password=? DEBUG [http-nio-555-exec-5] - ==> Parameters: root(String), aias(String) DEBUG [http-nio-555-exec-5] - <== Total: 1 DEBUG [http-nio-555-exec-5] - Resetting autocommit to true on JDBC Connection [com.mysql.jdbc.JDBC4Connection@552146ee] DEBUG [http-nio-555-exec-5] - Closing JDBC Connection [com.mysql.jdbc.JDBC4Connection@552146ee] DEBUG [http-nio-555-exec-5] - Returned connection 1428244206 to pool. 09-Dec-2019 20:10:23.398 信息 [Catalina-utility-1] org.apache.catalina.startup.HostConfig.deployDirectory 把web 应用程序部署到目录 [C:\apache-tomcat-9.0.27-windows-x64\apache-tomcat-9.0.27\webapps\manager] 09-Dec-2019 20:10:23.482 信息 [Catalina-utility-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [C:\apache-tomcat-9.0.27-windows-x64\apache-tomcat-9.0.27\webapps\manager] has finished in [83] ms DEBUG [http-nio-555-exec-10] - Opening JDBC Connection DEBUG [http-nio-555-exec-10] - Checked out connection 1428244206 from pool. DEBUG [http-nio-555-exec-10] - Setting autocommit to false on JDBC Connection [com.mysql.jdbc.JDBC4Connection@552146ee] DEBUG [http-nio-555-exec-10] - ==> Preparing: select max(id) from emp DEBUG [http-nio-555-exec-10] - ==> Parameters: DEBUG [http-nio-555-exec-10] - <== Total: 1 DEBUG [http-nio-555-exec-10] - Resetting autocommit to true on JDBC Connection [com.mysql.jdbc.JDBC4Connection@552146ee] DEBUG [http-nio-555-exec-10] - Closing JDBC Connection [com.mysql.jdbc.JDBC4Connection@552146ee] DEBUG [http-nio-555-exec-10] - Returned connection 1428244206 to pool. DEBUG [http-nio-555-exec-10] - Opening JDBC Connection DEBUG [http-nio-555-exec-10] - Checked out connection 1428244206 from pool. DEBUG [http-nio-555-exec-10] - Setting autocommit to false on JDBC Connection [com.mysql.jdbc.JDBC4Connection@552146ee] DEBUG [http-nio-555-exec-10] - ==> Preparing: insert into emp(id,empno,username,password,ename,sex,birthday,email,call,pname,deptno,state,permissions) values (?,?,?,?,?,?,?,?,?,?,?,?,?) DEBUG [http-nio-555-exec-10] - ==> Parameters: 28(Integer), 028(String), test(String), test(String), 测试(String), 男(String), 2019-12-09(String), 777777777@qq.com(String), 11111111111(String), 接待员(String), 001(String), 在职(String), 普通员工(String) java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) DEBUG [http-nio-555-exec-10] - Rolling back JDBC Connection [com.mysql.jdbc.JDBC4Connection@552146ee] at java.lang.reflect.Method.invoke(Method.java:498) DEBUG [http-nio-555-exec-10] - Resetting autocommit to true on JDBC Connection [com.mysql.jdbc.JDBC4Connection@552146ee] DEBUG [http-nio-555-exec-10] - Closing JDBC Connection [com.mysql.jdbc.JDBC4Connection@552146ee] at com.cdx.psms.utils.TransactionInvocationHandler.invoke(TransactionInvocationHandler.java:30) DEBUG [http-nio-555-exec-10] - Returned connection 1428244206 to pool. at com.sun.proxy.$Proxy5.add(Unknown Source) at com.cdx.psms.controller.Emp_InsertAddServlet.doPost(Emp_InsertAddServlet.java:46) at javax.servlet.http.HttpServlet.service(HttpServlet.java:660) at javax.servlet.http.HttpServlet.service(HttpServlet.java:741) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:526) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:678) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:861) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1579) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:748) Caused by: org.apache.ibatis.exceptions.PersistenceException: ### Error updating database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'call,pname,deptno,state,permissions) values (28,'028','test','te' at line 2 ### The error may exist in com/cdx/psms/mapper/EmpMapper.xml ### The error may involve emp.add-Inline ### The error occurred while setting parameters ### SQL: insert into emp(id,empno,username,password,ename,sex,birthday,email,call,pname,deptno,state,permissions) values (?,?,?,?,?,?,?,?,?,?,?,?,?) ### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'call,pname,deptno,state,permissions) values (28,'028','test','te' at line 2 at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30) at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:199) at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:184) at com.cdx.psms.dao.EmpDaoImpl.add(EmpDaoImpl.java:42) at com.cdx.psms.service.EmpServiceImpl.add(EmpServiceImpl.java:26) ... 31 more Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'call,pname,deptno,state,permissions) values (28,'028','test','te' at line 2 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at com.mysql.jdbc.Util.handleNewInstance(Util.java:425) at com.mysql.jdbc.Util.getInstance(Util.java:408) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:944) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3933) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3869) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2524) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2675) at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2465) at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1912) at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1251) 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.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.java:59) at com.sun.proxy.$Proxy7.execute(Unknown Source) at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:47) at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:74) at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:50) at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117) at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:76) at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:197) ... 34 more ```
使用mybatis遇到的奇葩错误
``` java.lang.ClassFormatError: Method "setString" in class sun/reflect/GeneratedMethodAccessor5 has illegal signature "(IPjava/lang/String;)V" at sun.misc.Unsafe.defineClass(Native Method) at sun.reflect.ClassDefiner.defineClass(Unknown Source) at sun.reflect.MethodAccessorGenerator$1.run(Unknown Source) at sun.reflect.MethodAccessorGenerator$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at sun.reflect.MethodAccessorGenerator.generate(Unknown Source) at sun.reflect.MethodAccessorGenerator.generateMethod(Unknown Source) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.java:53) at com.sun.proxy.$Proxy26.setString(Unknown Source) at org.apache.ibatis.type.StringTypeHandler.setNonNullParameter(StringTypeHandler.java:12) at org.apache.ibatis.type.StringTypeHandler.setNonNullParameter(StringTypeHandler.java:8) at org.apache.ibatis.type.BaseTypeHandler.setParameter(BaseTypeHandler.java:23) at org.apache.ibatis.type.UnknownTypeHandler.setNonNullParameter(UnknownTypeHandler.java:21) at org.apache.ibatis.type.BaseTypeHandler.setParameter(BaseTypeHandler.java:23) at org.apache.ibatis.executor.parameter.DefaultParameterHandler.setParameters(DefaultParameterHandler.java:73) at org.apache.ibatis.executor.statement.PreparedStatementHandler.parameterize(PreparedStatementHandler.java:61) at org.apache.ibatis.executor.statement.RoutingStatementHandler.parameterize(RoutingStatementHandler.java:43) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:44) at com.sun.proxy.$Proxy25.parameterize(Unknown Source) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:44) at com.sun.proxy.$Proxy25.parameterize(Unknown Source) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:44) at com.sun.proxy.$Proxy25.parameterize(Unknown Source) at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:56) at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:28) at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:88) at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:43) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:44) at com.sun.proxy.$Proxy24.update(Unknown Source) at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:122) at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:111) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at com.al.persistence.ExtSqlSessionTemplate$SqlSessionInterceptor.invoke(ExtSqlSessionTemplate.java:190) at com.sun.proxy.$Proxy12.insert(Unknown Source) at com.al.persistence.ExtSqlSessionTemplate.insert(ExtSqlSessionTemplate.java:116) at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:59) at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:25) at com.sun.proxy.$Proxy17.insertCacheData(Unknown Source) ``` 在Mapper.xml 中配置sql语句, 数据库字段: cache_dir varchar2(50) cache_key varchar2(50) cache_value varchar2(1000) is_remote varchar2(5) create_date varchar2(50) value_type varchar2(50) ``` public void updateCacheData(Map<String, String> argsMap); ``` ``` insert into CACHE_TABLE ( CACHE_DIR, CACHE_KEY, CACHE_VALUE, IS_REMOTE, VALUE_TYPE, CREATE_DATE ) values( #{cacheDir,jdbcType=VARCHAR}, #{cacheKey,jdbcType=VARCHAR}, #{cacheValue,jdbcType=VARCHAR}, #{isRemote,jdbcType=LONGVARCHAR}, #{valueType,jdbcType=LONGVARCHAR}, #{createDate,jdbcType=LONGVARCHAR} ) </insert> ``` 后面三个字段用jdbcType=varchar就报上面那个错,用longvarchar就不报错了,所有字段都不为空值,这是为什么?
org.apache.ibatis.exceptions.PersistenceException怎么解决?
调试一个开源项目出现报错,项目所有sql都会报空指针异常 ``` 严重: Servlet.service() for servlet [springMvc] in context with path [/mallapp] threw exception [Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: java.lang.NullPointerException ### The error may exist in file [H:\WorksSpace\.metadata\.plugins\org.eclipse.wst.server.core\tmp2\wtpwebapps\mallapp\WEB-INF\classes\mybatis\category\CategoryMapper.xml] ### The error may involve CategoryMapper.listAll-Inline ### The error occurred while setting parameters ### SQL: select category_name, category_img, sort, category_id, super_id from shop_category where super_id =? order by sort ### Cause: java.lang.NullPointerException] with root cause java.lang.NullPointerException at org.apache.ibatis.type.BaseTypeHandler.setParameter(BaseTypeHandler.java:43) at org.apache.ibatis.scripting.defaults.DefaultParameterHandler.setParameters(DefaultParameterHandler.java:81) at org.apache.ibatis.executor.statement.PreparedStatementHandler.parameterize(PreparedStatementHandler.java:80) at org.apache.ibatis.executor.statement.RoutingStatementHandler.parameterize(RoutingStatementHandler.java:61) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:62) at com.sun.proxy.$Proxy84.parameterize(Unknown Source) at org.apache.ibatis.executor.ReuseExecutor.prepareStatement(ReuseExecutor.java:79) at org.apache.ibatis.executor.ReuseExecutor.doQuery(ReuseExecutor.java:56) at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:267) at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:137) at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:96) at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:77) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:108) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:102) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:358) at com.sun.proxy.$Proxy74.selectList(Unknown Source) at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:198) at com.yq.dao.DaoSupport.findForList(DaoSupport.java:118) at com.yq.service.category.impl.CategoryService.listAll(CategoryService.java:62) at com.yq.service.category.impl.CategoryService$$FastClassBySpringCGLIB$$51d95cd7.invoke(<generated>) at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:711) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:98) at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:262) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95) 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.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:644) at com.yq.service.category.impl.CategoryService$$EnhancerBySpringCGLIB$$c2253a36.listAll(<generated>) at com.yq.controller.category.CategoryController.list(CategoryController.java:80) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:749) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:690) at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:945) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:876) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852) at javax.servlet.http.HttpServlet.service(HttpServlet.java:624) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837) at javax.servlet.http.HttpServlet.service(HttpServlet.java:731) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:123) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:436) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745) ``` CategoryMapper.xml ``` <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="CategoryMapper"> <!--表名 --> <sql id="tableName"> shop_category </sql> <!-- 字段 --> <sql id="Field"> category_name, category_img, sort, category_id, super_id </sql> <!-- 字段值 --> <sql id="FieldValue"> #{category_name}, #{category_img}, #{sort}, #{category_id}, #{super_id} </sql> <!-- 新增--> <insert id="save" parameterType="pd"> insert into <include refid="tableName"></include> ( <include refid="Field"></include> ) values ( <include refid="FieldValue"></include> ) </insert> <!-- 删除--> <delete id="delete" parameterType="pd"> delete from <include refid="tableName"></include> where category_id = #{category_id} </delete> <!-- 修改 --> <update id="edit" parameterType="pd"> update <include refid="tableName"></include> set category_name = #{category_name}, category_img = #{category_img}, sort = #{sort} where category_id = #{category_id} </update> <!-- 通过ID获取数据 --> <select id="findById" parameterType="pd" resultType="pd"> select <include refid="Field"></include> from <include refid="tableName"></include> where category_id = #{category_id} </select> <!-- 列表 --> <select id="datalistPage" parameterType="page" resultType="pd"> select <include refid="Field"></include> from <include refid="tableName"></include> where 1=1 and super_id =#{pd.super_id} order by sort </select> <!-- 列表(全部) --> <select id="listAll" parameterType="pd" resultType="pd"> select <include refid="Field"></include> from <include refid="tableName"></include> where super_id =#{super_id} order by sort </select> <!-- 批量删除 --> <delete id="deleteAll" parameterType="String"> delete from <include refid="tableName"></include> where category_id in <foreach item="item" index="index" collection="array" open="(" separator="," close=")"> #{item} </foreach> </delete> </mapper> ``` mybatis-config.xml ``` <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD SQL Map Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> <settings> <setting name="cacheEnabled" value="true" /><!-- 全局映射器启用缓存 --> <setting name="useGeneratedKeys" value="true" /> <setting name="defaultExecutorType" value="REUSE" /> <!-- 打印查询语句 --> <setting name="logImpl" value="LOG4J" /> </settings> <typeAliases> <typeAlias type="org.change.entity.system.User" alias="User"/> <typeAlias type="org.change.entity.system.Role" alias="Role"/> <typeAlias type="org.change.entity.system.Menu" alias="Menu"/> <typeAlias type="org.change.entity.system.Dictionaries" alias="Dictionaries"/> <typeAlias type="org.change.entity.system.Department" alias="Department"/> <typeAlias type="org.change.util.PageData" alias="pd"/> <!-- 分页 --> <typeAlias type="org.change.entity.Page" alias="Page"/> </typeAliases> <plugins> <plugin interceptor="org.change.plugin.PagePlugin"> <property name="dialect" value="mysql"/> <property name="pageSqlId" value=".*listPage.*"/> </plugin> </plugins> </configuration> ``` DAO.java ``` public interface DAO { /** * 保存对象 * @param str * @param obj * @return * @throws Exception */ public Object save(String str, Object obj) throws Exception; /** * 修改对象 * @param str * @param obj * @return * @throws Exception */ public Object update(String str, Object obj) throws Exception; /** * 删除对象 * @param str * @param obj * @return * @throws Exception */ public Object delete(String str, Object obj) throws Exception; /** * 查找对象 * @param str * @param obj * @return * @throws Exception */ public Object findForObject(String str, Object obj) throws Exception; /** * 查找对象 * @param str * @param obj * @return * @throws Exception */ public Object findForList(String str, Object obj) throws Exception; /** * 查找对象封装成Map * @param s * @param obj * @return * @throws Exception */ public Object findForMap(String sql, Object obj, String key , String value) throws Exception; } ``` DaoSupport.java ``` @Repository("daoSupport") public class DaoSupport implements DAO { @Resource(name = "sqlSessionTemplate") private SqlSessionTemplate sqlSessionTemplate; /** * 保存对象 * @param str * @param obj * @return * @throws Exception */ public Object save(String str, Object obj) throws Exception { return sqlSessionTemplate.insert(str, obj); } /** * 批量更新 * @param str * @param obj * @return * @throws Exception */ public Object batchSave(String str, List objs )throws Exception{ return sqlSessionTemplate.insert(str, objs); } /** * 修改对象 * @param str * @param obj * @return * @throws Exception */ public Object update(String str, Object obj) throws Exception { return sqlSessionTemplate.update(str, obj); } /** * 批量更新 * @param str * @param obj * @return * @throws Exception */ public void batchUpdate(String str, List objs )throws Exception{ SqlSessionFactory sqlSessionFactory = sqlSessionTemplate.getSqlSessionFactory(); //批量执行器 SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH,false); try{ if(objs!=null){ for(int i=0,size=objs.size();i<size;i++){ sqlSession.update(str, objs.get(i)); } sqlSession.flushStatements(); sqlSession.commit(); sqlSession.clearCache(); } }finally{ sqlSession.close(); } } /** * 批量更新 * @param str * @param obj * @return * @throws Exception */ public Object batchDelete(String str, List objs )throws Exception{ return sqlSessionTemplate.delete(str, objs); } /** * 删除对象 * @param str * @param obj * @return * @throws Exception */ public Object delete(String str, Object obj) throws Exception { return sqlSessionTemplate.delete(str, obj); } /** * 查找对象 * @param str * @param obj * @return * @throws Exception */ public Object findForObject(String str, Object obj) throws Exception { return sqlSessionTemplate.selectOne(str, obj); } /** * 查找对象 * @param str * @param obj * @return * @throws Exception */ public Object findForList(String str, Object obj) throws Exception { return sqlSessionTemplate.selectList(str, obj); } public Object findForMap(String str, Object obj, String key, String value) throws Exception { return sqlSessionTemplate.selectMap(str, obj, key); } } ``` spring.xml ``` <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd "> <!-- 配置事务管理器 --> <bean name="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"></property> </bean> <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location" value="classpath:jdbc.properties"/> </bean> <!-- 阿里 druid数据库连接池 --> <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" destroy-method="close"> <!-- 数据库基本信息配置 --> <property name="driverClassName" value="${driverClassName}" /> <property name="url" value="${url}" /> <property name="username" value="${username}" /> <property name="password" value="${password}" /> <property name="filters" value="${filters}" /> <!-- 最大并发连接数 --> <property name="maxActive" value="${maxActive}" /> <!-- 初始化连接数量 --> <property name="initialSize" value="${initialSize}" /> <!-- 配置获取连接等待超时的时间 --> <property name="maxWait" value="${maxWait}" /> <!-- 最小空闲连接数 --> <property name="minIdle" value="${minIdle}" /> <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 --> <property name="timeBetweenEvictionRunsMillis" value="${timeBetweenEvictionRunsMillis}" /> <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 --> <property name="minEvictableIdleTimeMillis" value="${minEvictableIdleTimeMillis}" /> <property name="validationQuery" value="${validationQuery}" /> <property name="testWhileIdle" value="${testWhileIdle}" /> <property name="testOnBorrow" value="${testOnBorrow}" /> <property name="testOnReturn" value="${testOnReturn}" /> <property name="maxOpenPreparedStatements" value="${maxOpenPreparedStatements}" /> <!-- 打开removeAbandoned功能 --> <property name="removeAbandoned" value="${removeAbandoned}" /> <!-- 1800秒,也就是30分钟 --> <property name="removeAbandonedTimeout" value="${removeAbandonedTimeout}" /> <!-- 关闭abanded连接时输出错误日志 --> <property name="logAbandoned" value="${logAbandoned}" /> </bean> <!-- 启用注解 --> <context:annotation-config /> <!-- 启动组件扫描,排除@Controller组件,该组件由SpringMVC配置文件扫描 --> <context:component-scan base-package="com"> <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" /> </context:component-scan> <!-- 注解方式配置事务--> <!-- <tx:annotation-driven transaction-manager="transactionManager" /> --> <!-- 拦截器方式配置事务 --> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="delete*" propagation="REQUIRED" read-only="false" rollback-for="java.lang.Exception"/> <tx:method name="insert*" propagation="REQUIRED" read-only="false" rollback-for="java.lang.Exception" /> <tx:method name="update*" propagation="REQUIRED" read-only="false" rollback-for="java.lang.Exception" /> <tx:method name="save*" propagation="REQUIRED" read-only="false" rollback-for="java.lang.Exception" /> <tx:method name="*" propagation="SUPPORTS"/> </tx:attributes> </tx:advice> <aop:aspectj-autoproxy proxy-target-class="true"/> <!-- 事物处理 --> <aop:config> <aop:pointcut id="pc" expression="execution(* com.*.service..*(..))" /> <aop:advisor pointcut-ref="pc" advice-ref="txAdvice" /> </aop:config> <!-- 配置mybatis --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="configLocation" value="classpath:mybatis-config.xml"></property> <!-- mapper扫描 --> <property name="mapperLocations" value="classpath:mybatis/*/*.xml"></property> </bean> <bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate"> <constructor-arg ref="sqlSessionFactory" /> </bean> </beans> ```
MyBatis-plus分页条件自定义查询的问题
```java package io.renren.modules.soft.service.impl; import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import io.renren.common.utils.PageUtils; import io.renren.common.utils.Query; import io.renren.modules.soft.dao.OrderDao; import io.renren.modules.soft.dto.OrderVO; import io.renren.modules.soft.entity.OrderEntity; import io.renren.modules.soft.service.OrderService; @Service("orderService") public class OrderServiceImpl extends ServiceImpl<OrderDao, OrderEntity> implements OrderService { @Autowired private OrderDao orderDao; @Override public PageUtils getlistData(Map<String, Object> params) { Page<OrderVO> page = (Page<OrderVO>) new Query<OrderVO>().getPage(params); page.setRecords(this.baseMapper.selectListData(page,params)); return new PageUtils(page); } } ``` OrderDao.java方法 ``` package io.renren.modules.soft.dao; import java.util.List; import java.util.Map; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import io.renren.modules.soft.dto.OrderVO; import io.renren.modules.soft.entity.OrderEntity; /** * 订单基础表 * * @author Mark * @email sunlightcs@gmail.com * @date 2019-03-22 08:54:02 */ @Mapper public interface OrderDao extends BaseMapper<OrderEntity> { List<OrderVO> selectListData(Page<OrderVO> page, @Param("map")Map<String, Object> params); } ``` 自定的XML中的SQL语句 ``` <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="io.renren.modules.soft.dao.OrderDao"> <!-- 可根据自己的需求,是否要使用 --> <resultMap type="io.renren.modules.soft.entity.OrderEntity" id="orderMap"> <result property="id" column="ID"/> <result property="orderNo" column="order_no"/> <result property="orderType" column="order_type"/> <result property="orderTitle" column="order_title"/> <result property="totalFee" column="total_fee"/> <result property="settlementTotalFee" column="settlement_total_fee"/> <result property="payWay" column="pay_way"/> <result property="orderStatus" column="order_status"/> <result property="payStatus" column="pay_status"/> <result property="payId" column="pay_id"/> <result property="userId" column="user_id"/> <result property="payEndTime" column="pay_end_time"/> <result property="createTime" column="create_time"/> <result property="createBy" column="create_by"/> <result property="updateBy" column="update_by"/> <result property="updateTime" column="update_time"/> <result property="status" column="status"/> </resultMap> <!-- 可根据自己的需求,是否要使用 --> <resultMap type="io.renren.modules.soft.dto.OrderVO" id="orderVOMap"> <result property="id" column="ID"/> <result property="orderNo" column="order_no"/> <result property="orderType" column="order_type"/> <result property="orderTitle" column="order_title"/> <result property="totalFee" column="total_fee"/> <result property="settlementTotalFee" column="settlement_total_fee"/> <result property="payWay" column="pay_way"/> <result property="orderStatus" column="order_status"/> <result property="payStatus" column="pay_status"/> <result property="payId" column="pay_id"/> <result property="username" column="username"/> <result property="payEndTime" column="pay_end_time"/> </resultMap> <select id="selectListData" parameterType="String" resultMap="orderVOMap"> SELECT a.ID, a.order_no, a.order_type, a.order_title, a.total_fee, a.settlement_total_fee, a.pay_way, a.order_status, a.pay_status, a.pay_id, au.wechat_nick_name as username, a.pay_end_time FROM tb_order a, tb_user au WHERE a.status = 0 AND a.user_id = au.id <if test="map.username != null"> AND au.wechat_nick_name like concat(concat("%",#{map.username}),"%") </if> </select> </mapper> ``` 出现的问题:当map.username不是空的时候,在第一页能够查询出所有的结果,但是跳转到第二页的时候,再输入条件查询,直接连带着分页参数和条件查询参数直接查询SQL语句。 这样,如果第二页中不存在这个条件的结果,那么就完全查询不到着一条数据。请问有什么解决方法 当在第一页查询的日志如下: ``` i.r.m.soft.dao.OrderDao.selectListData : ==> Preparing: SELECT a.ID, a.order_no, a.order_type, a.order_title, a.total_fee, a.settlement_total_fee, a.pay_way, a.order_status, a.pay_status, a.pay_id, au.wechat_nick_name as username, a.pay_end_time FROM tb_order a, tb_user au WHERE a.status = 0 AND a.user_id = au.id AND au.wechat_nick_name like concat(concat("%",?),"%") LIMIT ?,? i.r.m.soft.dao.OrderDao.selectListData : ==> Parameters: 刘仁(String), 0(Long), 10(Long) i.r.m.soft.dao.OrderDao.selectListData : <== Total: 3 ``` 当在第二页的时候查询日志如下: ``` i.r.m.soft.dao.OrderDao.selectListData : ==> Preparing: SELECT a.ID, a.order_no, a.order_type, a.order_title, a.total_fee, a.settlement_total_fee, a.pay_way, a.order_status, a.pay_status, a.pay_id, au.wechat_nick_name as username, a.pay_end_time FROM tb_order a, tb_user au WHERE a.status = 0 AND a.user_id = au.id AND au.wechat_nick_name like concat(concat("%",?),"%") LIMIT ?,? i.r.m.soft.dao.OrderDao.selectListData : ==> Parameters: 刘仁(String), 10(Long), 10(Long) i.r.m.soft.dao.OrderDao.selectListData : <== Total: 0 ``` 因为分页了,所有查询不到结果,可是我想分不分也都能查询到全部结果,各位大神有什么好的解决方案,请帮一下忙。
一个ssm项目只给了映射文件,需要我创建数据库,但是有些问题,
controller取不到数据库的值,方法里写了打印输出语句输出为空,想让各位看下表是否有问题。 一共四个映射文件 admin_info表 ``` <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.digital.dao.AdminInfoDAO"> <select id="getAdminInfoByCond" parameterType="com.digital.pojo.AdminInfo" resultType="com.digital.pojo.AdminInfo"> select * from admin_info where name=#{name} and pwd=#{pwd} </select> <select id="getAdminInfoFunctions" parameterType="int" resultMap="getAdminInfoFunctionsMap"> select ai.id,ai.name,f.id fuid,f.name fname,f.parentid fpid,f.isleaf fisleaf,f.nodeorder fno from admin_info ai left join powers p on ai.id=p.aid join functions f on p.fid=f.id where ai.id=#{id} ORDER BY fpid </select> <resultMap type="com.digital.pojo.AdminInfo" id="getAdminInfoFunctionsMap"> <id property="id" column="id"/> <result property="name" column="name"/> <collection property="fs" ofType="com.digital.pojo.Functions"> <id property="id" column="fuid"/> <result property="name" column="fname"/> <result property="parentid" column="fpid"/> <result property="isleaf" column="fisleaf"/> </collection> </resultMap> <select id="getAllAdminInfo" resultType="com.digital.pojo.Functions"> select * from admin_info </select> <select id="getAdminById" parameterType="int" resultType="com.digital.pojo.AdminInfo"> select * from admin_info(name,pwd,role) values(#{name},#{pwd},#{role}) </select> </mapper> ``` ![图片说明](https://img-ask.csdn.net/upload/201904/18/1555592692_131715.png) functions表 ``` <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.digital.dao.FunctionsDAO"> <select id="getAllFunctions" resultType="com.digital.pojo.Functions"> select * from functions </select> </mapper> ``` ![图片说明](https://img-ask.csdn.net/upload/201904/18/1555593008_498896.png) powers表 ``` <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.digital.dao.PowersDAO"> <select id="delPowersByAdminid" parameterType="int"> delete from Powers where aid=#{aid} </select> <!-- 保存管理员和系统功能之间的关联关系信息 --> <insert id="addPowers" parameterType="java.util.Map"> insert into powers(aid,fid) values(#{aid},#{fid}) </insert> </mapper> ``` ![图片说明](https://img-ask.csdn.net/upload/201904/18/1555592859_4441.png) user_info 表 ``` <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.digital.dao.UserInfoDAO"> <select id="getUserInfoByCond" parameterType="com.digital.pojo.UserInfo" resultType="com.digital.pojo.UserInfo"> select * from user_info where userName=#{userName} and password=#{password} </select> <select id="getUserListByPage" parameterType="java.util.Map" resultType="com.digital.pojo.UserInfo"> <if test="userName!=null and userName!=''"> select * from user_info where userName LIKE CONCAT(CONCAT('%',#{userName}),'%') limt #{start},#{limt} </if> <if test="userName==null or userName==''"> select * from user_info where limt #{start},#{limt} </if> </select> <select id="getAllUser" parameterType="String" resultType="com.digital.pojo.UserInfo"> <if test="_parameter!=null and _parameter!=''"> select * from user_info where userName LIKE CONCAT(CONCAT('%',#{_parameter}),'%') </if> <if test="userName==null or userName==''"> select * from user_info </if> </select> <select id="updateUserStatus" parameterType="java.util.Map"> <if test="flag==0"> upadate user_info set status=0 where id in </if> <if test="flag==1"> update user_info set status=1 where id in </if> <foreach item="item" index="index" collection="ids" open="(" separator="," close=")"> #{item} </foreach> </select> </mapper> ``` ![图片说明](https://img-ask.csdn.net/upload/201904/18/1555592952_239120.png) 这是mybatis的配置 ``` <!-- 配置mybatis工厂 --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <!-- 注入数据源 --> <property name="dataSource" ref="dataSource"/> <!-- 指定mybatis映射文件位置 --> <property name="mapperLocations" value="classpath*:com/digital/mapping/*Mapper.xml"/> </bean> <!--配置MapperScannerConfigurer,DAO接口所在包名,Spring会自动查找其下的类 --> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.digital.dao"/> <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/> </bean> ``` 配置文件所在的包 ![图片说明](https://img-ask.csdn.net/upload/201904/18/1555594856_354610.png) 项目的部分目录 ![图片说明](https://img-ask.csdn.net/upload/201904/18/1555598353_700162.png)
java SSM整合问题,无法进入Controller
![图片说明](https://img-ask.csdn.net/upload/201805/10/1525933317_321633.png) web.xml ``` <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring-mybatis.xml</param-value> </context-param> <servlet> <servlet-name>SpringMVC</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring-mvc.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> <async-supported>true</async-supported> </servlet> <servlet-mapping> <servlet-name>SpringMVC</servlet-name> <!-- 此处可以可以配置成*.do,对应struts的后缀习惯 --> <url-pattern>/</url-pattern> </servlet-mapping> ``` spring-mvc.xml: ``` <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd"> <!-- 自动扫描该包,使SpringMVC认为包下用了@controller注解的类是控制器 --> <context:component-scan base-package="com.controller.*" /> <!--避免IE执行AJAX时,返回JSON出现下载文件 --> <bean id="mappingJacksonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"> <property name="supportedMediaTypes"> <list> <value>text/html;charset=UTF-8</value> </list> </property> </bean> ``` Spring-mybatis.xml: ``` <!-- 自动扫描 --> <!-- <context:component-scan base-package="com.services.*" /> --> <!-- 引入配置文件 --> <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location" value="classpath:jdbc.properties" /> </bean> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="${driver}" /> <property name="url" value="${url}" /> <property name="username" value="${username}" /> <property name="password" value="${password}" /> <!-- 初始化连接大小 --> <property name="initialSize" value="${initialSize}"></property> <!-- 连接池最大数量 --> <property name="maxActive" value="${maxActive}"></property> <!-- 连接池最大空闲 --> <property name="maxIdle" value="${maxIdle}"></property> <!-- 连接池最小空闲 --> <property name="minIdle" value="${minIdle}"></property> <!-- 获取连接最大等待时间 --> <property name="maxWait" value="${maxWait}"></property> </bean> <!-- 第一种 spring和MyBatis完美整合,不需要mybatis的配置映射文件 --> <!-- <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> 自动扫描mapping.xml文件 <property name="mapperLocations" value="classpath*:mapping/*.xml"></property> </bean> --> <!--第二种 mybatis-spring整合 手动配置mybatis配置文件--> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource"/> <property name="configLocation" value="classpath:mybatis-config.xml"/> </bean> <!-- DAO接口所在包名,Spring会自动查找其下的类 --> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.DAO" /> <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property> </bean> ``` mybatis.xml ``` <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> <!-- 创建实体类别名 --> <typeAliases> <!--type:对象类型 alias:对象别名 --> <typeAlias type="com.model.User" alias="User"/> </typeAliases> <!--配置mybatis映射文件 --> <mappers> <mapper resource="com/mapper/UserMapper.xml"/> </mappers> </configuration> ``` DAO: ``` package com.DAO; import com.model.User; public interface UserDao { User findUserByName(String username,String pwd); } ``` mapper: ``` <mapper namespace="com.DAO.UserDao"> <!-- 新增 --> <insert id="saveUser" parameterType="com.cn.ssm.pojo.User" > insert into t_user(user_name,user_age) values (#{username},#{age}) </insert> <!-- 修改 --> <update id="updateUser" parameterType="com.cn.ssm.pojo.User" > update t_user set user_name=#{username},user_age=#{age} where user_id=#{id} </update> <!-- 删除 --> <delete id="deleteUser" parameterType="int"> delete from t_user where user_id=#{id} </delete> <!-- 根据id查找单个用户 --> <select id="findUserById" parameterType="java.lang.Integer" resultType="com.cn.ssm.pojo.User"> select id,user_name,age from user_t where id=#{id} </select> <!-- 查询所有 --> <select id="findAll" resultType="com.cn.ssm.pojo.User"> select user_id id,user_name userName,user_age age from t_user </select> <!-- 根据用户名和密码查询用户 --> <select id="findUserByName" parameterType="String" resultType="com.model.User"> <!-- 只传一个参数到sql语句时,可以直接写参数名,当传多个参数时,需用0,1,2...,或者在dao层使用@Param注解--> select * from userinfo where UserName=#{0} AND PassWord=#{1} </select> ``` services: ``` package com.services; import com.model.User; public interface IUserService { public User findUserByName(String username,String pwd); } ``` services.implents: ``` @Service @Transactional public class UserServiceImpl implements IUserService{ @Autowired public UserDao UserMapper; public User findUserByName(String name,String password){ return this.UserMapper.findUserByName(name, password); } } ``` Controller: ``` @Controller @RequestMapping("/user") public class UserController { @Autowired private IUserService userService; @RequestMapping("longin") public void checkLogin(HttpServletRequest request,HttpServletResponse response){ String username=request.getParameter("name"); String password=request.getParameter("password"); response.setCharacterEncoding("utf-8"); System.out.println(username+","+password); User user=userService.findUserByName(username, password); HttpSession session=request.getSession(); if(user!=null){ session.setAttribute("user", user); try { //response.sendRedirect("../index2.jsp"); response.getWriter().write("登录失败"); } catch (IOException e) { e.printStackTrace(); } }else{ try { response.getWriter().write("登录失败"); } catch (IOException e) { // TODO Auto-generated catch block ``` jsp: ``` <body> <form action="user/longin"> <label>用户名:<input type="text" name="name"></label> <label>密码:<input type="password" name="password"></label> <input type="submit" value="登录..."> </form> <button onclick="login_ip()">IP登录</button> </body> ```
Mybatis使用查询失败查询一直为空
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!-- 命名空间可以任选命名,但最好要定义一定规则,便于后继的使用 --> <mapper namespace="cn.scau.cty.DeptMapper"> <!-- 一般在查询时使用--> <resultMap id="deptResultMap" type="Dept"> <id property="deptId" column="dept_id"/> <result property="deptName" column="dept_name"/> <result property="deptAddress" column="dept_address"/> </resultMap> <!-- 定义插入的sql语句,通过命名空间+id方式被定位 --> <insert id="insert" parameterType="Dept"> insert into dept(dept_name,dept_address) values(#{deptName},#{deptAddress}) </insert> <update id="update" parameterType="Dept"> update dept set dept_name=#{deptName},dept_address=#{deptAddress} where dept_id =#{deptId} </update> <delete id="delete" parameterType="Dept"> delete from dept where dept_id=#{deptId} </delete> <select id="selectOne" parameterType="int" resultMap="deptResultMap" > select * from dept where dept_id=#{deptId} </select> <select id="selectList" parameterType="string" resultMap="deptResultMap"> select * from dept where dept_address=#{deptAddress} </select> </mapper> public class MyBatisUtil { private static final ThreadLocal<SqlSession> threadLocal = new ThreadLocal<SqlSession>(); private static SqlSessionFactory sessionFactory; private static String CONFIG_FILE_LOCATION ="myBatis-config.xml"; static { try { buildSessionFactory(); } catch (Exception e) { System.err.println("%%%% Error Creating SessionFactory %%%%"); e.printStackTrace(); } } private MyBatisUtil() { } /** * Returns the ThreadLocal Session instance. Lazy initialize * the <code>SessionFactory</code> if needed. * * @return Session * @throws Exception */ public static SqlSession getSession() throws Exception { SqlSession session = (SqlSession) threadLocal.get(); if (session == null) { if (sessionFactory == null) { buildSessionFactory(); } session = (sessionFactory != null) ? sessionFactory.openSession() : null; threadLocal.set(session); } return session; } /** * build session factory * */ public static void buildSessionFactory() { Reader reader=null; try { reader=Resources.getResourceAsReader(CONFIG_FILE_LOCATION); sessionFactory = new SqlSessionFactoryBuilder().build(reader); } catch (Exception e) { System.err.println("%%%% Error Creating SessionFactory %%%%"); e.printStackTrace(); }finally{ try { reader.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } /** * Close the single session instance. * */ public static void closeSession(){ SqlSession session = (SqlSession) threadLocal.get(); threadLocal.set(null); if (session != null) { session.close(); } } /** * return session factory * */ public static SqlSessionFactory getSessionFactory() { return sessionFactory; } } public Dept selectOne(int deptId) { Dept dept = null; SqlSession session = null; try { session = MyBatisUtil.getSession(); dept = (Dept)session.selectOne("cn.scau.cty.DeptMapper.selectOne", deptId); } catch (Exception e) { e.printStackTrace(); session.rollback(); }finally{ MyBatisUtil.closeSession(); } return dept; } @Test public void testSelectOne(){ Dept dept = deptDaoImpl.selectOne(4); System.out.println("查询到的记录部门是"+dept); } 查询到的记录 是null 求大神帮忙看下 谢谢了 上面没显示出来的是这个 <resultMap id="deptResultMap" type="Dept"> <id property="deptId" column="dept_id"/> <result property="deptName" column="dept_name"/> <result property="deptAddress" column="dept_address"/> </resultMap>
Could not find result map !按照百度说法把reaultMap改为resultType更是启动不了项目
以下是教材的sql语句,我跟教材唯独表名不一样。教材也是resultMap,所以不要再说把reaultMap改为resultType了 ``` <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > <mapper namespace="com.mmall.dao.SysDeptMapper" > <resultMap id="BaseResultMap" type="com.mmall.model.SysDept" > <id column="id" property="id" jdbcType="INTEGER" /> <result column="name" property="name" jdbcType="VARCHAR" /> <result column="parent_id" property="parentId" jdbcType="INTEGER" /> <result column="level" property="level" jdbcType="VARCHAR" /> <result column="seq" property="seq" jdbcType="INTEGER" /> <result column="remark" property="remark" jdbcType="VARCHAR" /> <result column="operator" property="operator" jdbcType="VARCHAR" /> <result column="operate_time" property="operateTime" jdbcType="TIMESTAMP" /> <result column="operate_ip" property="operateIp" jdbcType="VARCHAR" /> </resultMap> <sql id="Base_Column_List" > id, name, parent_id, level, seq, remark, operator, operate_time, operate_ip </sql> <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" > select <include refid="Base_Column_List" /> from sys_dept where id = #{id,jdbcType=INTEGER} </select> <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" > delete from sys_dept where id = #{id,jdbcType=INTEGER} </delete> <insert id="insert" parameterType="com.mmall.model.SysDept" > insert into sys_dept (id, name, parent_id, level, seq, remark, operator, operate_time, operate_ip ) values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{parentId,jdbcType=INTEGER}, #{level,jdbcType=VARCHAR}, #{seq,jdbcType=INTEGER}, #{remark,jdbcType=VARCHAR}, #{operator,jdbcType=VARCHAR}, #{operateTime,jdbcType=TIMESTAMP}, #{operateIp,jdbcType=VARCHAR} ) </insert> <insert id="insertSelective" parameterType="com.mmall.model.SysDept" keyProperty="id" useGeneratedKeys="true"> insert into sys_dept <trim prefix="(" suffix=")" suffixOverrides="," > <if test="id != null" > id, </if> <if test="name != null" > name, </if> <if test="parentId != null" > parent_id, </if> <if test="level != null" > level, </if> <if test="seq != null" > seq, </if> <if test="remark != null" > remark, </if> <if test="operator != null" > operator, </if> <if test="operateTime != null" > operate_time, </if> <if test="operateIp != null" > operate_ip, </if> </trim> <trim prefix="values (" suffix=")" suffixOverrides="," > <if test="id != null" > #{id,jdbcType=INTEGER}, </if> <if test="name != null" > #{name,jdbcType=VARCHAR}, </if> <if test="parentId != null" > #{parentId,jdbcType=INTEGER}, </if> <if test="level != null" > #{level,jdbcType=VARCHAR}, </if> <if test="seq != null" > #{seq,jdbcType=INTEGER}, </if> <if test="remark != null" > #{remark,jdbcType=VARCHAR}, </if> <if test="operator != null" > #{operator,jdbcType=VARCHAR}, </if> <if test="operateTime != null" > #{operateTime,jdbcType=TIMESTAMP}, </if> <if test="operateIp != null" > #{operateIp,jdbcType=VARCHAR}, </if> </trim> </insert> <update id="updateByPrimaryKeySelective" parameterType="com.mmall.model.SysDept" > update sys_dept <set > <if test="name != null" > name = #{name,jdbcType=VARCHAR}, </if> <if test="parentId != null" > parent_id = #{parentId,jdbcType=INTEGER}, </if> <if test="level != null" > level = #{level,jdbcType=VARCHAR}, </if> <if test="seq != null" > seq = #{seq,jdbcType=INTEGER}, </if> <if test="remark != null" > remark = #{remark,jdbcType=VARCHAR}, </if> <if test="operator != null" > operator = #{operator,jdbcType=VARCHAR}, </if> <if test="operateTime != null" > operate_time = #{operateTime,jdbcType=TIMESTAMP}, </if> <if test="operateIp != null" > operate_ip = #{operateIp,jdbcType=VARCHAR}, </if> </set> where id = #{id,jdbcType=INTEGER} </update> <update id="updateByPrimaryKey" parameterType="com.mmall.model.SysDept" > update sys_dept set name = #{name,jdbcType=VARCHAR}, parent_id = #{parentId,jdbcType=INTEGER}, level = #{level,jdbcType=VARCHAR}, seq = #{seq,jdbcType=INTEGER}, remark = #{remark,jdbcType=VARCHAR}, operator = #{operator,jdbcType=VARCHAR}, operate_time = #{operateTime,jdbcType=TIMESTAMP}, operate_ip = #{operateIp,jdbcType=VARCHAR} where id = #{id,jdbcType=INTEGER} </update> <select id="getAllDept" resultMap="BaseResultMap"> select <include refid="Base_Column_List" /> from sys_dept </select> <select id="getChildDeptListByLevel" resultMap="BaseResultMap"> select <include refid="Base_Column_List" /> from sys_dept WHERE level like #{level} || '.%' </select> <update id="batchUpdateLevel" parameterType="map"> <foreach collection="sysDeptList" item="sysDept" separator=";"> UPDATE sys_dept SET level = #{dept.level} WHERE id = #{dept.id} </foreach> </update> <select id="countByNameAndParentId" parameterType="map" resultType="int"> SELECT count(1) FROM sys_dept WHERE name = #{name} <if test="parentId != null"> AND parent_id = #{parentId} </if> <if test="id != null"> AND id != #{id} </if> </select> <select id="countByParentId" parameterType="int" resultType="int"> SELECT count(1) FROM sys_dept WHERE parent_id = #{deptId} </select> </mapper> ```
相见恨晚的超实用网站
搞学习 知乎:www.zhihu.com 简答题:http://www.jiandati.com/ 网易公开课:https://open.163.com/ted/ 网易云课堂:https://study.163.com/ 中国大学MOOC:www.icourse163.org 网易云课堂:study.163.com 哔哩哔哩弹幕网:www.bilibili.com 我要自学网:www.51zxw
花了20分钟,给女朋友们写了一个web版群聊程序
参考博客 [1]https://www.byteslounge.com/tutorials/java-ee-html5-websocket-example
爬虫福利二 之 妹子图网MM批量下载
爬虫福利一:27报网MM批量下载    点击 看了本文,相信大家对爬虫一定会产生强烈的兴趣,激励自己去学习爬虫,在这里提前祝:大家学有所成! 目标网站:妹子图网 环境:Python3.x 相关第三方模块:requests、beautifulsoup4 Re:各位在测试时只需要将代码里的变量 path 指定为你当前系统要保存的路径,使用 python xxx.py 或IDE运行即可。
字节跳动视频编解码面经
引言 本文主要是记录一下面试字节跳动的经历。 三四月份投了字节跳动的实习(图形图像岗位),然后hr打电话过来问了一下会不会opengl,c++,shador,当时只会一点c++,其他两个都不会,也就直接被拒了。 七月初内推了字节跳动的提前批,因为内推没有具体的岗位,hr又打电话问要不要考虑一下图形图像岗,我说实习投过这个岗位不合适,不会opengl和shador,然后hr就说秋招更看重基础。我当时
Java学习的正确打开方式
在博主认为,对于入门级学习java的最佳学习方法莫过于视频+博客+书籍+总结,前三者博主将淋漓尽致地挥毫于这篇博客文章中,至于总结在于个人,实际上越到后面你会发现学习的最好方式就是阅读参考官方文档其次就是国内的书籍,博客次之,这又是一个层次了,这里暂时不提后面再谈。博主将为各位入门java保驾护航,各位只管冲鸭!!!上天是公平的,只要不辜负时间,时间自然不会辜负你。 何谓学习?博主所理解的学习,它
程序员必须掌握的核心算法有哪些?
由于我之前一直强调数据结构以及算法学习的重要性,所以就有一些读者经常问我,数据结构与算法应该要学习到哪个程度呢?,说实话,这个问题我不知道要怎么回答你,主要取决于你想学习到哪些程度,不过针对这个问题,我稍微总结一下我学过的算法知识点,以及我觉得值得学习的算法。这些算法与数据结构的学习大多数是零散的,并没有一本把他们全部覆盖的书籍。下面是我觉得值得学习的一些算法以及数据结构,当然,我也会整理一些看过
大学四年自学走来,这些私藏的实用工具/学习网站我贡献出来了
大学四年,看课本是不可能一直看课本的了,对于学习,特别是自学,善于搜索网上的一些资源来辅助,还是非常有必要的,下面我就把这几年私藏的各种资源,网站贡献出来给你们。主要有:电子书搜索、实用工具、在线视频学习网站、非视频学习网站、软件下载、面试/求职必备网站。 注意:文中提到的所有资源,文末我都给你整理好了,你们只管拿去,如果觉得不错,转发、分享就是最大的支持了。 一、电子书搜索 对于大部分程序员...
linux系列之常用运维命令整理笔录
本博客记录工作中需要的linux运维命令,大学时候开始接触linux,会一些基本操作,可是都没有整理起来,加上是做开发,不做运维,有些命令忘记了,所以现在整理成博客,当然vi,文件操作等就不介绍了,慢慢积累一些其它拓展的命令,博客不定时更新 顺便拉下票,我在参加csdn博客之星竞选,欢迎投票支持,每个QQ或者微信每天都可以投5票,扫二维码即可,http://m234140.nofollow.ax.
比特币原理详解
一、什么是比特币 比特币是一种电子货币,是一种基于密码学的货币,在2008年11月1日由中本聪发表比特币白皮书,文中提出了一种去中心化的电子记账系统,我们平时的电子现金是银行来记账,因为银行的背后是国家信用。去中心化电子记账系统是参与者共同记账。比特币可以防止主权危机、信用风险。其好处不多做赘述,这一层面介绍的文章很多,本文主要从更深层的技术原理角度进行介绍。 二、问题引入 假设现有4个人...
Python 基础(一):入门必备知识
目录1 标识符2 关键字3 引号4 编码5 输入输出6 缩进7 多行8 注释9 数据类型10 运算符10.1 常用运算符10.2 运算符优先级 1 标识符 标识符是编程时使用的名字,用于给变量、函数、语句块等命名,Python 中标识符由字母、数字、下划线组成,不能以数字开头,区分大小写。 以下划线开头的标识符有特殊含义,单下划线开头的标识符,如:_xxx ,表示不能直接访问的类属性,需通过类提供
这30个CSS选择器,你必须熟记(上)
关注前端达人,与你共同进步CSS的魅力就是让我们前端工程师像设计师一样进行网页的设计,我们能轻而易举的改变颜色、布局、制作出漂亮的影音效果等等,我们只需要改几行代码,不需...
国产开源API网关项目进入Apache孵化器:APISIX
点击蓝色“程序猿DD”关注我回复“资源”获取独家整理的学习资料!近日,又有一个开源项目加入了这个Java开源界大名鼎鼎的Apache基金会,开始进行孵化器。项目名称:AP...
程序员接私活怎样防止做完了不给钱?
首先跟大家说明一点,我们做 IT 类的外包开发,是非标品开发,所以很有可能在开发过程中会有这样那样的需求修改,而这种需求修改很容易造成扯皮,进而影响到费用支付,甚至出现做完了项目收不到钱的情况。 那么,怎么保证自己的薪酬安全呢? 我们在开工前,一定要做好一些证据方面的准备(也就是“讨薪”的理论依据),这其中最重要的就是需求文档和验收标准。一定要让需求方提供这两个文档资料作为开发的基础。之后开发
网页实现一个简单的音乐播放器(大佬别看。(⊙﹏⊙))
今天闲着无事,就想写点东西。然后听了下歌,就打算写个播放器。 于是乎用h5 audio的加上js简单的播放器完工了。 欢迎 改进 留言。 演示地点跳到演示地点 html代码如下`&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;music&lt;/title&gt; &lt;meta charset="utf-8"&gt
Python十大装B语法
Python 是一种代表简单思想的语言,其语法相对简单,很容易上手。不过,如果就此小视 Python 语法的精妙和深邃,那就大错特错了。本文精心筛选了最能展现 Python 语法之精妙的十个知识点,并附上详细的实例代码。如能在实战中融会贯通、灵活使用,必将使代码更为精炼、高效,同时也会极大提升代码B格,使之看上去更老练,读起来更优雅。 1. for - else 什么?不是 if 和 else 才
数据库优化 - SQL优化
前面一篇文章从实例的角度进行数据库优化,通过配置一些参数让数据库性能达到最优。但是一些“不好”的SQL也会导致数据库查询变慢,影响业务流程。本文从SQL角度进行数据库优化,提升SQL运行效率。 判断问题SQL 判断SQL是否有问题时可以通过两个表象进行判断: 系统级别表象 CPU消耗严重 IO等待严重 页面响应时间过长
2019年11月中国大陆编程语言排行榜
2019年11月2日,我统计了某招聘网站,获得有效程序员招聘数据9万条。针对招聘信息,提取编程语言关键字,并统计如下: 编程语言比例 rank pl_ percentage 1 java 33.62% 2 c/c++ 16.42% 3 c_sharp 12.82% 4 javascript 12.31% 5 python 7.93% 6 go 7.25% 7
通俗易懂地给女朋友讲:线程池的内部原理
餐厅的约会 餐盘在灯光的照耀下格外晶莹洁白,女朋友拿起红酒杯轻轻地抿了一小口,对我说:“经常听你说线程池,到底线程池到底是个什么原理?”我楞了一下,心里想女朋友今天是怎么了,怎么突然问出这么专业的问题,但做为一个专业人士在女朋友面前也不能露怯啊,想了一下便说:“我先给你讲讲我前同事老王的故事吧!” 大龄程序员老王 老王是一个已经北漂十多年的程序员,岁数大了,加班加不动了,升迁也无望,于是拿着手里
经典算法(5)杨辉三角
杨辉三角 是经典算法,这篇博客对它的算法思想进行了讲解,并有完整的代码实现。
编写Spring MVC控制器的14个技巧
本期目录 1.使用@Controller构造型 2.实现控制器接口 3.扩展AbstractController类 4.为处理程序方法指定URL映射 5.为处理程序方法指定HTTP请求方法 6.将请求参数映射到处理程序方法 7.返回模型和视图 8.将对象放入模型 9.处理程序方法中的重定向 10.处理表格提交和表格验证 11.处理文件上传 12.在控制器中自动装配业务类 ...
腾讯算法面试题:64匹马8个跑道需要多少轮才能选出最快的四匹?
昨天,有网友私信我,说去阿里面试,彻底的被打击到了。问了为什么网上大量使用ThreadLocal的源码都会加上private static?他被难住了,因为他从来都没有考虑过这个问题。无独有偶,今天笔者又发现有网友吐槽了一道腾讯的面试题,我们一起来看看。 腾讯算法面试题:64匹马8个跑道需要多少轮才能选出最快的四匹? 在互联网职场论坛,一名程序员发帖求助到。二面腾讯,其中一个算法题:64匹
面试官:你连RESTful都不知道我怎么敢要你?
面试官:了解RESTful吗? 我:听说过。 面试官:那什么是RESTful? 我:就是用起来很规范,挺好的 面试官:是RESTful挺好的,还是自我感觉挺好的 我:都挺好的。 面试官:… 把门关上。 我:… 要干嘛?先关上再说。 面试官:我说出去把门关上。 我:what ?,夺门而去 文章目录01 前言02 RESTful的来源03 RESTful6大原则1. C-S架构2. 无状态3.统一的接
求小姐姐抠图竟遭白眼?痛定思痛,我决定用 Python 自力更生!
点击蓝色“Python空间”关注我丫加个“星标”,每天一起快乐的学习大家好,我是 Rocky0429,一个刚恰完午饭,正在用刷网页浪费生命的蒟蒻...一堆堆无聊八卦信息的网页内容慢慢使我的双眼模糊,一个哈欠打出了三斤老泪,就在此时我看到了一张图片:是谁!是谁把我女朋友的照片放出来的!awsl!太好看了叭...等等,那个背景上的一堆鬼画符是什么鬼?!真是看不下去!叔叔婶婶能忍,隔壁老王的三姨妈的四表...
为啥国人偏爱Mybatis,而老外喜欢Hibernate/JPA呢?
关于SQL和ORM的争论,永远都不会终止,我也一直在思考这个问题。昨天又跟群里的小伙伴进行了一番讨论,感触还是有一些,于是就有了今天这篇文。 声明:本文不会下关于Mybatis和JPA两个持久层框架哪个更好这样的结论。只是摆事实,讲道理,所以,请各位看官勿喷。 一、事件起因 关于Mybatis和JPA孰优孰劣的问题,争论已经很多年了。一直也没有结论,毕竟每个人的喜好和习惯是大不相同的。我也看
SQL-小白最佳入门sql查询一
不要偷偷的查询我的个人资料,即使你再喜欢我,也不要这样,真的不好;
项目中的if else太多了,该怎么重构?
介绍 最近跟着公司的大佬开发了一款IM系统,类似QQ和微信哈,就是聊天软件。我们有一部分业务逻辑是这样的 if (msgType = "文本") { // dosomething } else if(msgType = "图片") { // doshomething } else if(msgType = "视频") { // doshomething } else { // doshom...
致 Python 初学者
欢迎来到“Python进阶”专栏!来到这里的每一位同学,应该大致上学习了很多 Python 的基础知识,正在努力成长的过程中。在此期间,一定遇到了很多的困惑,对未来的学习方向感到迷茫。我非常理解你们所面临的处境。我从2007年开始接触 python 这门编程语言,从2009年开始单一使用 python 应对所有的开发工作,直至今天。回顾自己的学习过程,也曾经遇到过无数的困难,也曾经迷茫过、困惑过。开办这个专栏,正是为了帮助像我当年一样困惑的 Python 初学者走出困境、快速成长。希望我的经验能真正帮到你
“狗屁不通文章生成器”登顶GitHub热榜,分分钟写出万字形式主义大作
一、垃圾文字生成器介绍 最近在浏览GitHub的时候,发现了这样一个骨骼清奇的雷人项目,而且热度还特别高。 项目中文名:狗屁不通文章生成器 项目英文名:BullshitGenerator 根据作者的介绍,他是偶尔需要一些中文文字用于GUI开发时测试文本渲染,因此开发了这个废话生成器。但由于生成的废话实在是太过富于哲理,所以最近已经被小伙伴们给玩坏了。 他的文风可能是这样的: 你发现,...
程序员:我终于知道post和get的区别
是一个老生常谈的话题,然而随着不断的学习,对于以前的认识有很多误区,所以还是需要不断地总结的,学而时习之,不亦说乎
《程序人生》系列-这个程序员只用了20行代码就拿了冠军
你知道的越多,你不知道的越多 点赞再看,养成习惯GitHub上已经开源https://github.com/JavaFamily,有一线大厂面试点脑图,欢迎Star和完善 前言 这一期不算《吊打面试官》系列的,所有没前言我直接开始。 絮叨 本来应该是没有这期的,看过我上期的小伙伴应该是知道的嘛,双十一比较忙嘛,要值班又要去帮忙拍摄年会的视频素材,还得搞个程序员一天的Vlog,还要写BU...
加快推动区块链技术和产业创新发展,2019可信区块链峰会在京召开
11月8日,由中国信息通信研究院、中国通信标准化协会、中国互联网协会、可信区块链推进计划联合主办,科技行者协办的2019可信区块链峰会将在北京悠唐皇冠假日酒店开幕。   区块链技术被认为是继蒸汽机、电力、互联网之后,下一代颠覆性的核心技术。如果说蒸汽机释放了人类的生产力,电力解决了人类基本的生活需求,互联网彻底改变了信息传递的方式,区块链作为构造信任的技术有重要的价值。   1...
程序员把地府后台管理系统做出来了,还有3.0版本!12月7号最新消息:已在开发中有github地址
第一幕:缘起 听说阎王爷要做个生死簿后台管理系统,我们派去了一个程序员…… 996程序员做的梦: 第一场:团队招募 为了应对地府管理危机,阎王打算找“人”开发一套地府后台管理系统,于是就在地府总经办群中发了项目需求。 话说还是中国电信的信号好,地府都是满格,哈哈!!! 经常会有外行朋友问:看某网站做的不错,功能也简单,你帮忙做一下? 而这次,面对这样的需求,这个程序员...
网易云6亿用户音乐推荐算法
网易云音乐是音乐爱好者的集聚地,云音乐推荐系统致力于通过 AI 算法的落地,实现用户千人千面的个性化推荐,为用户带来不一样的听歌体验。 本次分享重点介绍 AI 算法在音乐推荐中的应用实践,以及在算法落地过程中遇到的挑战和解决方案。 将从如下两个部分展开: AI算法在音乐推荐中的应用 音乐场景下的 AI 思考 从 2013 年 4 月正式上线至今,网易云音乐平台持续提供着:乐屏社区、UGC...
【技巧总结】位运算装逼指南
位算法的效率有多快我就不说,不信你可以去用 10 亿个数据模拟一下,今天给大家讲一讲位运算的一些经典例子。不过,最重要的不是看懂了这些例子就好,而是要在以后多去运用位运算这些技巧,当然,采用位运算,也是可以装逼的,不信,你往下看。我会从最简单的讲起,一道比一道难度递增,不过居然是讲技巧,那么也不会太难,相信你分分钟看懂。 判断奇偶数 判断一个数是基于还是偶数,相信很多人都做过,一般的做法的代码如下...
【管理系统课程设计】美少女手把手教你后台管理
【文章后台管理系统】URL设计与建模分析+项目源码+运行界面 栏目管理、文章列表、用户管理、角色管理、权限管理模块(文章最后附有源码) 1. 这是一个什么系统? 1.1 学习后台管理系统的原因 随着时代的变迁,现如今各大云服务平台横空出世,市面上有许多如学生信息系统、图书阅读系统、停车场管理系统等的管理系统,而本人家里就有人在用烟草销售系统,直接在网上完成挑选、购买与提交收货点,方便又快捷。 试想,若没有烟草销售系统,本人家人想要购买烟草,还要独自前往药...
8年经验面试官详解 Java 面试秘诀
作者 |胡书敏 责编 | 刘静 出品 | CSDN(ID:CSDNnews) 本人目前在一家知名外企担任架构师,而且最近八年来,在多家外企和互联网公司担任Java技术面试官,前后累计面试了有两三百位候选人。在本文里,就将结合本人的面试经验,针对Java初学者、Java初级开发和Java开发,给出若干准备简历和准备面试的建议。 Java程序员准备和投递简历的实...
面试官如何考察你的思维方式?
1.两种思维方式在求职面试中,经常会考察这种问题:北京有多少量特斯拉汽车?某胡同口的煎饼摊一年能卖出多少个煎饼?深圳有多少个产品经理?一辆公交车里能装下多少个乒乓球?一个正常成年人有多少根头发?这类估算问题,被称为费米问题,是以科学家费米命名的。为什么面试会问这种问题呢?这类问题能把两类人清楚地区分出来。一类是具有文科思维的人,擅长赞叹和模糊想象,它主要依靠的是人的第一反应和直觉,比如小孩...
碎片化的时代,如何学习
今天周末,和大家聊聊学习这件事情。 在如今这个社会,我们的时间被各类 APP 撕的粉碎。 刷知乎、刷微博、刷朋友圈; 看论坛、看博客、看公号; 等等形形色色的信息和知识获取方式一个都不错过。 貌似学了很多,但是却感觉没什么用。 要解决上面这些问题,首先要分清楚一点,什么是信息,什么是知识。 那什么是信息呢? 你一切听到的、看到的,都是信息,比如微博上的明星出轨、微信中的表情大战、抖音上的...
so easy! 10行代码写个"狗屁不通"文章生成器
前几天,GitHub 有个开源项目特别火,只要输入标题就可以生成一篇长长的文章。 背后实现代码一定很复杂吧,里面一定有很多高深莫测的机器学习等复杂算法 不过,当我看了源代码之后 这程序不到50行 尽管我有多年的Python经验,但我竟然一时也没有看懂 当然啦,原作者也说了,这个代码也是在无聊中诞生的,平时撸码是不写中文变量名的, 中文...
相关热词 c# 输入ip c# 乱码 报表 c#选择结构应用基本算法 c# 收到udp包后回包 c#oracle 头文件 c# 序列化对象 自定义 c# tcp 心跳 c# ice连接服务端 c# md5 解密 c# 文字导航控件
立即提问

相似问题

2
mapper.xml报找不到对应的实体类
4
关于mybatis引用mapper.xml文件的路径问题
6
MybatisPlus中在mapper.xml中编写原生sql
2
Mapper.xml传一个带<where><if>标签的sql,解析不了,怎么解决,急!!
2
apringtask项目使用ssm框架但是并没有使用到mvc项目运行后报很多错 是配置文件有问题嚒
4
Mapper.xml中的like查询里怎么拼接多个查询条件?
3
springboot项目中使用了mybatisplus的baseMapper中的方法,却提示报错自己的mapper中没有这个方法
2
mapper.xml文件怎么实现多条件查询?
2
hibernate.cfg.xml中的mapper配置程序无法识别
3
spring+mybatis,mybatis的mapper.xml配置文件里面有数据库字段错误,为什么tomcat还能正常启动 ?
6
springboot+mybatis+idea报错Invalid bound statement (not found): XXX
3
mapper.xml中 <foreach>遍历List问题
1
请教一下,到底我的mapper.xml哪里出错了,弄不明白为什么找不到我写的log类
2
新手ssm整合报以下错误,求大神解答?
2
使用IntelliJ IDEA开发的maven项目,ssm框架
3
Mybatis生成的实体类和Mapper.java类报错
2
springboot 整合mybatis 报错提示包扫描不进去
1
在做一个淘淘商城的项目,出现了子项目pom.xml报错的问题
2
org.apache.ibatis.binding.BindingException: Mapper method 'com.easy.demo.mapper.UserMapper.loginUser attempted to return null from a method with a primitive return type (int).报错怎么解决?
2
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.cqgcxy.ols.mapper.UserMapper.userRegister?