mybatis dao层空指针异常。 5C

严重: Servlet.service() for servlet [springmvc] in context with path [/fourth] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause
java.lang.NullPointerException
at com.ssm.fourth.service.MapServiceImpl.selectAll(MapServiceImpl.java:20)
at com.ssm.fourth.controller.MapController.second(MapController.java:23)

下面是具体配置 和代码   跪求解决方法 谢谢了


web.xml
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>



springmvc
org.springframework.web.servlet.DispatcherServlet

contextConfigLocation
classpath:springmvc.xml

1


springmvc
*.action


org.springframework.web.context.ContextLoaderListener

applicationContext.xml
<context:component-scan 
base-package="com.ssm.fourth.service,com.ssm.fourth.dao"></context:component-scan>
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" value="classpath:jdbc.properties"/>
</bean>

<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/> 

<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" 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="maxWaite" value="${maxWaite}"></property> -->
</bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <property name="configLocation" value="classpath:mybaties/SqlMapConfig.xml"/>
    <!-- 自动扫描mapping.xml文件 -->
    <property name="mapperLocations" value="classpath:mapper/*.xml"/>
</bean>

<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource"/>
</bean>


springmvc.xml
<mvc:annotation-driven/>
    <context:component-scan base-package="com.ssm.fourth.controller"/>

    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/jsps/"/>
    <property name="suffix" value=".jsp"/>
</bean>


代码:
package com.ssm.fourth.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.ssm.fourth.entity.Map;
import com.ssm.fourth.service.MapService;

@Controller
@RequestMapping(value="b")
public class MapController {

@Autowired
private MapService mapService;


@RequestMapping(value="second.action")
public String second(){
    System.out.println("second");
    List<Map> list = mapService.selectAll();
    for(int i=0;i < list.size();i++){
        System.out.println(list.get(i).getLatitude());
    }
    return "second";
}

}

package com.ssm.fourth.dao;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.ssm.fourth.entity.Map;

@Repository
public interface MapDao {

public List<Map> selectAll();

}

package com.ssm.fourth.service;

import java.util.List;

import com.ssm.fourth.entity.Map;

public interface MapService {

public List<Map> selectAll();

}

package com.ssm.fourth.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.ssm.fourth.dao.MapDao;
import com.ssm.fourth.entity.Map;

@Service
public class MapServiceImpl implements MapService{

@Qualifier("mapDao")
private MapDao mapDao;

@Override
public List<Map> selectAll() {
    return this.mapDao.selectAll();
}

}

4个回答

I don't konw what it is! MyBatis's Exception: I encontered the problem of "NullPointerException" of "SqlSession" .Who caused this?
The Main bad woman is:
In The MyBatis Configuration's file(SqlMaoConfig.xml) :

<environments default="environment">  
    <environment id="environment">  

The "default" and "id" may be the same name.Or maybe NullPointerException.OK ,this is my problem and I solve that through my hands by
searching the internet. Maybe it help you.

看你程序你是在用springmvc+mybatis,但是你没有用spring完全整合mybatis。你的web.xml文件中有这样的引用吗


contextConfigLocation

/WEB-INF/config/spring-*.xml

    建议把spring和mybatis的整合在看下

你去百度搜下,肯定有意外的收获

配置文件中哪里有dao用spring注入的代码了?
@Qualifier("mapDao")
private MapDao mapDao;
这个好像是springmvc的注解,你扫描Controller包下注解,怎么能扫描到dao呢!
还有一般mybatis的mapper都是绑定到sql语句的,直接调用接口就行了,还需要配置dao?

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
mybatis 出现空指针异常

刚刚学习的mybatis 实现的是在myeclipse中输入的东西的储存在数据库中 ![报错](https://img-ask.csdn.net/upload/201608/09/1470707548_632500.png) ![图片说明](https://img-ask.csdn.net/upload/201608/09/1470707667_682542.png)![图片说明](https://img-ask.csdn.net/upload/201608/09/1470707657_14324.png)![图片说明](https://img-ask.csdn.net/upload/201608/09/1470707693_66705.png)![图片说明](https://img-ask.csdn.net/upload/201608/09/1470707705_458748.png)

mybatis单元测试空指针

![![![图片说明](https://img-ask.csdn.net/upload/201610/10/1476068010_542255.png)图片说明](https://img-ask.csdn.net/upload/201610/10/1476068030_892503.png)图片说明](https://img-ask.csdn.net/upload/201610/10/1476068022_317570.png) 总是空指针异常 查不到数据库

job调用mybatis dao层方法时报空指针错误

代码 public void addYzToken(){ String refreshToken=""; try { refreshToken=tokenDao.getLastYzToken().getRefreshToken(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println(refreshToken+"---"); } 异常信息: java.lang.NullPointerException at com.sinowel.job.RefreshTokenTask.addYzToken(RefreshTokenTask.java:113) 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.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:64) at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:53) at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:81) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) at java.util.concurrent.FutureTask.run(FutureTask.java:262) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:178) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:292) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:744) spring 配置 <!-- MyBatis SqlSessionFactory注入 --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="configLocation" value="classpath:db/sqlMapConfig.xml" /> <property name="mapperLocations" value="classpath:mybatis/com/sinowel/data/**/*.xml" /> <property name="dataSource" ref="dataSource" /> </bean> <!--MyBatis SqlSessionTemplate注入 --> <bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate"> <!-- <property name="sqlSessionFactory" ref="sqlSessionFactory" /> --> <constructor-arg index="0" ref="sqlSessionFactory"></constructor-arg> </bean> <!--自定义commonDao注入 --> <bean id="dao" class="com.sinowel.core.dao.ibatis.IbatisDao"> <property name="sqlSessionTemplate" ref="sqlSessionTemplate" /> </bean> 求大神指点

Springboot+Mybatis查询空指针

