public interface StaffMapper {
public List<Staff> getStaffList(@Param("departmentType") String dapartmentType, @Param("staffName") String staffName, @Param("staffId") Integer staffId);
public Staff getStaffById(@Param("staffId") Integer staffId);
public int updateStaffById(@Param("identityType") String identityType,@Param("email") String email,@Param("staffAddress") String staffAddress
,@Param("departName") String departName ,@Param("staffSex") String staffSex,@Param("staffId") Integer staffId);
}
<?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.zll.dao.staff.StaffMapper">
<!-- public List<Staff> getStaffList(@Param("departmentType") String dapartmentType,@Param("staffName") String staffName,@Param("staffId") Integer staffId);-->
<select id="getStaffList" resultMap="stafflist">
select s.*,d.* from staffinfo s,departmentinfo d where s.departmentId=d.departmentId
<if test="departmentType != null || departmentType != '' ">
and d.departmentType like CONCAT ('%',#{departmentType},'%')
</if>
<if test="staffName != null || staffName!=''">
and s.staffName like CONCAT ('%',#{staffName},'%')
</if>
<if test="staffId != null">
and s.staffId=#{staffId}
</if>
order BY s.staffId asc
</select>
<select id="getStaffById" resultMap="stafflist">
select s.*,d.* from staffinfo s,departmentinfo d where s.departmentId=d.departmentId and s.staffId=#{staffId}
</select>
<update id="updateStaffById">
update staffinfo s,departmentinfo d
<set>
<if test="email != null">
s.email=#{email},
</if>
<if test="identityType != null">
s.identityType=#{identityType},
</if>
<if test="staffAddress != null">
s.staffAddress=#{staffAddress},
</if>
<if test="departName != null">
d.departmentType=#{departName},
</if>
<if test="staffSex != null">
s.staffSex=#{staffSex}
</if>
</set>
where s.departmentId = d.departmentId
and s.staffId=#{staffId}
</update>
<resultMap id="stafflist" type="Staff">
<result property="staffId" column="staffId"></result>
<result property="hospitalId" column="hospitalId"></result>
<result property="postId" column="postId"></result>
<result property="departmentId" column="departmentId"></result>
<result property="staffName" column="staffName"></result>
<result property="staffSex" column="staffSex"></result>
<result property="staffAge" column="staffAge"></result>
<result property="staffBirth" column="staffBirth"></result>
<result property="staffAddress" column="staffAddress"></result>
<result property="staffPhone" column="staffPhone"></result>
<result property="departName" column="departmentType"></result>
<result property="inhospitalDate" column="inhospitalDate"></result>
<result property="outhospitalDate" column="outhospitalDate"></result>
<result property="id" column="id"></result>
<result property="identityType" column="identityType"></result>
<result property="email" column="email"></result>
</resultMap>
</mapper>
public interface StaffService {
public List<Staff> QueryStaff(String staffName,String departmentType,Integer staffId);
public Staff getStaffById(Integer staffId);
public int updateStaffById(String identityType, String email, String staffAddress
, String departName , String staffSex,Integer staffId);
}
@Service
public class StaffServiceImpl implements StaffService {
@Autowired
private StaffMapper staffMapper;
@Override
public List<Staff> QueryStaff(String staffName, String departmentType, Integer staffId) {
List<Staff> staff = new ArrayList<>();
staff = staffMapper.getStaffList(departmentType,staffName,staffId);
return staff;
}
@Override
public Staff getStaffById(Integer staffId) {
Staff staff = new Staff();
staff = staffMapper.getStaffById(staffId);
return staff;
}
@Override
public int updateStaffById(String identityType, String email, String staffAddress
, String departName , String staffSex,Integer staffId){
return staffMapper.updateStaffById(identityType,email,staffAddress,departName,staffSex,staffId);
}
}
package com.zll.controller.staff;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zll.pojo.Staff;
import com.zll.service.staff.StaffService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
/**
* @auther zll
* @create 2020/7/28-17:38
*/
@Controller
@RequestMapping("/staff")
public class staffController {
@Autowired
private StaffService staffService;
@RequestMapping("/look")
public String query( String staffName, String departmentType, Integer staffId, @RequestParam(value = "pn",defaultValue = "1") Integer pn, Model model){
PageHelper.startPage(pn,2);
List<Staff> staff = new ArrayList<>();
staff = staffService.QueryStaff(staffName,departmentType,staffId);
PageInfo pageInfo = new PageInfo(staff,3);
// model.addAttribute("stafflist",staff);
model.addAttribute("pageInfo",pageInfo);
return "doctor/index";
}
@RequestMapping("/scan/{staffId}")
public String look(@PathVariable Integer staffId,Model model){
Staff staffById = staffService.getStaffById(staffId);
model.addAttribute("staff",staffById);
return "doctor/look";
}
@RequestMapping("/toupdate/{staffId}")
public String toupdate(@PathVariable Integer staffId,Model model){
Staff staffById = staffService.getStaffById(staffId);
model.addAttribute("staff",staffById);
return "doctor/edit";
}
@RequestMapping("/editstaff")
public String updateStaff(String identityType, String email, String staffAddress
, String departName , String staffSex,Integer staffId){
System.out.println(identityType);
System.out.println(email);
staffService.updateStaffById(identityType,email,staffAddress,departName,staffSex,staffId);
return "doctor/index";
}
}