基于SSM+layui实现用户删除功能

实现原理:通过索引id的值编写delete删除语句。jsp界面效果:layer.confirm弹出提示框,并通过ajax中post请求实现异步提交、页面不刷新,提高效率

一、效果实现

基于SSM+layui实现用户删除功能_第1张图片

二、数据准备

user表

基于SSM+layui实现用户删除功能_第2张图片

三、代码实现

1、bean层—UserInfo.java

@AllArgsConstructor
@NoArgsConstructor
@Data
public class UserInfo implements Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = -6943242013517012358L;
	private Integer id;
	private String userId;
	private String userName;
	private String password;
	@JsonFormat(timezone = "GMT+8", pattern="yyyy-MM-dd HH:mm:ss")
	private Date registerTime;
	private Boolean state;
}

2、mapper层—UserInfoMapper.java UserInfoMapper.xml

2.1 UserInfoMapper.java

public interface UserInfoMapper {
    public void deleteUserInfoById(Integer id);
}

2.2 UserInfoMapper.xml

<delete id="deleteUserInfoById" parameterType="UserInfo">
		delete from user where id=#{id}
delete>

3、service层—UserInfoService.java UserInfoServiceImpl.java

3.1 UserInfoService.java

public interface UserInfoService {
    public void deleteUserInfoById(Integer id);
}

3.2 UserInfoServiceImpl.java

@Transactional
@Service
public class UserInfoServiceImpl implements UserInfoService{
	
	@Autowired
	private UserInfoMapper userInfoMapper;
    
    @Override
	public void deleteUserInfoById(Integer id) {
		userInfoMapper.deleteUserInfoById(id);
	}
	
}

4、controller层—UserInfoController.java

@Controller
public class UserInfoController {

	@Autowired
	private UserInfoService userInfoService;
    
    @RequestMapping("/deleteUserInfoById")
	public void deleteUserInfoById(Integer id) {
		userInfoService.deleteUserInfoById(id);
	}
	
}

5、jsp界面—list_user.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>






用户列表








	

你可能感兴趣的:(ssm,layui,java,servlet)