遇见问题汇总

1. 当项目启动时,启动失败并提示端口被占用

使用Shell指令查看端口占用:
netstat -ano | findstr 端口号
得到该端口的PID,在任务管理器将其结束。

2. Maven项目的XML文件扫描问题

错误提示:

## Error building SqlSession.The error may exist in com.hmt.dao/UserMapper.xml

## Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.io.IOException: Could not find resource com.hmt.dao/UserMapper.xml

解决方案

<build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
                <filtering>true</filtering>
            </resource>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
                <filtering>true</filtering>
            </resource>
        </resources>
    </build>

3. JDBC连接数据库失败问题

属于时区问题

注意:mysql版本大于8的必须设置时区

解决方案:

URL处添加时区:ServerTimeZone(不修改数据时区)

url:
jdbc:mysql://localhost:3306/mybatis?useSSL=true
&useUnicode=true
&characterEncoding=utf-8
&serverTimezone=GMT%2B8

// GMT+8, 加号在URL中必须被编码,成了%2B.

也可以通过修改数据库文件,修改时区

4. MySQL数据库不兼容only_full_group_by的SQL模式

mysql默认:
		sql_mode=only_full_group_by
	修改:
		set @@global.sql_mode ='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';

5. Tomcat出现中文乱码

在Tomcat的配置中的VM option加
	-Dconsole.encoding=UTF-8 -Dfile.encoding=UTF-8

6. springMVC的SpringMVC-Servlet(内含jackson的中文乱码)

方法一:

<?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:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/context
       https://www.springframework.org/schema/context/spring-context.xsd
       http://www.springframework.org/schema/mvc
       https://www.springframework.org/schema/mvc/spring-mvc.xsd">
        <context:component-scan base-package="com.hmt.controller"/>
        <mvc:annotation-driven>
		<!--解决JSON数据中文乱码问题-->
                <mvc:message-converters register-defaults="true">
                        <bean class="org.springframework.http.converter.StringHttpMessageConverter">
                                <constructor-arg value="UTF-8"/>
                        </bean>
                        <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
                                <property name="objectMapper">
                                        <bean class="org.springframework.http.converter.json.Jackson2ObjectMapperFactoryBean">
                                                <property name="failOnEmptyBeans" value="false"/>
                                        </bean>
                                </property>
                        </bean>
                </mvc:message-converters>
        </mvc:annotation-driven>
        <mvc:default-servlet-handler/>

        <!-- 视图解析器 -->
        <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"
              id="internalResourceViewResolver">
        <!-- 前缀 -->
        <property name="prefix" value="/WEB-INF/jsp/" />
        <!-- 后缀 -->
        <property name="suffix" value=".jsp" />
        </bean>
</beans>

方法二:

在Controller层中的RequestMapping中加:

@RequestMapping(value = “/t1”,produces = “application/json;charset=utf-8”)

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值