之前学的ssm框架没怎么总结,现在复习,把一些重要基础的知识点总结一下。
需要引入的头文件
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
增
keyproperty属性的值,下面sql里面必须也得加上,否则会报错
id和方法名保持一致,parameterType就是传入的参数类型。sql中获取的值,通过#加大括号获取,也需要和方法传入的参数保持一致,这样才能获取到正确的参数。
<insert id="addUser1" useGeneratedKeys="true">
insert into user(username,password) values(#{username},#{password})
</insert>
<insert id="addUser2" useGeneratedKeys="true" keyProperty="id" keyColumn="id" parameterType="com.sikiedu.ssm.entity.User">
insert into user values(#{id},#{username},#{password})
</insert>
删
<delete id="deleteUserById1">
delete from user where id = #{id}
</delete>
改
<update id="updateUser" parameterType="com.sikiedu.ssm.entity.User">
update user set username=#{username},password=#{password} where id=#{id}
</update>
查
resultType是返回值类型。
<select id="searchAllUsers" resultType="com.sikiedu.ssm.entity.User">
select * from user
</select>
<select id="searchUserById" resultType="com.sikiedu.ssm.entity.User">
select * from user where id = #{id}
</select>