发表于: 2017-06-25 21:16:53

1 1063


今天完成的:复习以前学习的东西

mybatis常用方法

<?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">
<!-- 动态web工程版本2.3,仍使用DTD声明 -->
<mapper namespace="dao.CommandItemDAOInterface">
   <!-- 不同namespace下的相同id的sql语句可以同时存在,接口方式编程namespace必须为借口的全限定名 -->
   <resultMap type="bean.Command" id="CommandResult">
       <id column="ID" property="id" jdbcType="VARCHAR" />
       <!-- sql主键使用id标签,jdbcType映射sql的数据类型 ;如果 null 被当作值来传递,对于所有可能为空的列,JDBC Type
               是需要的。 -->
       <result column="NAME" jdbcType="VARCHAR" property="name" />
       <result column="DESCRIPTION" jdbcType="VARCHAR" property="description" />
   </resultMap>
   <!-- map<command,page> ,将page包装进来便于limit分页,map里面对象的属性可以直接读-->
   <select id="queryCommandList" parameterType="java.util.Map"
           resultMap="CommandResult">
       <!-- resultMap指向映射,在映射标签中配置关系。resultType指向java类型,使用resultType时,不关联resultMap,
               而是通过javabean的属性值来和DB字段名进行匹配 ,两者必须相同 -->
       select
<include refid="col" />
       from command
<where>
           <if test="command.name!=null&amp;&amp;!&quot;&quot;.equals(command.name.trim())">and NAME=#{command.name}</if>
           <!-- 此处引号和&&需要在HTML中转义,&quot;引号,&amp;且&&-->
           <!-- mybatis拼接sql前面不用添加空格等等,mybatis自动处理 -->
           <if
                   test="command.description!=null&amp;&amp;!&quot;&quot;.equals(command.description.trim())">and DESCRIPTION like '%' #{command.description} '%'</if>
           <!-- '%'之间仍然需要添加空格 ,%为通配符,即在开头和结尾前只要包含#{description}就符合条件 -->
       </where>
       order by ID limit #{page.dbIndex},#{page.dbNumber}
</select>
   <sql id="col">ID,NAME,DESCRIPTION</sql>
   <delete id="deleteOne" parameterType="int">delete from command where
ID= #{_parameter}
</delete>
   <!-- ${_parameter}在OGNI表达式中对应String和基本数据类型 -->
   <delete id="deleteBatch" parameterType="java.util.List">
       delete from command where ID in(
<foreach collection="list" item="item" separator=",">#{item}
</foreach>
       <!-- foreach是mybatis的遍历标签,separator相当于split()方法 -->
       )
</delete>
   <insert id="insertCommand" parameterType="bean.Command"
           useGeneratedKeys="true" keyProperty="id">
       insert into
command(NAME,DESCRIPTION)values(#{name},#{description})
</insert>
   <update id="updateItem" parameterType="bean.Command">
       update command
<set>
           <if test="name!=null&amp;&amp;!&quot;&quot;.equals(name.trim())">NAME=#{name},</if>
           <if
                   test="description!=null&amp;&amp;!&quot;&quot;.equals(description.trim())">DESCRIPTION=#{description},</if>
       </set>
       where id=#{id}
</update>

   <select id="count" parameterType="bean.Command"
           resultType="int">
       select
count(*)
from command
<where>
           <if test="name!=null&amp;&amp;!&quot;&quot;.equals(name.trim())">and NAME=#{name}</if>
           <!-- OGNI表达式,常用于strus2,可直接使用javaAPI,此处引号和&&需要在HTML中转义,也可以使用OGNI特有的操作符 -->
           <!-- mybatis拼接sql前面不用添加空格,mybatis自动处理 -->
           <!-- eclipse将#{}转义为?并读取其中的类型,有点类似泛型 -->
           <if
                   test="description!=null&amp;&amp;!&quot;&quot;.equals(description.trim())">and DESCRIPTION like '%' #{description} '%'</if>
           <!-- '%'之间仍然需要添加空格 ,%为通配符,即在开头和结尾前只要包含#{description}就符合条件 -->
       </where>
   </select>
   <!-- sql标签相当于常量定义 -->
   <!-- <trim>标签较为灵活,可以替代where/set <choose>标签可以表示if else/switch case <association>标签用于在主表中关联子表,并映射到子表的javabean中 -->
   <!-- resultMap和ResultType:resultMap指向映射,在映射标签中配置关系。resultType指向java类型,使用resultType时,不关联resultMap,
           而是通过javabean的属性值来和DB字段名进行匹配 ,两者必须相同 . parameterMap和parameterType:parameterMap已经很少使用了。
           #{}和${}:#{}会预编译为?,从而对sql语句进行插入,防止sql注入。${}会直接将内容插入到sql中。而且不安全,但${}使用与动态排序 -->
</mapper>

在HttpServlet源码中找到了doget/dopost/dodelete等等方法,都提供了这些标准的Http规范,但很多人都无视了,直接用get/post处理所有的请求

然后是jsp

常用的jsp标签,通过el取值

cookie的处理方法

明天的计划

还有一些以前写的都忘了,明天要捡起来,顺便开始任务3


返回列表 返回列表
评论

    分享到