Compare commits
5 Commits
2d1507022e
...
c0904ea464
| Author | SHA1 | Date |
|---|---|---|
|
|
c0904ea464 | 4 weeks ago |
|
|
eb5b333eca | 4 weeks ago |
|
|
0d78a67acc | 2 months ago |
|
|
79161d9cd8 | 2 months ago |
|
|
7b3994ca84 | 2 months ago |
6 changed files with 92 additions and 0 deletions
@ -0,0 +1,19 @@ |
|||
import org.slf4j.Logger; |
|||
import org.slf4j.LoggerFactory; |
|||
|
|||
public class ArticleRepository { |
|||
private static final Logger log = LoggerFactory.getLogger(ArticleRepository.class); |
|||
|
|||
public void save(Article article) { |
|||
// 防御检查:空值拦截
|
|||
if (article == null) { |
|||
log.warn("保存文章失败:article为空"); |
|||
return; |
|||
} |
|||
if (article.getTitle() == null || article.getTitle().isBlank()) { |
|||
log.warn("保存文章失败:标题为空"); |
|||
return; |
|||
} |
|||
// 原有保存逻辑
|
|||
} |
|||
} |
|||
@ -0,0 +1,7 @@ |
|||
package exception; |
|||
|
|||
public class ParseException extends CrawlerException { |
|||
public ParseException(String message) { |
|||
super(message); |
|||
} |
|||
} |
|||
@ -0,0 +1,42 @@ |
|||
abstract class Area{ |
|||
public abstract double draw(); |
|||
} |
|||
class circle extends Area{ |
|||
double r; |
|||
public double draw() { |
|||
double area = 3.14 * r * r; |
|||
System.out.println(area); |
|||
return area; |
|||
} |
|||
} |
|||
class rectangle extends Area{ |
|||
double l,b; |
|||
public double draw() { |
|||
double area = l * b; |
|||
System.out.println(area); |
|||
return area; |
|||
} |
|||
} |
|||
class tangle extends Area{ |
|||
double b,h; |
|||
public double draw() { |
|||
double area = 0.5 * b * h; |
|||
System.out.println(area); |
|||
return area; |
|||
} |
|||
} |
|||
public class Main{ |
|||
static void main(String[] args) { |
|||
circle c=new circle(); |
|||
c.r=5; |
|||
c.draw(); |
|||
rectangle a=new rectangle(); |
|||
a.l=5; |
|||
a.b=4; |
|||
a.draw(); |
|||
tangle t=new tangle(); |
|||
t.b=5; |
|||
t.h=4; |
|||
t.draw(); |
|||
} |
|||
} |
|||
@ -0,0 +1,23 @@ |
|||
public class Pair<K,V>{ |
|||
private K key; |
|||
private V value; |
|||
public Pair(K key,V value){ |
|||
this.key=key; |
|||
this.value=value; |
|||
} |
|||
public K getKey(){ |
|||
return key; |
|||
} |
|||
public V getValue(){ |
|||
return value; |
|||
} |
|||
public void setKey(K key){ |
|||
this.key=key; |
|||
} |
|||
public void setValue(V value){ |
|||
this.value=value; |
|||
} |
|||
public static <K,V> Pair<V,K> swap(Pair<K,V> pair){ |
|||
return new Pair<>(pair.getValue(), pair.getKey()); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue