首先DAO层
构建查询字段是否存在
public boolean selectCount(Integer yg_id) throws SQLException {
String sql = "select count(*) from j_dp where yg_id=?";
PreparedStatement ps = conn.prepareStatement(sql);
ps.setInt(1, yg_id);
ResultSet rs = ps.executeQuery();
long count = 0l;
while (rs.next()) {
count = rs.getLong(1);
}
return count > 0;
}
Action层
调用selectCount方法
用if语句实现判断和是否插入