zoukankan      html  css  js  c++  java
  • FT网站开发过程遇到的问题汇总

    1.jar包不兼容问题。主要是mybatis,spring jar包不兼容。同时jstl标签也需要jar包,是jstl.jar,standard.jar。

    2.mybatis的mapper.xml映射文件,传入多个参数问题

    第一种方案 

    DAO层的函数方法 

    1. Public User selectUser(String name,String area);  

    对应的Mapper.xml  

    1. <select id="selectUser" resultMap="BaseResultMap">  
    2.     select  *  from user_user_t   where user_name = #{0} and user_area=#{1}  
    3. </select>  

    其中,#{0}代表接收的是dao层中的第一个参数,#{1}代表dao层中第二参数,更多参数一致往后加即可。

    第二种方案

    此方法采用Map传多参数.

    Dao层的函数方法

    1. Public User selectUser(Map paramMap);  

    对应的Mapper.xml

     
    1. <select id=" selectUser" resultMap="BaseResultMap">  
    2.    select  *  from user_user_t   where user_name = #{userName,jdbcType=VARCHAR} and user_area=#{userArea,jdbcType=VARCHAR}  
    3. </select>  

    Service层调用

     Private User xxxSelectUser(){  
    1.    Map paramMap=new hashMap();  
    2.    paramMap.put(“userName”,”对应具体的参数值”);  
    3.    paramMap.put(“userArea”,”对应具体的参数值”);  
    4.    User user=xxx. selectUser(paramMap);}  

    个人认为此方法不够直观,见到接口方法不能直接的知道要传的参数是什么。

    第三种方案

    Dao层的函数方法

    1. Public User selectUser(@param(“userName”)String name,@param(“userArea”)String area);  

    对应的Mapper.xml

    1. <select id=" selectUser" resultMap="BaseResultMap">  
    2.    select  *  from user_user_t   where user_name = #{userName,jdbcType=VARCHAR} and user_area=#{userArea,jdbcType=VARCHAR}  
    3. </select>   

    个人觉得这种方法比较好,能让开发者看到dao层方法就知道该传什么样的参数,比较直观,个人推荐用此种方案。

    3.mybatis update语句怎么写?这个至今还没完全解决好,主要纠结在于id是数据库主键,自动增长的。

    4.mysql返回指定的多行记录:select * from product limit 15 offset #{(value-1)*15+1}

    主要用到了limit 和offest指令。offest指令标识偏移量,即记录从哪开始。limit用来指定选取多少记录。

    <select id="getSomeProductsList" parameterType="int" resultMap="ProductsList">
    select * from product limit 15 offset #{(value-1)*15+1}
    </select>

    在这里发现的解决办法,http://blog.chinaunix.net/uid-23028928-id-2567738.html

    5.spring 用c3p0数据库连接池必须采用jdbc前置名properties文件

    6.mybatis的 mappe.xml怎样返回list<object>?

    答:配置resultMap

    <resultMap id="ProductsList" type="com.pojo.ProductItem">
    <id column="id" property="id" />
    <result column="name" property="name" />
    <result column="amount" property="amount" />
    <result column="price" property="price" />
    </resultMap>

    然后在,注意返回类型不再是ResultType属性,而是resultMap属性

    <select id="getAllProductsList" resultMap="ProductsList">
    select * from product
    </select>

  • 相关阅读:
    (转)树状数组
    poj 3041 Asteroids(二分图最小顶点覆盖)
    poj 2513 Colored Sticks
    (转)优先队列的用法 附:poj2442 poj1442
    poj 1094 Sorting It All Out (拓补)
    poj 3026 Borg Maze(bfs+最小生成树)
    poj 3349 Snowflake Snow Snowflakes
    poj 3020 Antenna Placement(二分图的最大匹配)
    mysql explain
    php strtotime
  • 原文地址:https://www.cnblogs.com/panxuejun/p/5851656.html
Copyright © 2011-2022 走看看