假期作业7
删除信息:
servlet:
点击查看代码
package com.vivy.web;
import com.vivy.service.BaseService;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
@WebServlet("/deleteServlet")
public class deleteServlet extends HttpServlet {
private BaseService service = new BaseService();
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=utf-8");
//# = new String(classId.getBytes(StandardCharsets.ISO_8859_1),StandardCharsets.UTF_8);
String assessmentId = request.getParameter("id");
service.delete(assessmentId);
request.getRequestDispatcher("/selectAllServlet").forward(request,response);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doGet(request, response);
}
}
mapper:
点击查看代码
package com.vivy.mapper;
import com.vivy.pojo.Base;
import java.util.List;
public interface BaseMapper {
void add(Base base);
List<Base> selectAll();
void delete(String assessmentId);
void update(Base base);
}
xml:
点击查看代码
<?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">
<!--接口全路径名-->
<mapper namespace="com.vivy.mapper.BaseMapper">
<insert id="add" parameterType="com.vivy.pojo.Base">
INSERT INTO tb_base (
assessmentId, assessmentDate, assessmentReason, name, gender, birthDate,
idCard, socialCard, ethnicity, educationLevel, religious, maritalStatus,
livingCondition, medicalPayment, economicSource, dementia, mentalIllness,
chronicDiseases, fall, gettingLost, choking, suicide, otherInfo,
informantName, relationship, contactName, contactPhone
) VALUES (
#{assessmentId}, #{assessmentDate}, #{assessmentReason}, #{name}, #{gender}, #{birthDate},
#{idCard}, #{socialCard}, #{ethnicity}, #{educationLevel}, #{religious}, #{maritalStatus},
#{livingCondition}, #{medicalPayment}, #{economicSource}, #{dementia}, #{mentalIllness},
#{chronicDiseases}, #{fall}, #{gettingLost}, #{choking}, #{suicide}, #{otherInfo},
#{informantName}, #{relationship}, #{contactName}, #{contactPhone}
)
</insert>
<delete id="delete">
delete from tb_base where assessmentId = #{assessmentId}
</delete>
<select id="selectAll" resultType="com.vivy.pojo.Base">
SELECT * FROM tb_base
</select>
<update id="update">
update tb_base
<set>
<if test="assessmentDate != null and assessmentDate != '' ">
assessmentDate = #{assessmentDate},
</if>
<if test="assessmentReason != null">
assessmentReason = #{assessmentReason},
</if>
<if test="name != null and name != '' ">
name = #{name},
</if>
<if test="gender != null and gender != '' ">
gender = #{gender},
</if>
<if test="birthDate != null and birthDate != '' ">
birthDate = #{birthDate},
</if>
<if test="idCard != null and idCard != '' ">
idCard = #{idCard},
</if>
<if test="socialCard != null and socialCard != '' ">
socialCard = #{socialCard},
</if>
<if test="ethnicity != null and ethnicity != '' ">
ethnicity = #{ethnicity},
</if>
<if test="educationLevel != null">
educationLevel = #{educationLevel},
</if>
<if test="religious != null">
religious = #{religious},
</if>
<if test="maritalStatus != null">
maritalStatus = #{maritalStatus},
</if>
<if test="livingCondition != null">
livingCondition = #{livingCondition},
</if>
<if test="medicalPayment != null">
medicalPayment = #{medicalPayment},
</if>
<if test="economicSource != null">
economicSource = #{economicSource},
</if>
<if test="dementia != null">
dementia = #{dementia},
</if>
<if test="mentalIllness != null">
mentalIllness = #{mentalIllness},
</if>
<if test="chronicDiseases != null and chronicDiseases != '' ">
chronicDiseases = #{chronicDiseases},
</if>
<if test="fall != null">
fall = #{fall},
</if>
<if test="gettingLost != null">
gettingLost = #{gettingLost},
</if>
<if test="choking != null">
choking = #{choking},
</if>
<if test="suicide != null">
suicide = #{suicide},
</if>
<if test="otherInfo != null and otherInfo != '' ">
otherInfo = #{otherInfo},
</if>
<if test="informantName != null and informantName != '' ">
informantName = #{informantName},
</if>
<if test="relationship != null and relationship != '' ">
relationship = #{relationship},
</if>
<if test="contactName != null and contactName != '' ">
contactName = #{contactName},
</if>
<if test="contactPhone != null and contactPhone != '' ">
contactPhone = #{contactPhone},
</if>
</set>
where assessmentId = #{assessmentId};
</update>
</mapper>

浙公网安备 33010602011771号