FT网站开发过程遇到的问题汇总

Posted THISISPAN

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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>

以上是关于FT网站开发过程遇到的问题汇总的主要内容,如果未能解决你的问题,请参考以下文章

开发过程中遇到的各种问题汇总

性能测试工具开发过程中遇到的问题汇总

汇总开发过程中遇到的坑

开发过程遇到的坑汇总

使用ubuntu过程中遇到的问题汇总

使用LR11过程中遇到的一些问题汇总