数据库字段设计 ![图片说明](https://img-ask.csdn.net/upload/201805/26/1527346499_571715.png) 实体类编写 均有get和set方法 ![图片说明](https://img-ask.csdn.net/upload/201805/26/1527346523_530253.png) dao层方法 ![图片说明](https://img-ask.csdn.net/upload/201805/26/1527346538_177283.png) 进行测试时候报错 ![图片说明](https://img-ask.csdn.net/upload/201805/26/1527346556_978861.png)

Dao层调用Mapper为什么会报空指针异常

![图片说明](https://img-ask.csdn.net/upload/201802/08/1518055499_898570.png) ``` return userMapper.getUserByName(username); ``` 这句语句出现空指针异常 userMapper.java: ![图片说明](https://img-ask.csdn.net/upload/201802/08/1518055604_637398.png) userMapper.xml: ![图片说明](https://img-ask.csdn.net/upload/201802/08/1518055633_831685.png) mapper的配置文件: ![图片说明](https://img-ask.csdn.net/upload/201802/08/1518055690_364239.png) 结构: ![图片说明](https://img-ask.csdn.net/upload/201802/08/1518055703_415794.png)

spring3+mybatis 注入空指针问题,请各位帮忙一下。

大家好,我刚学习三大框架,碰到一个空指针问题怎么都解决不了,快3天了,请帮忙下,谢谢了。 我测试所有的注入都是空指针 applicationContext.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:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:jdbc=" http://www.springframework.org/schema/jdbc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd" default-autowire="byName" default-lazy-init="false"> <!-- 开启自动扫描并注册Bean定义支持 --> <!-- <context:component-scan base-package="cn.xhf"></context:component-scan> --> <!-- 采用注释的方式配置bean --> <!-- <context:annotation-config /> --> <!-- 配置datasource源 --> <context:property-placeholder location="classpath:mysql.properties" /> <!-- 使用mysql配置属性值 --> <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="maxActive" value="${maxActive}"></property> <property name="maxIdle" value="${maxIdle}"></property> <property name="maxWait" value="${maxWait}"></property> <property name="defaultAutoCommit" value="${defaultAutoCommit}"></property> </bean> <!-- 配置sqlSessionFactory,同时制定数据源 --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="configLocation" value="classpath:Configuration.xml" /> </bean> <!-- 配置SqlSessionTemplate --> <bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate"> <constructor-arg index="0" ref="sqlSessionFactory" /> <constructor-arg index="1" value="BATCH" /> </bean> <!-- 配置dao --> <bean id="booksDao" class="cn.xhf.dao.impl.BooksDaoImpl"> <property name="sqlSession" ref="sqlSession"></property> </bean> <bean id="usersDao" class="cn.xhf.dao.impl.UsersDaoImpl"> <property name="sqlSession" ref="sqlSession"></property> </bean> <!-- 配置service --> <bean id="booksService" class="cn.xhf.service.impl.BooksServiceImpl" scope="prototype"> <property name="booksDao" ref="booksDao"></property> </bean> <bean id="usersService" class="cn.xhf.service.impl.UsersServiceImpl" scope="prototype"> <property name="usersDao" ref="usersDao"></property> </bean> <!-- 配置action --> <bean id="booksAction" class="cn.xhf.action.BooksAction" scope="prototype"> <property name="booksService" ref="booksService"></property> </bean> <bean id="usersAction" class="cn.xhf.action.UsersAction" scope="prototype"> <property name="usersService" ref="usersService"></property> </bean> <!-- 配置事务管理器 --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource" /> </bean> <!-- 通知 --> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="delete*" propagation="REQUIRED" /> <tx:method name="insert*" propagation="REQUIRED" /> <tx:method name="update*" propagation="REQUIRED" /> <tx:method name="find*" read-only="true" /> <tx:method name="get*" read-only="true" /> <tx:method name="select*" read-only="true" /> </tx:attributes> </tx:advice> <!-- 切面配置 --> <!-- <aop:config> <aop:pointcut expression="execution(* cn.xhf.service.*.*(..))" id="method" /> <aop:advisor advice-ref="txAdvice" pointcut-ref="method" /> </aop:config> --> </beans> ``` dao层 ``` package cn.xhf.dao.impl; import java.util.ArrayList; import java.util.List; import org.apache.ibatis.session.SqlSession; import org.springframework.beans.factory.annotation.Autowired; import cn.xhf.dao.BooksDao; import cn.xhf.pojo.Books; /** * */ public class BooksDaoImpl implements BooksDao { private SqlSession sqlSession; //就是这个空指针 ,其他bean也是空 @Override public int deleteBooksById(String bid) { return sqlSession.delete("books.deleteBooksById", bid); } @Override public int updataBooksById(String bid) { return sqlSession.update("books.updataBooksById", bid); } @Override public List<Books> findAll() { List<Books> booksList = new ArrayList<Books>(); booksList = sqlSession.selectList("books.findBooks"); return booksList; } @Override public List<Books> findBooksByKeyword(String bookName, String bookAuthor) { List<Books> bookList = new ArrayList<Books>(); // Books books = new Books(); // books.setBookName(bookName); // books.setBookAuthor(bookAuthor); // bookList = sqlSession.selectList("books.findBooks", books); return bookList; } @Override public int insertBooks(Books books) { return sqlSession.insert("books.insertBooks", books); } public SqlSession getSqlSession() { return sqlSession; } public void setSqlSession(SqlSession sqlSession) { this.sqlSession = sqlSession; } } ``` test方法 ``` package cn.xhf.pojo; import java.util.List; import cn.xhf.dao.BooksDao; import cn.xhf.dao.impl.BooksDaoImpl; public class TestBooks { public static void main(String[] args) { BooksDao booksDao = new BooksDaoImpl(); List<Books> list = booksDao.findAll(); System.out.println(list.size()); } } ``` 报错信息: Exception in thread "main" java.lang.NullPointerException at cn.xhf.dao.impl.BooksDaoImpl.findAll(BooksDaoImpl.java:32) at cn.xhf.pojo.TestBooks.main(TestBooks.java:11)

mybaitis springmvc整合空指针异常

这是我的web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <!-- spring mvc 配置 --> <servlet> <servlet-name>mvcdemo</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>mvcdemo</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <!-- spring 配置 --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <!-- 指定spring bean配置文件所在位置 --> <context-param> <!-- 这个是固定写法contextConfigLocation --> <param-name>contextConfigLocation</param-name> <param-value>classpath:config/applicationContext.xml</param-value> </context-param> </web-app> applicationContex.xml文件 <context:property-placeholder location="classpath:config/db.properties" /> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" p:driverClassName="${driver}" p:url="${url}" p:username="${username}" p:password="${password}" p:maxActive="10" p:maxIdle="10"> </bean> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource" /> </bean> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <!-- dataSource属性指定要用到的连接池 --> <property name="dataSource" ref="dataSource" /> <!-- configLocation属性指定mybatis的核心配置文件 --> <property name="configLocation" value="classpath:config/Configuration.xml" /> <!-- 所有配置的mapper文件 --> <property name="mapperLocations" value="classpath:mapper/*.xml"></property> </bean> <bean id="propertyMapper" class="org.mybatis.spring.mapper.MapperFactoryBean"> <property name="mapperInterface" value="wang.dao.IPropertyDao"></property> <property name="sqlSessionFactory" ref="sqlSessionFactory"></property> </bean> 这里是mvcdemo-servlet.xml文件 <context:annotation-config/> <!-- spring扫描器,用于实现bean自动载入UserController中 --> <context:component-scan base-package="wang.controller"/> <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/property/"/> <property name="suffix" value=".jsp"/> </bean> IPropertyDao层 package wang.dao; import java.util.List; import wang.model.Property; public interface IPropertyDao { public List<Property> selectProperty(); } property.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="wang.dao.IPropertyDao"> <select id="selectProperty" resultType="wang.model.Property"> select * from property </select> </mapper> 最后是controller层 package wang.controller; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import wang.dao.IPropertyDao; import wang.model.Property; @Controller @RequestMapping("/property") public class PropertyController { private IPropertyDao propertyDao; private Property property; @RequestMapping("/show") public String show(Model model){ System.out.println(propertyDao.selectProperty()); // property = propertyDao.selectProperty(); // model.addAttribute("property", property); return "/list"; } public IPropertyDao getPropertyDao() { return propertyDao; } public void setPropertyDao(IPropertyDao propertyDao) { this.propertyDao = propertyDao; } public Property getProperty() { return property; } public void setProperty(Property property) { this.property = property; } } 运行后错误500, debug发现propertyDao.selectProperty()是空的,请问大神,是哪里错啦?

使用mybatis时sqlsession总是空指针异常

我的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="mysql.properties"/> <settings> <setting name="logImpl" value="LOG4J"></setting> </settings> <typeAliases> <typeAlias alias="User" type="ssm.pojo.User" /> </typeAliases> <environments default="development"> <environment id="development"> <transactionManager type="JDBC"/> <dataSource type="POOLED"> <property name="driver" value="${driver}"/> <property name="url" value="${url}"/> <property name="username" value="${username}"/> <property name="password" value="${password}"/> </dataSource> </environment> </environments> <mappers> <mapper resource="ssm/dao/UserMapper.xml"/> </mappers> </configuration> ``` 获取session代码如下: ``` public class Test { private static SqlSessionFactory sf; static{ try { InputStream inputStream=Resources.getResourceAsStream("mybatis-config.xml"); sf= new SqlSessionFactoryBuilder().build(inputStream); } catch (Exception e) { // TODO: handle exception } } @org.junit.Test public void test() { SqlSession session=sf.openSession(false); List<User> list=session.selectList("ssm.dao.UserMapper.selectAll"); for (User user : list) { System.out.println(user.getUserName()); } } } ```

SpringMVC mybatis注入Dao层失败

BaseDaoImpl.java ``` public class BaseDaoImpl<T> extends SqlSessionDaoSupport { @Resource public void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory) { super.setSqlSessionFactory(sqlSessionFactory); } public List<QuestionOption> GetTest() { return getSqlSession().selectList("executeSql", "SELECT * FROM xxx"); } } ``` BaseDao.java ``` public interface BaseDao { public List<QuestionOption> GetTest(); } ``` QuestionBankServiceImpl.java ``` @Transactional @Service("QuestionBankService") public class QuestionBankServiceImpl implements IQuestionBankService { @Resource private IQuestionBankDao questionBankDao; public List<QuestionOption> GetTest() { List<QuestionOption> list=questionBankDao.GetTest(); return list; } } ``` spring-mvc.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: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"> <mvc:annotation-driven /> <mvc:resources location="/images/" mapping="/images/**" /> <mvc:resources location="/css/" mapping="/css/**" /> <mvc:resources location="/js/" mapping="/js/**" /> <!-- 自动扫描该包,使SpringMVC认为包下用了@controller注解的类是控制器 --> <context:component-scan base-package="com.TJ.test.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> <value>application/json;charset=UTF-8</value> </list> </property> </bean> <!-- 启动SpringMVC的注解功能,完成请求和注解POJO的映射 --> <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"> <property name="messageConverters"> <list> <ref bean="mappingJacksonHttpMessageConverter" /> <!-- JSON转换器 --> </list> </property> </bean> <!-- 定义跳转的文件的前后缀 ,视图模式配置 --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <!-- 这里的配置我的理解是自动给后面action的方法return的字符串加上前缀和后缀,变成一个 可用的url地址 --> <property name="prefix" value="/WEB-INF/jsp/" /> <property name="suffix" value=".jsp" /> </bean> <!-- 配置文件上传,如果没有使用文件上传可以不用配置,当然如果不配,那么配置文件中也不必引入上传组件包 --> <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <!-- 默认编码 --> <property name="defaultEncoding" value="utf-8" /> <!-- 文件大小最大值 --> <property name="maxUploadSize" value="10485760000" /> <!-- 内存中的最大值 --> <property name="maxInMemorySize" value="40960" /> </bean> <!-- 全局异常处理 自定义实现spring的全局异常解析器HandlerExceptionResolver --> <bean id="exceptionResolver" class="com.anyi.globallicai.mvcframework.CustomExceptionResolver"></bean> </beans> ``` spring-mybatis.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: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-4.0.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"> <!-- 自动扫描 --> <context:component-scan base-package="com.Tj.test.*" /> <!-- 引入配置文件 --> <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location" value="classpath:conf/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" /> <property name="configLocation" value="classpath:conf/mybatis-config.xml"></property> <!-- 自动扫描mapping.xml文件 --> <property name="mapperLocations" value="classpath:com/Tj/test/mapping/*.xml"></property> </bean> <!-- DAO接口所在包名,Spring会自动查找其下的类 --> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.TJ.test.dao" /> <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property> </bean> <!-- (事务管理)transaction manager, use JtaTransactionManager for global tx --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource" /> </bean> </beans> ``` BaseDao 我想写一些基础的 增删改查 然后 以后dao的每个class 直接继承 BaseDao 在Service直接调用就可以了 现在 运行调用之后 提示 Invalid bound statement (not found): com.Tj.test.dao.IQuestionBankDao.GetTest 所以怀疑没有注入成功 ![结构目录](https://img-ask.csdn.net/upload/201808/20/1534754528_778233.jpg)

SSM的serviceImpl中调用dao接口的方法报空指针异常,求大神支招

用SSM写的项目,需要实现的功能是从第三方接口获取数据,然后将数据保存到服务器上的数据库,数据获取正常,但是调用dao接口的方法是报空指针异常,请问是什么原因![![图片说明](https://img-ask.csdn.net/upload/201709/21/1505956943_524842.jpg)图片说明](https://img-ask.csdn.net/upload/201709/21/1505956934_524659.png)

spring中service层中无法autowired注入dao,报空指针异常,求助各位大神

## controller代码: @Controller public class UserController { @Autowired private UserService userService; @RequestMapping(value = "/add.action") public String add(Model model) throws Exception { userService.add(); System.out.println("controller............"); return "/WEB-INF/jsp/1.jsp"; } } ## service代码 public class UserService { @Autowired private UserDaoImpl userDao; public void add() throws Exception { userDao.add(); System.out.println("service.............."); } } ## dao代码 @Repository public class UserDaoImpl{ public void add() throws Exception { System.out.println("daoImpl.............."); } } ## spring配置文件: <?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:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <!--<context:component-scan base-package="cn.taxas.spring.dao"/>--> <bean id="userDao" class="cn.taxas.spring.dao.UserDaoImpl"/> <bean id="userService" class="cn.taxas.spring.service.UserService"/> </beans> ## springmvc配置文件; <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <mvc:annotation-driven/> <context:component-scan base-package="cn.taxas.spring.controller"> <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/> </context:component-scan> <!--<bean id="userController" class="cn.taxas.spring.controller.UserController"/>--> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"/> </beans> ## 报错: java.lang.NullPointerException at cn.taxas.spring.service.UserService.add(UserService.java:20) at cn.taxas.spring.controller.UserController.add(UserController.java:23) at sun.reflect.GeneratedMethodAccessor42.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)

mybatis已经添加了@Mapper注解,为什么测试的时候报空指针?

这个类在com.lb.springcloud.dao层下,并且添加了@Mapper ![图片说明](https://img-ask.csdn.net/upload/201909/12/1568283016_874724.png) 这是对应的xml文件 ![图片说明](https://img-ask.csdn.net/upload/201909/12/1568283096_290663.png) 测试代码如下 ![图片说明](https://img-ask.csdn.net/upload/201909/12/1568283137_724691.png) 报错 ![图片说明](https://img-ask.csdn.net/upload/201909/12/1568283155_676625.png) 真的是莫名其妙啊,求各路大神看看

利用注解注入service,会空指针异常。而用getBean方式则可以获取到service

在整合springmvc和mybatis时,在controller中注入service,无法注入,具体代码如下 @Controller public class ItemsController { @Autowired private ItemsService itemsService; @RequestMapping("/queryItems") public ModelAndView queryItems(){ if (itemsService == null) System.out.println("DDDDDDDDDDDDDDDDDD"); List<ItemsCustom> itemsList = itemsService.findItemsList(null); ModelAndView modelAndView = new ModelAndView(); modelAndView.addObject("itemsList", itemsList); modelAndView.setViewName("items/itemsList"); return modelAndView; } } public interface ItemsService { public List<ItemsCustom> findItemsList(ItemsQueryVo itemsQueryVo); } public class ItemsServiceImpl implements ItemsService { @Autowired private ItemsMapperCustom itemsMapperCustom; @Override public List<ItemsCustom> findItemsList(ItemsQueryVo itemsQueryVo){ return itemsMapperCustom.findItemsList(itemsQueryVo); } } spring的配置,已经在这里非注解的配置了service的bean <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd "> <!-- DAO部分 --> <context:property-placeholder location="classpath:db.properties" /> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName" value="${jdbc.driver}" /> <property name="url" value="${jdbc.url}" /> <property name="username" value="${jdbc.username}" /> <property name="password" value="${jdbc.password}" /> <property name="maxActive" value="30" /> <property name="maxIdle" value="5" /> </bean> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="configLocation" value="classpath:mybatis/sqlMapConfig.xml" /> </bean> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="ssm.mapper"></property> <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" /> </bean> <!-- service部分 --> <bean id="itemsService" class="ssm.service.impl.ItemsServiceImpl" /> <!-- <context:component-scan base-package="ssm.service.impl"></context:component-scan> <context:annotation-config /> --> <!-- 事务部分 --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource" /> </bean> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="save*" propagation="REQUIRED" /> <tx:method name="insert*" propagation="REQUIRED" /> <tx:method name="delete*" propagation="REQUIRED" /> <tx:method name="update*" propagation="REQUIRED" /> <tx:method name="find*" propagation="SUPPORTS" read-only="true" /> <tx:method name="select*" propagation="SUPPORTS" read-only="true" /> </tx:attributes> </tx:advice> <aop:config> <aop:advisor advice-ref="txAdvice" pointcut="execution(* ssm.service.impl.*.*(..))" /> </aop:config> </beans>

Springboot,使用@Autowired疑似注入失败,报空指针错误

项目结构: ![图片说明](https://img-ask.csdn.net/upload/202005/07/1588846375_795799.png) User类: ``` package com.test.mp.mp1111.entity; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableId; import lombok.Data; import org.springframework.stereotype.Component; @Data public class User { // @TableId(type = IdType.AUTO) private Long id; private Integer age; private String name; private String email; } ``` UserMapper: ``` package com.test.mp.mp1111.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.test.mp.mp1111.entity.User; import lombok.Data; import org.apache.ibatis.annotations.Mapper; import org.springframework.context.annotation.ComponentScan; import org.springframework.stereotype.Component; import org.springframework.stereotype.Repository; @Component public interface UserMapper extends BaseMapper<User> { } ``` Mp1111ApplicationTests: ``` package com.test.mp.mp1111; import com.test.mp.mp1111.entity.User; import com.test.mp.mp1111.mapper.UserMapper; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import java.util.List; @SpringBootTest class Mp1111ApplicationTests { @Autowired private UserMapper userMapper; @Test public void testUpdateById() { if (userMapper == null) { System.out.println("空指针"); } } } ``` 项目pom.xml ``` <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.7.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.test.mp</groupId> <artifactId>mp1111</artifactId> <version>0.0.1-SNAPSHOT</version> <name>mp1111</name> <description>Demo project for Spring Boot</description> <properties> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <!--mybatis-plus--> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>3.0.5</version> </dependency> <!--mysql--> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> <!--lombok用来简化实体类--> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> </dependency> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter</artifactId> <version>RELEASE</version> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project> ``` 我运行Mp1111ApplicationTests中的testUpdateById方法, 显示userMapper为空指针,这是为什么呀

使用spring+Mybatis 注解无效

使用spring+Mybatis,使用spring注解,一直报空指针异常,各位麻烦看看 这个spring文件 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <!-- 使用注解式注入 --> <context:annotation-config /> <context:component-scan base-package="com/springMyBatis/system/service/*"/> <context:component-scan base-package="com/springMyBatis/system/dao/*"/> <!-- 配置数据源--> <import resource="application-db.xml" /> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource"> <ref bean="jdbcDataSource" /> </property> <!-- MyBatis 的 XML 配置文件路径 --> <property name="configLocation" value="classpath:com/springMyBatis/Mybatis.xml" /> <!-- 扫描自动生成的xml文件 --><!-- Mybatis XML映射文件 --> <property name="mapperLocations"> <list><!-- Mybatis XML映射文件 --> <value>classpath*:com/springMyBatis/system/mapper/*.xml</value> </list> </property> </bean> <!-- 扫描mybatisGenerator 自动生成的 所有接口--> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com/springMyBatis/system/dao"></property> </bean> <!-- 事务管理 --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="jdbcDataSource" /> </bean> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="annotationClass" value="org.springframework.stereotype.Repository"/> <property name="basePackage" value="com.springMyBatis.system"/> <property name="sqlSessionFactory" ref="sqlSessionFactory"/> </bean> </beans> Mybatis配置文件 <?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> <settings> <!-- 全局映射器启用缓存 --> <setting name="cacheEnabled" value="false" /> <!-- 查询时,关闭关联对象即时加载以提高性能 --> <setting name="lazyLoadingEnabled" value="false" /> <!-- 设置关联对象加载的形态,此处为按需加载字段(加载字段由SQL指定),不会加载关联表的所有字段,以提高性能 --> <setting name="aggressiveLazyLoading" value="false" /> <!-- 对于未知的SQL查询,允许返回不同的结果集以达到通用的效果 --> <setting name="multipleResultSetsEnabled" value="true" /> <!-- 允许使用列标签代替列名 --> <setting name="useColumnLabel" value="true" /> <!-- 允许使用自定义的主键值(比如由程序生成的UUID 32位编码作为键值),数据表的PK生成策略将被覆盖 --> <!-- <setting name="useGeneratedKeys" value="true" /> --> <!-- 给予被嵌套的resultMap以字段-属性的映射支持 --> <!-- <setting name="autoMappingBehavior" value="FULL" /> --> <!-- 对于批量更新操作缓存SQL以提高性能 --> <setting name="defaultExecutorType" value="BATCH" /> <!-- 数据库超过25000秒仍未响应则超时 --> <!-- <setting name="defaultStatementTimeout" value="25000" /> --> </settings> </configuration> DAO层接口 package com.springMyBatis.system.dao; import java.util.List; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; import com.springMyBatis.system.model.User; @Repository @Transactional public interface UserDao { public List<User> selectAllUser(); } mapper.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="com.springMyBatis.system.dao.UserDao"> <select id="selectAllUser" resultType="com.springMyBatis.system.model.User"> select * from user </select> </mapper> service层文件 package com.springMyBatis.system.service; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.stereotype.Controller; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.springMyBatis.system.dao.UserDao; import com.springMyBatis.system.model.User; @Service public class Select { @Autowired private UserDao userdao; public List<User> selectAllUser(){ System.out.println(userdao); List<User> list=userdao.selectAllUser(); return list; } userdao一直为空,求大神指导下

求助java学习过程中使用mybatis时遇到异常报错PersistenceException

异常错误信息是 ``` Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: java.lang.NullPointerException ### The error may exist in com/briup/estore/dao/CustomerMapper.xml ### The error may involve com.briup.estore.dao.ICustomerDao.findByName ### The error occurred while executing a query ### Cause: java.lang.NullPointerException at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:122) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:113) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:73) at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:69) at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:53) at com.sun.proxy.$Proxy0.findByName(Unknown Source) at com.briup.estore.service.impl.Test.main(Test.java:21) Caused by: java.lang.NullPointerException at java.lang.String.<init>(Unknown Source) at oracle.sql.CharacterSet.AL32UTF8ToString(CharacterSet.java:1518) at oracle.jdbc.driver.DBConversion.CharBytesToString(DBConversion.java:610) at oracle.jdbc.driver.DBConversion.CharBytesToString(DBConversion.java:555) at oracle.jdbc.driver.T4CTTIoauthenticate.receiveOauth(T4CTTIoauthenticate.java:822) at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:362) at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:441) at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:165) at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:35) at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:801) at java.sql.DriverManager.getConnection(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source) at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.doGetConnection(UnpooledDataSource.java:201) at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.doGetConnection(UnpooledDataSource.java:196) at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.getConnection(UnpooledDataSource.java:93) at org.apache.ibatis.datasource.pooled.PooledDataSource.popConnection(PooledDataSource.java:385) at org.apache.ibatis.datasource.pooled.PooledDataSource.getConnection(PooledDataSource.java:89) at org.apache.ibatis.transaction.jdbc.JdbcTransaction.openConnection(JdbcTransaction.java:140) at org.apache.ibatis.transaction.jdbc.JdbcTransaction.getConnection(JdbcTransaction.java:62) at org.apache.ibatis.executor.BaseExecutor.getConnection(BaseExecutor.java:315) at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:75) at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:61) at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:303) at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:154) at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:102) at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:82) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:120) ... 6 more ``` 我使用的mybatis-config.xml和mapper.xml中的代码都没有问题,我把原代码打包都放入他人电脑中运行都能成功,而我的不行,会报上述异常,数据库用的是Oracle 10g ,编译代码的是eclipse 4.7,Oracle使用cmd命令可以使用,但是就是用mybatis的不行,有没有大佬知道这种情况的,求帮助

关于mybatis通用mapper的问题。

项目是maven管理的,用的mybatis+spring,单表的CRUD都需要手写,感觉很麻烦。于是网上找了通用mapper的配置方法。 在POM.XML加入了 <dependency> <groupId>tk.mybatis</groupId> <artifactId>mapper</artifactId> <version>${mapper.version}</version> </dependency> <dependency> <groupId>javax.persistence</groupId> <artifactId>persistence-api</artifactId> <version>1.0</version> </dependency> 这两个包配置。 然后新建了一个基本业务接口 ``` public interface BaseService<T>{ } ``` 基本业务接口的实现类: ``` @Service public abstract class BaseServiceImpl<T> implements BaseService<T> { CrBaseMapper<T> crBaseMapper; @Resource CourseMapper courseMapper; public int add(T entity, boolean insertSelective) { if (insertSelective) { return this.crBaseMapper.insertSelective(entity); } return this.crBaseMapper.insert(entity); } public int delete(T entity) { return this.crBaseMapper.deleteByPrimaryKey(entity); } public int update(T entity, boolean updateSelective) { if (updateSelective) { return this.crBaseMapper.updateByPrimaryKeySelective(entity); } return this.crBaseMapper.updateByPrimaryKey(entity); } public T get(Long pk) { return this.crBaseMapper.selectByPrimaryKey(pk); } public List<T> selectAll() { return this.crBaseMapper.selectAll(); } } ``` 然后就是基本DAO接口: ``` @Repository public abstract interface CrBaseMapper<T> extends Mapper<T> { } ``` 。 最后在applicationContext.xml也进行了如下的配置: ``` <bean class="tk.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.isea533.mybatis.mapper"/> <property name="properties"> <value> mappers=tk.mybatis.mapper.common.Mapper </value> </property> </bean> <context:component-scan base-package="com.insi.cream"/> ``` 是哪里配置有问题吗,为什么启动时候还是提示 Error creating bean with name 'crBaseMapper' defined in file? 求大神解答,感激不仅!!!!~~~~

Mybatis Plus 的 selectOne一直报错,说sql语法有问题,然而我没有进行mapper拓展啊,咋就有问题了?

![图片说明](https://img-ask.csdn.net/upload/202002/09/1581177656_966381.png) **第一张表(ItemType)一直报错,后面两张表没错误,我的数据库表设计没问题啊。** 上错误信息: ``` org.springframework.jdbc.BadSqlGrammarException: ### Error querying database. Cause: java.sql.SQLSyntaxErrorException: 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 'order FROM item_type WHERE (id = 2)' at line 1 ### The error may exist in com/kuanggong/demo/mapper/ItemTypeMapper.java (best guess) ### The error may involve defaultParameterMap ### The error occurred while setting parameters ### SQL: SELECT id,pid,type_name,order FROM item_type WHERE (id = ?) ### Cause: java.sql.SQLSyntaxErrorException: 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 'order FROM item_type WHERE (id = 2)' at line 1 ; bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: 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 'order FROM item_type WHERE (id = 2)' at line 1 at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:235) at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72) at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:88) at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:440) at com.sun.proxy.$Proxy109.selectOne(Unknown Source) at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:159) at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.execute(MybatisMapperMethod.java:108) at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:96) at com.sun.proxy.$Proxy136.selectOne(Unknown Source) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:343) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212) at com.sun.proxy.$Proxy137.selectOne(Unknown Source) at com.kuanggong.demo.DemoApplicationTests.ceshi(DemoApplicationTests.java:55) 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:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:74) at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:84) at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75) at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86) at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) 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: java.sql.SQLSyntaxErrorException: 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 'order FROM item_type WHERE (id = 2)' at line 1 at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97) at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:974) at com.mysql.cj.jdbc.ClientPreparedStatement.execute(ClientPreparedStatement.java:391) at com.alibaba.druid.pool.DruidPooledPreparedStatement.execute(DruidPooledPreparedStatement.java:494) at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:64) at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:79) 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.plugin.Plugin.invoke(Plugin.java:63) at com.sun.proxy.$Proxy189.query(Unknown Source) at com.baomidou.mybatisplus.core.executor.MybatisSimpleExecutor.doQuery(MybatisSimpleExecutor.java:67) at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:324) at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156) at com.baomidou.mybatisplus.core.executor.MybatisCachingExecutor.query(MybatisCachingExecutor.java:155) at com.baomidou.mybatisplus.core.executor.MybatisCachingExecutor.query(MybatisCachingExecutor.java:90) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:147) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:76) 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.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:426) ... 47 more ```

SSM 遇到的java.lang.NullPointerException问题

报错 java.lang.NullPointerException ** at com.archives.controller.sysmanage.DepartmentController.doPageData(DepartmentController.java:38) ** at com.archives.controller.sy****smanage.DepartmentController.initHome(DepartmentController.java:32) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:220) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:134) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:116) 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:963) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861) at javax.servlet.http.HttpServlet.service(HttpServlet.java:624) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) 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 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.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.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2517) at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2506) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:748) mapper.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="com.archives.dao.UserDeptDao"> <resultMap id="userdeptMap" type="com.archives.entity.UserDept"> <id column="deptid" property="deptid"></id> <result column="deptname" property="deptname"/> <result column="telephone" property="telephone"/> <result column="fax" property="fax"/> <result column="managerid" property="managerid"/> <result column="remark" property="remark"/> <association property="userInfo" javaType="com.archives.entity.UserInfo"> <id column="loginid" property="loginid"></id> <result column="loginname" property="loginname"/> <result column="loginpwd" property="loginpwd"/> <result column="realname" property="realname"/> <result column="roleid" property="roleid"/> <result column="leveid" property="leveid"/> <result column="cardid" property="cardid"/> <result column="dutyid" property="dutyid"/> <result column="deptid" property="deptid"/> <result column="joindate" property="joindate"/> <result column="telephone" property="telephone"/> <result column="enduid" property="enduid"/> <result column="address" property="address"/> <result column="sex" property="sex"/> </association> </resultMap> <select id="selectUserDeptCount" parameterType="com.archives.model.A0104Model" resultType="Integer"> select count(*) as cnt from userinfo,dept and userinfo.deptid = dept.deptid <if test="loginname != null and loginname.trim() != '' "> and userinfo.loginname = #{loginname} </if> <if test="realname != null and realname.trim() != '' "> and userinfo.realname = #{realname} </if> <if test="deptname != null and deptname.trim() != '' "> and dept.deptname = #{deptname} </if> </select> <select id="selectUserDeptList" parameterType="com.archives.model.A0104Model" resultMap="userdeptMap"> select userinfo.loginid , userinfo.loginname , userinfo.realname , dept.deptname , dept.deptid from userinfo,dept where userinfo.deptid = dept.deptid limit #{offsetindex},#{pageCount} </select> </mapper> controller.java文件 package com.archives.controller.sysmanage; import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import com.alibaba.fastjson.JSON; import com.archives.common.Constant; import com.archives.entity.Menu; import com.archives.entity.UserDept; import com.archives.entity.UserInfo; import com.archives.model.A0104Model; import com.archives.service.HomeService; import com.archives.service.UserDeptService; @Controller @RequestMapping("/department") public class DepartmentController { UserDeptService userdeptService; @RequestMapping("/init") public String initHome(HttpServletRequest request) { A0104Model model=new A0104Model(); model.setCurPage(1); model.setPageCount(Constant.PAGE_COUNT); 对应的错误行**doPageData(request,model);** return "department"; } private void doPageData(HttpServletRequest request, A0104Model model) { // TODO Auto-generated method stub int cnt = userdeptService.selectUserDeptCount(model); int totalPage = 0; if(cnt%Constant.PAGE_COUNT == 0) { totalPage = cnt/Constant.PAGE_COUNT; }else { totalPage = cnt/Constant.PAGE_COUNT + 1; } model.setTotalPage(totalPage); model.setOffsetindex((model.getCurPage() - 1) * Constant.PAGE_COUNT); model.setPageCount(Constant.PAGE_COUNT); 对应的错误行**List<UserDept> userdeptduiyList=userdeptService.selectUserDeptList(model);** request.setAttribute("userdeptList", userdeptList); request.setAttribute("model", model); } } model.java文件 package com.archives.model; public class A0104Model { private String loginname; private String realname; private String deptname; public String getLoginname() { return loginname; } public void setLoginname(String loginname) { this.loginname = loginname; } public String getRealname() { return realname; } public void setRealname(String realname) { this.realname = realname; } public String getDeptname() { return deptname; } public void setDeptname(String deptname) { this.deptname = deptname; } public int getCurPage() { return curPage; } public void setCurPage(int curPage) { this.curPage = curPage; } public int getTotalPage() { return totalPage; } public void setTotalPage(int totalPage) { this.totalPage = totalPage; } public int getOffsetindex() { return offsetindex; } public void setOffsetindex(int offsetindex) { this.offsetindex = offsetindex; } public int getPageCount() { return pageCount; } public void setPageCount(int pageCount) { this.pageCount = pageCount; } private int curPage; private int totalPage; private int offsetindex; private int pageCount; } Dao package com.archives.dao; import java.util.List; import com.archives.entity.UserDept; import com.archives.model.A0104Model; public interface UserDeptDao { UserDeptDao getUserDeptByName(String loginname); int selectUserDeptCount(A0104Model model); List<UserDept> selectUserDeptList(A0104Model model); } service package com.archives.service; import java.util.List; import com.archives.entity.UserDept; import com.archives.model.A0104Model; public interface UserDeptService { int selectUserDeptCount(A0104Model model); List<UserDept> selectUserDeptList(A0104Model model); } serviceImpl package com.archives.service; import java.util.List; import com.archives.dao.UserDeptDao; import com.archives.entity.UserDept; import com.archives.model.A0104Model; public class UserDeptServiceImpl implements UserDeptService { UserDeptDao userdeptDao; @Override public int selectUserDeptCount(A0104Model model) { // TODO Auto-generated method stub int cnt=userdeptDao.selectUserDeptCount(model); return cnt; } @Override public List<UserDept> selectUserDeptList(A0104Model model) { // TODO Auto-generated method stub List<UserDept> userdeptList =userdeptDao.selectUserDeptList(model); return userdeptList; } } UserDept.java package com.archives.entity; public class UserDept { private int deptid; private String deptname; private String telephone; private String fax; private String managerid; private String remark; public String getTelephone() { return telephone; } public void setTelephone(String telephone) { this.telephone = telephone; } public String getFax() { return fax; } public void setFax(String fax) { this.fax = fax; } public String getManagerid() { return managerid; } public void setManagerid(String managerid) { this.managerid = managerid; } public String getRemark() { return remark; } public void setRemark(String remark) { this.remark = remark; } public int getDeptid() { return deptid; } public void setDeptid(int deptid) { this.deptid = deptid; } public String getDeptname() { return deptname; } public void setDeptname(String deptname) { this.deptname = deptname; } public String getLoginid() { return loginid; } public void setLoginid(String loginid) { this.loginid = loginid; } public String getLoginname() { return loginname; } public void setLoginname(String loginname) { this.loginname = loginname; } public String getRealname() { return realname; } public void setRealname(String realname) { this.realname = realname; } private String loginid; private String loginname; private String realname; }

在中国程序员是青春饭吗?

今年,我也32了 ,为了不给大家误导,咨询了猎头、圈内好友,以及年过35岁的几位老程序员……舍了老脸去揭人家伤疤……希望能给大家以帮助,记得帮我点赞哦。 目录: 你以为的人生 一次又一次的伤害 猎头界的真相 如何应对互联网行业的「中年危机」 一、你以为的人生 刚入行时,拿着傲人的工资,想着好好干,以为我们的人生是这样的: 等真到了那一天,你会发现,你的人生很可能是这样的: ...

删库了,我们一定要跑路吗?

在工作中,我们误删数据或者数据库,我们一定需要跑路吗?我看未必,程序员一定要学会自救,神不知鬼不觉的将数据找回。 在 mysql 数据库中,我们知道 binlog 日志记录了我们对数据库的所有操作,所以 binlog 日志就是我们自救的利器。 接下来就来开启程序员自救之路。 想要自救成功,binlog 这把利器一定要好,在自己之前,我们一定要确定我们有 binlog 这把利器,以下就是确保有 bi...

再不跳槽,应届毕业生拿的都比我多了!

跳槽几乎是每个人职业生涯的一部分,很多HR说“三年两跳”已经是一个跳槽频繁与否的阈值了,可为什么市面上有很多程序员不到一年就跳槽呢?他们不担心影响履历吗? PayScale之前发布的**《员工最短任期公司排行榜》中,两家码农大厂Amazon和Google**,以1年和1.1年的员工任期中位数分列第二、第四名。 PayScale:员工最短任期公司排行榜 意外的是,任期中位数极小的这两家公司,薪资...

我以为我学懂了数据结构,直到看了这个导图才发现,我错了

数据结构与算法思维导图

技术大佬:我去,你写的 switch 语句也太老土了吧

昨天早上通过远程的方式 review 了两名新来同事的代码,大部分代码都写得很漂亮,严谨的同时注释也很到位,这令我非常满意。但当我看到他们当中有一个人写的 switch 语句时,还是忍不住破口大骂:“我擦,小王,你丫写的 switch 语句也太老土了吧!” 来看看小王写的代码吧,看完不要骂我装逼啊。 private static String createPlayer(PlayerTypes p...

华为初面+综合面试(Java技术面)附上面试题

华为面试整体流程大致分为笔试,性格测试,面试,综合面试,回学校等结果。笔试来说,华为的难度较中等,选择题难度和网易腾讯差不多。最后的代码题,相比下来就简单很多,一共3道题目,前2题很容易就AC,题目已经记不太清楚,不过难度确实不大。最后一题最后提交的代码过了75%的样例,一直没有发现剩下的25%可能存在什么坑。 笔试部分太久远,我就不怎么回忆了。直接将面试。 面试 如果说腾讯的面试是挥金如土...

和黑客斗争的 6 天!

互联网公司工作,很难避免不和黑客们打交道,我呆过的两家互联网公司,几乎每月每天每分钟都有黑客在公司网站上扫描。有的是寻找 Sql 注入的缺口,有的是寻找线上服务器可能存在的漏洞,大部分都...

讲一个程序员如何副业月赚三万的真实故事

loonggg读完需要3分钟速读仅需 1 分钟大家好,我是你们的校长。我之前讲过,这年头,只要肯动脑,肯行动,程序员凭借自己的技术,赚钱的方式还是有很多种的。仅仅靠在公司出卖自己的劳动时...

上班一个月,后悔当初着急入职的选择了

最近有个老铁,告诉我说,上班一个月,后悔当初着急入职现在公司了。他之前在美图做手机研发,今年美图那边今年也有一波组织优化调整,他是其中一个,在协商离职后,当时捉急找工作上班,因为有房贷供着,不能没有收入来源。所以匆忙选了一家公司,实际上是一个大型外包公司,主要派遣给其他手机厂商做外包项目。**当时承诺待遇还不错,所以就立马入职去上班了。但是后面入职后,发现薪酬待遇这块并不是HR所说那样,那个HR自...

女程序员,为什么比男程序员少???

昨天看到一档综艺节目,讨论了两个话题:(1)中国学生的数学成绩,平均下来看,会比国外好?为什么?(2)男生的数学成绩,平均下来看,会比女生好?为什么?同时,我又联想到了一个技术圈经常讨...

副业收入是我做程序媛的3倍,工作外的B面人生是怎样的?

提到“程序员”,多数人脑海里首先想到的大约是:为人木讷、薪水超高、工作枯燥…… 然而,当离开工作岗位,撕去层层标签,脱下“程序员”这身外套,有的人生动又有趣,马上展现出了完全不同的A/B面人生! 不论是简单的爱好,还是正经的副业,他们都干得同样出色。偶尔,还能和程序员的特质结合,产生奇妙的“化学反应”。 @Charlotte:平日素颜示人,周末美妆博主 大家都以为程序媛也个个不修边幅,但我们也许...

MySQL数据库面试题(2020最新版)

文章目录数据库基础知识为什么要使用数据库什么是SQL?什么是MySQL?数据库三大范式是什么mysql有关权限的表都有哪几个MySQL的binlog有有几种录入格式?分别有什么区别?数据类型mysql有哪些数据类型引擎MySQL存储引擎MyISAM与InnoDB区别MyISAM索引与InnoDB索引的区别?InnoDB引擎的4大特性存储引擎选择索引什么是索引?索引有哪些优缺点?索引使用场景(重点)...

如果你是老板,你会不会踢了这样的员工?

有个好朋友ZS,是技术总监,昨天问我:“有一个老下属,跟了我很多年,做事勤勤恳恳,主动性也很好。但随着公司的发展,他的进步速度,跟不上团队的步伐了,有点...

我入职阿里后,才知道原来简历这么写

私下里,有不少读者问我:“二哥,如何才能写出一份专业的技术简历呢?我总感觉自己写的简历太烂了,所以投了无数份,都石沉大海了。”说实话,我自己好多年没有写过简历了,但我认识的一个同行,他在阿里,给我说了一些他当年写简历的方法论,我感觉太牛逼了,实在是忍不住,就分享了出来,希望能够帮助到你。 01、简历的本质 作为简历的撰写者,你必须要搞清楚一点,简历的本质是什么,它就是为了来销售你的价值主张的。往深...

外包程序员的幸福生活

今天给你们讲述一个外包程序员的幸福生活。男主是Z哥,不是在外包公司上班的那种,是一名自由职业者,接外包项目自己干。接下来讲的都是真人真事。 先给大家介绍一下男主,Z哥,老程序员,是我十多年前的老同事,技术大牛,当过CTO,也创过业。因为我俩都爱好喝酒、踢球,再加上住的距离不算远,所以一直也断断续续的联系着,我对Z哥的状况也有大概了解。 Z哥几年前创业失败,后来他开始干起了外包,利用自己的技术能...

现代的 “Hello, World”,可不仅仅是几行代码而已

作者 |Charles R. Martin译者 | 弯月,责编 | 夕颜头图 |付费下载自视觉中国出品 | CSDN(ID:CSDNnews)新手...

!大部分程序员只会写3年代码

如果世界上都是这种不思进取的软件公司,那别说大部分程序员只会写 3 年代码,恐怕就没有程序员这种职业。

离职半年了,老东家又发 offer,回不回?

有小伙伴问松哥这个问题,他在上海某公司,在离职了几个月后,前公司的领导联系到他,希望他能够返聘回去,他很纠结要不要回去? 俗话说好马不吃回头草,但是这个小伙伴既然感到纠结了,我觉得至少说明了两个问题:1.曾经的公司还不错;2.现在的日子也不是很如意。否则应该就不会纠结了。 老实说,松哥之前也有过类似的经历,今天就来和小伙伴们聊聊回头草到底吃不吃。 首先一个基本观点,就是离职了也没必要和老东家弄的苦...

HTTP与HTTPS的区别

面试官问HTTP与HTTPS的区别,我这样回答让他竖起大拇指!

程序员毕业去大公司好还是小公司好?

虽然大公司并不是人人都能进,但我仍建议还未毕业的同学,尽力地通过校招向大公司挤,但凡挤进去,你这一生会容易很多。 大公司哪里好?没能进大公司怎么办?答案都在这里了,记得帮我点赞哦。 目录: 技术氛围 内部晋升与跳槽 啥也没学会,公司倒闭了? 不同的人脉圈,注定会有不同的结果 没能去大厂怎么办? 一、技术氛围 纵观整个程序员技术领域,哪个在行业有所名气的大牛,不是在大厂? 而且众所...

男生更看重女生的身材脸蛋,还是思想?

往往,我们看不进去大段大段的逻辑。深刻的哲理,往往短而精悍,一阵见血。问:产品经理挺漂亮的,有点心动,但不知道合不合得来。男生更看重女生的身材脸蛋,还是...

程序员为什么千万不要瞎努力?

本文作者用对比非常鲜明的两个开发团队的故事,讲解了敏捷开发之道 —— 如果你的团队缺乏统一标准的环境,那么即使勤劳努力,不仅会极其耗时而且成果甚微,使用...

为什么程序员做外包会被瞧不起?

二哥,有个事想询问下您的意见,您觉得应届生值得去外包吗?公司虽然挺大的,中xx,但待遇感觉挺低,马上要报到,挺纠结的。

当HR压你价,说你只值7K,你该怎么回答?

当HR压你价,说你只值7K时,你可以流畅地回答,记住,是流畅,不能犹豫。 礼貌地说:“7K是吗?了解了。嗯~其实我对贵司的面试官印象很好。只不过,现在我的手头上已经有一份11K的offer。来面试,主要也是自己对贵司挺有兴趣的,所以过来看看……”(未完) 这段话主要是陪HR互诈的同时,从公司兴趣,公司职员印象上,都给予对方正面的肯定,既能提升HR的好感度,又能让谈判气氛融洽,为后面的发挥留足空间。...

面试阿里p7,被按在地上摩擦,鬼知道我经历了什么?

面试阿里p7被问到的问题(当时我只知道第一个):@Conditional是做什么的?@Conditional多个条件是什么逻辑关系?条件判断在什么时候执...

终于懂了TCP和UDP协议区别

终于懂了TCP和UDP协议区别

无代码时代来临,程序员如何保住饭碗?

编程语言层出不穷,从最初的机器语言到如今2500种以上的高级语言,程序员们大呼“学到头秃”。程序员一边面临编程语言不断推陈出新,一边面临由于许多代码已存在,程序员编写新应用程序时存在重复“搬砖”的现象。 无代码/低代码编程应运而生。无代码/低代码是一种创建应用的方法,它可以让开发者使用最少的编码知识来快速开发应用程序。开发者通过图形界面中,可视化建模来组装和配置应用程序。这样一来,开发者直...

面试了一个 31 岁程序员,让我有所触动,30岁以上的程序员该何去何从?

最近面试了一个31岁8年经验的程序猿,让我有点感慨,大龄程序猿该何去何从。

大三实习生,字节跳动面经分享,已拿Offer

说实话,自己的算法,我一个不会,太难了吧

程序员垃圾简历长什么样?

已经连续五年参加大厂校招、社招的技术面试工作,简历看的不下于万份 这篇文章会用实例告诉你,什么是差的程序员简历! 疫情快要结束了,各个公司也都开始春招了,作为即将红遍大江南北的新晋UP主,那当然要为小伙伴们做点事(手动狗头)。 就在公众号里公开征简历,义务帮大家看,并一一点评。《启舰:春招在即,义务帮大家看看简历吧》 一石激起千层浪,三天收到两百多封简历。 花光了两个星期的所有空闲时...

立即提问
相关内容推荐