2017-11-20陈德java_jsp_servletmybatis学习

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

2017-11-20 陈德java_jsp_servlet mybatis
学习
核心代码
<mapper namespace="com.whxh.modle.AdminDao">
<!-- 下面就是要实现增删查改id 就相当于方法名(方法的标识)parameterType参数类型两个间括弧之内需要写sql语句-->
<insert id="addAdmin" parameterType="com.whxh.modle.AdminEntity"> insert into t_admin values(0,#{username},#{upass},#{name},#{status}) </insert>
<select id="selectOne" parameterType="int"
resultType="com.whxh.modle.AdminEntity"> select * from t_admin where
id=#{id}
</select>
<!-- 多个参数如何配置的方法之一(如下方式) -->
<!-- findAll(int pageNo,int pageSize) -->
<select id="selectAdmin" resultMap="maps"> select * from t_admin
</select>
<update id="updateAdmin" parameterType="com.whxh.modle.AdminEntity"> update t_admin set
username=#{username},upass=#{upass},name=#{name},status=#{status} where
id=#{id}
</update>
<update id="forbidden">
update t_admin set status=#{0} where id=#{1}"
</update>
<select id="login"
resultType="com.whxh.modle.AdminEntity">
select * from t_admin where username=#{0} and upass=#{1} and status=#{2} </select>
<resultMap type="com.whxh.modle.AdminEntity" id="maps"> <id column="id"
property="id" />
<result column="username" property="username" /> <result column="upass"
property="upass" /> <result column="name" property="name" /> <result
column="status" property="status" /> </resultMap>
</mapper>
<mapper namespace="com.whxh.modle.NewsDao">
<!-- 下面就是要实现增删查改id 就相当于方法名(方法的标识) parameterType参数类型两个间括弧之内需要写sql语句-->
<!-- 增加图书-->
<insert id="addNews" parameterType="com.whxh.modle.NewsEntity">
insert into t_news values(0,#{title},#{author},#{newstime},#{pageview},#{content},#{status}) </insert>
<!-- 修改-->
<update id="updateNews" parameterType="com.whxh.modle.NewsEntity"> update t_news set title=#{title},author=#{author},
newstime=#{newstime},pageview=#{pageview},
content=#{content},status=#{status}
where id=#{id}
</update>
<!-- 查询所有文章的返回一个List 集合--> <select id="selectNews"
resultMap="maps"> select * from t_news
</select>
<!-- 根据ID 查询-->
<select id="selectOne" parameterType="int"
resultType="com.whxh.modle.NewsEntity">
select * from t_news where id=#{id}
</select>
<!-- 完成禁用-->
<update id="forbidden" parameterType="int">
update t_news set status=#{status} where id=#{#id} </update>
<select id="finNo" resultType="int">
select count(*) from t_news
</select>
<select id="pageSelect" resultMap="maps">
select * from t_news limit #{0} , #{1}
</select>
<resultMap type="com.whxh.modle.NewsEntity" id="maps"> <id column="id"
property="id" />
<result column="title" property="title" />
<result column="author" property="author" />
<result column="newstime" property="newstime" />
<result column="pageview" property="pageview" /> <result
column="content" property="content" />
<result column="status" property="status" /> </resultMap>
</mapper>
<mapper namespace="erDao">
<!-- 下面就是要实现增删查改id 就相当于方法名(方法的标识)parameterType参数类型两个间括弧之内需要写sql语句-->
<!-- 增加图书-->
<insert id="addUser" parameterType="erEntity"> insert into t_user values(0,#{username},#{upass},#{name},#{status})
</insert>
<select id="selectOne" parameterType="int"
resultType="erEntity"> select * from t_user where
id=#{id}
</select>
<!-- 多个参数如何配置的方法之一(如下方式) -->
<!-- findAll(int pageNo,int pageSize) -->
<select id="findAll" resultMap="maps"> select * from t_admin
</select>
<update id="updateUser" parameterType="erEntity"> update t_user set
username=#{username},upass=#{upass},name=#{name},status=#{status} where
id=#{id}
</update>
<select id="login" resultType="erEntity"> select * from t_user where username=#{0} and upass=#{1} and status=#{2} </select>
<update id="pageviewAdd" parameterType="int">
UPDATE t_news SET pageview=pageview+1 WHERE id=#{id} </update>
<resultMap type="erEntity" id="maps"> <id column="id"
property="id" />
<result column="username" property="username" /> <result column="upass"
property="upass" />
<result column="name" property="name" />
<result column="status" property="status" />
</resultMap>
</mapper>。

相关文档
最新文档