zoukankan      html  css  js  c++  java
  • mybatis程序容易出错的地方

    1、连接数据库的url地址问题:

      

     数据是查出来了,但是报一些红色的错误,看着很难受:

     要给连接数据库的url加上useSSL=trur;

    "jdbc:mysql://localhost:3306/mybatis?useSSL=true&useUnicode=true&characterEncoding=UTF-8"

     2、找不到mybatis-config.xml

    第一种解决方法:将接口实现类(.xml文件)放到resources(资源)目录下:

     第二种解决方法:

    没有放在了resources目录下,就需要在pom.xml中指定,能够找到这个文件:

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

     3、编写dao层业务接口(建议加上@Param)

    public interface UserDao {
        /**
         * 分页查询
         */
        List<User> getPageByLimit(@Param("map") Map<String, Integer> map);
        /**
         * 分页查询的第二种方式
         */
        List<User> getLimit(@Param("id1") Integer id1, @Param("id2") Integer id2);
    }
    • @Param是MyBatis所提供的(org.apache.ibatis.annotations.Param),
    • 作为Dao层的注解,作用是用于传递参数,从而可以与SQL中的的字段名相对应,一般在2=<参数数<=5时使用最佳。
    • @Param是地处Dao层,是为了传递多个参数,解决的是可读性和直观性;
  • 相关阅读:
    hdoj1251 统计难题 字典树
    nyoj322 sort 归并排序,树状数组
    优先队列 如何使用
    字典树(讲解+模版)
    hdoj1069 Monkey and Banana
    ny10 skilng
    hdoj1075 What Are You Talking About
    hdoj1171 Big Event in HDU
    ny613 免费馅饼
    Spring Boot2.0之Admin-UI分布式微服务监控中心
  • 原文地址:https://www.cnblogs.com/zhangzhixi/p/14197360.html
Copyright © 2011-2022 走看看