mybatis通用Mapper,第一次请求结果空指针,刷新又好了? 400 报错
这是我的mybatis配置
@Configuration
public class MybatisConfig {
@Bean
public SqlSessionFactory sqlSessionFactoryBean(DataSource dataSource) throws Exception {
SqlSessionFactoryBean factory = new SqlSessionFactoryBean();
factory.setDataSource(dataSource);
factory.setTypeAliasesPackage(ProjectConstant.DOMAIN_PACKAGE);
// 配置分页插件,详情请查阅官方文档
PageHelper pageHelper = new PageHelper();
Properties properties = new Properties();
properties.setProperty("pageSizeZero", "true"); // 分页尺寸为0时查询所有纪录不再执行分页
properties.setProperty("reasonable", "true"); // 页码<=0 查询第一页,页码>=总页数查询最后一页
properties.setProperty("supportMethodsArguments", "true"); // 支持通过 Mapper 接口参数来传递分页参数
pageHelper.setProperties(properties);
// 添加插件
factory.setPlugins(new Interceptor[]{pageHelper});
// 添加XML目录
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
factory.setMapperLocations(resolver.getResources("classpath*:mybatis/mapper/*.xml"));
return factory.getObject();
}
@Bean
public MapperScannerConfigurer mapperScannerConfigurer() {
MapperScannerConfigurer mapperScannerConfigurer = new MapperScannerConfigurer();
mapperScannerConfigurer.setSqlSessionFactoryBeanName("sqlSessionFactoryBean");
mapperScannerConfigurer.setBasePackage(ProjectConstant.MAPPER_PACKAGE);
// 配置通用Mapper,详情请查阅官方文档
Properties properties = new Properties();
properties.setProperty("`", ProjectConstant.MAPPER_INTERFACE_REFERENCE);
properties.setProperty("notEmpty", "false"); // insert、update是否判断字符串类型!='' 即 test="str != null"表达式内是否追加 and str != ''
properties.setProperty("IDENTITY", "MYSQL");
mapperScannerConfigurer.setProperties(properties);
return mapperScannerConfigurer;
}
}
这是启动类
@SpringBootApplication
@ComponentScan(basePackages = "com.uhope.rl")
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
/**
* 解决页面跨域访问问题
* @return FilterRegistrationBean
*/
@Bean
public FilterRegistrationBean omsFilter() {
FilterRegistrationBean registration = new FilterRegistrationBean();
registration.setFilter(new ServiceFilter());
registration.addUrlPatterns("/*");
//registration.addInitParameter("paramName", "paramValue");
registration.setName("MyFilter");
registration.setOrder(1);
return registration;
}
}
BUG是这样的,重启项目之后,前端第一次请求,我后台就崩了,报空指针,前端刷新一下发送第二次请求,我这里又都好了没有了空指针,DEBUG过了,每次参数都是有的,不会有参数不存在的问题,如果是我SQL代码问题,那第二次请求肯定也是空,所以排除了,下面是我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.uhope.rl.project.mapper.PmProjectMapper">
<resultMap id="BaseResultMap" type="com.uhope.rl.project.domain.PmProject">
<!--
WARNING - @mbg.generated
-->
<id column="ID" jdbcType="VARCHAR" property="id" />
<result column="RECVER" jdbcType="BIGINT" property="recver" />
<result column="COMPONENTID" jdbcType="VARCHAR" property="componentid" />
<result column="NAME" jdbcType="VARCHAR" property="name" />
<result column="CONSTRUCTIONCONTENT" jdbcType="VARCHAR" property="constructioncontent" />
<result column="PARENTS" jdbcType="VARCHAR" property="parents" />
<result column="PROJECTTARGET" jdbcType="VARCHAR" property="projecttarget" />
<result column="PROJECTSTATUS" jdbcType="VARCHAR" property="projectstatus" />
<result column="INVESTMENTTYPE" jdbcType="INTEGER" property="investmenttype" />
<result column="TOTALINVESTMENT" jdbcType="DOUBLE" property="totalinvestment" />
<result column="INSPECTERID" jdbcType="VARCHAR" property="inspecterid" />
<result column="RIVERID" jdbcType="VARCHAR" property="riverid" />
<result column="RIVERNAME" jdbcType="VARCHAR" property="rivername" />
<result column="PLANSTARTTIME" jdbcType="TIMESTAMP" property="planstarttime" />
<result column="PLANENDTIME" jdbcType="TIMESTAMP" property="planendtime" />
<result column="STARTTIME" jdbcType="TIMESTAMP" property="starttime" />
<result column="ENDTIME" jdbcType="TIMESTAMP" property="endtime" />
<result column="PROGRESS" jdbcType="DOUBLE" property="progress" />
<result column="VISUALIZEPROGRESS" jdbcType="DOUBLE" property="visualizeprogress" />
<result column="CREATETIME" jdbcType="TIMESTAMP" property="createtime" />
<result column="CREATEUSER" jdbcType="VARCHAR" property="createuser" />
<result column="MODIFYTIME" jdbcType="TIMESTAMP" property="modifytime" />
<result column="MODIFYUSER" jdbcType="VARCHAR" property="modifyuser" />
<result column="AUDITUSERID" jdbcType="VARCHAR" property="audituserid" />
<result column="AUDITTIME" jdbcType="TIMESTAMP" property="audittime" />
<result column="AUDITSUGGESTION" jdbcType="VARCHAR" property="auditsuggestion" />
<result column="AUDITSTATUS" jdbcType="INTEGER" property="auditstatus" />
<result column="RESPONSIBILITYUNIT" jdbcType="VARCHAR" property="responsibilityunit" />
<result column="CONSTRUCTIONUNITCONTACTER" jdbcType="VARCHAR" property="constructionunitcontacter" />
<result column="CONSTRUCTIONUNITCONTACTERTEL" jdbcType="VARCHAR" property="constructionunitcontactertel" />
<result column="CONSTRUCTIONUNITNAME" jdbcType="VARCHAR" property="constructionunitname" />
<result column="CONSTRUCTIONUNITADDRESS" jdbcType="VARCHAR" property="constructionunitaddress" />
<result column="SUPERVISIONUNITCONTACTER" jdbcType="VARCHAR" property="supervisionunitcontacter" />
<result column="SUPERVISIONUNITCONTACTERTEL" jdbcType="VARCHAR" property="supervisionunitcontactertel" />
<result column="SUPERVISIONUNITNAME" jdbcType="VARCHAR" property="supervisionunitname" />
<result column="SUPERVISIONUNITADDRESS" jdbcType="VARCHAR" property="supervisionunitaddress" />
<result column="PRINCIPAL" jdbcType="VARCHAR" property="principal" />
<result column="PRINCIPALID" jdbcType="VARCHAR" property="principalid" />
<result column="longitude" jdbcType="DOUBLE" property="longitude" />
<result column="latitude" jdbcType="DOUBLE" property="latitude" />
<result column="province_id" jdbcType="BIGINT" property="provinceId" />
<result column="city_id" jdbcType="BIGINT" property="cityId" />
<result column="county_id" jdbcType="BIGINT" property="countyId" />
<result column="town_id" jdbcType="BIGINT" property="townId" />
<result column="village_id" jdbcType="BIGINT" property="villageId" />
<result column="main_class_id" jdbcType="VARCHAR" property="mainClassId" />
<result column="sub_class_id" jdbcType="VARCHAR" property="subClassId" />
<result column="main_class_name" jdbcType="VARCHAR" property="mainClassName" />
<result column="sub_class_name" jdbcType="VARCHAR" property="subClassName" />
<result column="source" jdbcType="INTEGER" property="source" />
<result column="status" jdbcType="INTEGER" property="status" />
<result column="provin_cereach" jdbcType="VARCHAR" property="provinCereach" />
<result column="city_reach" jdbcType="VARCHAR" property="cityReach" />
<result column="county_reach" jdbcType="VARCHAR" property="countyReach" />
<result column="town_reach" jdbcType="VARCHAR" property="townReach" />
<result column="village_reach" jdbcType="VARCHAR" property="villageReach" />
<result column="writey_type" jdbcType="CHAR" property="writeyType" />
<result column="comp_level" jdbcType="INTEGER" property="compLevel" />
<result column="management_unit_return" jdbcType="VARCHAR" property="managementUnitReturn" />
<result column="the_total_project" jdbcType="DOUBLE" property="theTotalProject" />
<result column="enact_project_date" jdbcType="TIMESTAMP" property="enactProjectDate" />
<result column="provin_reach_length" jdbcType="DOUBLE" property="provinReachLength" />
<result column="city_reach_length" jdbcType="DOUBLE" property="cityReachLength" />
<result column="arithmetical_unit" jdbcType="VARCHAR" property="arithmeticalUnit" />
<result column="principal_unit" jdbcType="VARCHAR" property="principalUnit" />
<result column="reach_id" jdbcType="VARCHAR" property="reachId" />
<result column="reach_name" jdbcType="VARCHAR" property="reachName" />
<result column="target_one" jdbcType="DOUBLE" property="targetOne" />
<result column="target_one_unit" jdbcType="VARCHAR" property="targetOneUnit" />
<result column="target_two" jdbcType="DOUBLE" property="targetTwo" />
<result column="target_two_unit" jdbcType="VARCHAR" property="targetTwoUnit" />
<result column="principal_tel" jdbcType="VARCHAR" property="principalTel" />
<result column="import_no" jdbcType="VARCHAR" property="importNo" />
<result column="basinid" jdbcType="VARCHAR" property="basinid" />
<result column="basintype" jdbcType="VARCHAR" property="basintype" />
<result column="basinname" jdbcType="VARCHAR" property="basinname" />
<result column="srcid" jdbcType="VARCHAR" property="srcid" />
<result column="section" jdbcType="VARCHAR" property="section" />
<result column="sectionid" jdbcType="VARCHAR" property="sectionid" />
<result column="teskType" jdbcType="VARCHAR" property="tesktype" />
<result column="isInferIorV" jdbcType="INTEGER" property="isinferiorv" />
<result column="unithz" jdbcType="VARCHAR" property="unithz" />
<result column="unithzid" jdbcType="VARCHAR" property="unithzid" />
<result column="inferiorV_water_level" jdbcType="INTEGER" property="inferiorvWaterLevel" />
<result column="inferiorV_water_name" jdbcType="VARCHAR" property="inferiorvWaterName" />
<result column="inferiorV_water_no" jdbcType="VARCHAR" property="inferiorvWaterNo" />
<result column="uploadtime" jdbcType="TIMESTAMP" property="uploadtime" />
<result column="src" jdbcType="VARCHAR" property="src" />
</resultMap>
<resultMap id="ResultMap" type="com.uhope.rl.project.dto.PmProjectDTO">
<!--
WARNING - @mbg.generated
-->
<id column="ID" jdbcType="VARCHAR" property="id" />
<result column="RECVER" jdbcType="BIGINT" property="recver" />
<result column="COMPONENTID" jdbcType="VARCHAR" property="componentid" />
<result column="NAME" jdbcType="VARCHAR" property="name" />
<result column="CONSTRUCTIONCONTENT" jdbcType="VARCHAR" property="constructioncontent" />
<result column="PARENTS" jdbcType="VARCHAR" property="parents" />
<result column="PROJECTTARGET" jdbcType="VARCHAR" property="projecttarget" />
<result column="PROJECTSTATUS" jdbcType="VARCHAR" property="projectstatus" />
<result column="INVESTMENTTYPE" jdbcType="INTEGER" property="investmenttype" />
<result column="TOTALINVESTMENT" jdbcType="DOUBLE" property="totalinvestment" />
<result column="INSPECTERID" jdbcType="VARCHAR" property="inspecterid" />
<result column="RIVERID" jdbcType="VARCHAR" property="riverid" />
<result column="RIVERNAME" jdbcType="VARCHAR" property="rivername" />
<result column="PLANSTARTTIME" jdbcType="TIMESTAMP" property="planstarttime" />
<result column="PLANENDTIME" jdbcType="TIMESTAMP" property="planendtime" />
<result column="STARTTIME" jdbcType="TIMESTAMP" property="starttime" />
<result column="ENDTIME" jdbcType="TIMESTAMP" property="endtime" />
<result column="PROGRESS" jdbcType="DOUBLE" property="progress" />
<result column="VISUALIZEPROGRESS" jdbcType="DOUBLE" property="visualizeprogress" />
<result column="CREATETIME" jdbcType="TIMESTAMP" property="createtime" />
<result column="CREATEUSER" jdbcType="VARCHAR" property="createuser" />
<result column="MODIFYTIME" jdbcType="TIMESTAMP" property="modifytime" />
<result column="MODIFYUSER" jdbcType="VARCHAR" property="modifyuser" />
<result column="AUDITUSERID" jdbcType="VARCHAR" property="audituserid" />
<result column="AUDITTIME" jdbcType="TIMESTAMP" property="audittime" />
<result column="AUDITSUGGESTION" jdbcType="VARCHAR" property="auditsuggestion" />
<result column="AUDITSTATUS" jdbcType="INTEGER" property="auditstatus" />
<result column="RESPONSIBILITYUNIT" jdbcType="VARCHAR" property="responsibilityunit" />
<result column="CONSTRUCTIONUNITCONTACTER" jdbcType="VARCHAR" property="constructionunitcontacter" />
<result column="CONSTRUCTIONUNITCONTACTERTEL" jdbcType="VARCHAR" property="constructionunitcontactertel" />
<result column="CONSTRUCTIONUNITNAME" jdbcType="VARCHAR" property="constructionunitname" />
<result column="CONSTRUCTIONUNITADDRESS" jdbcType="VARCHAR" property="constructionunitaddress" />
<result column="SUPERVISIONUNITCONTACTER" jdbcType="VARCHAR" property="supervisionunitcontacter" />
<result column="SUPERVISIONUNITCONTACTERTEL" jdbcType="VARCHAR" property="supervisionunitcontactertel" />
<result column="SUPERVISIONUNITNAME" jdbcType="VARCHAR" property="supervisionunitname" />
<result column="SUPERVISIONUNITADDRESS" jdbcType="VARCHAR" property="supervisionunitaddress" />
<result column="PRINCIPAL" jdbcType="VARCHAR" property="principal" />
<result column="PRINCIPALID" jdbcType="VARCHAR" property="principalid" />
<result column="longitude" jdbcType="DOUBLE" property="longitude" />
<result column="latitude" jdbcType="DOUBLE" property="latitude" />
<result column="province_id" jdbcType="BIGINT" property="provinceId" />
<result column="city_id" jdbcType="BIGINT" property="cityId" />
<result column="county_id" jdbcType="BIGINT" property="countyId" />
<result column="town_id" jdbcType="BIGINT" property="townId" />
<result column="village_id" jdbcType="BIGINT" property="villageId" />
<result column="main_class_id" jdbcType="VARCHAR" property="mainClassId" />
<result column="sub_class_id" jdbcType="VARCHAR" property="subClassId" />
<result column="main_class_name" jdbcType="VARCHAR" property="mainClassName" />
<result column="sub_class_name" jdbcType="VARCHAR" property="subClassName" />
<result column="source" jdbcType="INTEGER" property="source" />
<result column="status" jdbcType="INTEGER" property="status" />
<result column="provin_cereach" jdbcType="VARCHAR" property="provinCereach" />
<result column="city_reach" jdbcType="VARCHAR" property="cityReach" />
<result column="county_reach" jdbcType="VARCHAR" property="countyReach" />
<result column="town_reach" jdbcType="VARCHAR" property="townReach" />
<result column="village_reach" jdbcType="VARCHAR" property="villageReach" />
<result column="writey_type" jdbcType="CHAR" property="writeyType" />
<result column="comp_level" jdbcType="INTEGER" property="compLevel" />
<result column="management_unit_return" jdbcType="VARCHAR" property="managementUnitReturn" />
<result column="the_total_project" jdbcType="DOUBLE" property="theTotalProject" />
<result column="enact_project_date" jdbcType="TIMESTAMP" property="enactProjectDate" />
<result column="provin_reach_length" jdbcType="DOUBLE" property="provinReachLength" />
<result column="city_reach_length" jdbcType="DOUBLE" property="cityReachLength" />
<result column="arithmetical_unit" jdbcType="VARCHAR" property="arithmeticalUnit" />
<result column="principal_unit" jdbcType="VARCHAR" property="principalUnit" />
<result column="reach_id" jdbcType="VARCHAR" property="reachId" />
<result column="reach_name" jdbcType="VARCHAR" property="reachName" />
<result column="target_one" jdbcType="DOUBLE" property="targetOne" />
<result column="target_one_unit" jdbcType="VARCHAR" property="targetOneUnit" />
<result column="target_two" jdbcType="DOUBLE" property="targetTwo" />
<result column="target_two_unit" jdbcType="VARCHAR" property="targetTwoUnit" />
<result column="principal_tel" jdbcType="VARCHAR" property="principalTel" />
<result column="import_no" jdbcType="VARCHAR" property="importNo" />
<result column="basinid" jdbcType="VARCHAR" property="basinid" />
<result column="basintype" jdbcType="VARCHAR" property="basintype" />
<result column="basinname" jdbcType="VARCHAR" property="basinname" />
<result column="srcid" jdbcType="VARCHAR" property="srcid" />
<result column="section" jdbcType="VARCHAR" property="section" />
<result column="sectionid" jdbcType="VARCHAR" property="sectionid" />
<result column="teskType" jdbcType="VARCHAR" property="tesktype" />
<result column="isInferIorV" jdbcType="INTEGER" property="isinferiorv" />
<result column="unithz" jdbcType="VARCHAR" property="unithz" />
<result column="unithzid" jdbcType="VARCHAR" property="unithzid" />
<result column="inferiorV_water_level" jdbcType="INTEGER" property="inferiorvWaterLevel" />
<result column="inferiorV_water_name" jdbcType="VARCHAR" property="inferiorvWaterName" />
<result column="inferiorV_water_no" jdbcType="VARCHAR" property="inferiorvWaterNo" />
<result column="uploadtime" jdbcType="TIMESTAMP" property="uploadtime" />
<result column="src" jdbcType="VARCHAR" property="src" />
<result column="dict_name" jdbcType="VARCHAR" property="dictName" />
<result column="INVESTMENTTYPENAME" jdbcType="VARCHAR" property="investmentTypeName" />
</resultMap>
<select id="downBox" resultMap="BaseResultMap">
SELECT NAME,ID,PRINCIPAL,PRINCIPALID,PROJECTSTATUS FROM pm_project
</select>
<select id="findByQuery" resultMap="ResultMap" parameterType="com.uhope.rl.project.dto.PmProjectDTO">
SELECT
pp.*, sd.dict_name
FROM
pm_project pp
JOIN sm_dictionary sd ON pp.PROJECTSTATUS = sd.id
<where>
<if test="name != null">AND pp.`NAME` LIKE concat('%',#{name},'%')</if>
<if test="status != null">AND pp.status = #{status}</if>
<if test="subClassName != null">AND pp.sub_class_name LIKE concat('%',#{subClassName},'%')</if>
<if test="projectstatus != null">AND pp.PROJECTSTATUS = #{projectstatus}</if>
<if test="totalinvestment != null">AND pp.TOTALINVESTMENT BETWEEN #{totalinvestment} AND #{number}</if>
</where>
</select>
</mapper>
请问有人知道这是为什么吗?
貌似错误信息没有贴出来吧######显示的就是空指针异常,参数明明都有######看看错误栈######显示的就是空指针异常,参数明明都有,但就是第一次请求不对######
大佬解决了吗,我也是一样的问题
######哪里空指针你倒是把栈堆信息贴出来啊。。。。
######org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: java.lang.NullPointerException######大佬解决了吗?我也是这个问题快崩溃了!
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。