<mapping class="hibernate.entity.User"/>
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.url">jdbc:mysql://localhost:3306/spring_course</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.username">root</property>
<property name="connection.password">springcourse</property>
<property name="current_session_context_class">thread</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">true</property>
<mapping class="hibernate.entity.User"/>
</session-factory>
</hibernate-configuration>
public class HtmlToPlainText {
public static String getPlainText(Element element) {
FormattingVisitor formatter = new FormattingVisitor();
NodeTraversor.traverse(formatter, element); // walk the DOM, and call .head() and .tail() for each node
return formatter.toString();
}
private static class FormattingVisitor implements NodeVisitor {
private static final int maxWidth = 80;
private int width = 0;
private StringBuilder accum = new StringBuilder(); // holds the accumulated text
// hit when the node is first seen
public void head(Node node, int depth) {
String name = node.nodeName();
if (node instanceof TextNode)
append(((TextNode) node).text()); // TextNodes carry all user-readable text in the DOM.
else if (name.equals("li"))
append("\n * ");
else if (name.equals("dt"))
append(" ");
else if (StringUtil.in(name, "p", "h1", "h2", "h3", "h4", "h5", "tr"))
append("\n");
}
// hit when all of the node's children (if any) have been visited
public void tail(Node node, int depth) {
String name = node.nodeName();
if (StringUtil.in(name, "br", "dd", "dt", "p", "h1", "h2", "h3", "h4", "h5"))
append("\n");
else if (name.equals("a"))
append(String.format(" <%s>", node.absUrl("href")));
}
// appends text to the string builder with a simple word wrap method
private void append(String text) {
if (text.startsWith("\n"))
width = 0; // reset counter if starts with a newline. only from formats above, not in natural text
if (text.equals(" ") &&
(accum.length() == 0 || StringUtil.in(accum.substring(accum.length() - 1), " ", "\n")))
return; // don't accumulate long runs of empty spaces
if (text.length() + width > maxWidth) { // won't fit, needs to wrap
String[] words = text.split("\\s+");
for (int i = 0; i < words.length; i++) {
String word = words[i];
boolean last = i == words.length - 1;
if (!last) // insert a space if not the last word
word = word + " ";
if (word.length() + width > maxWidth) { // wrap and reset counter
accum.append("\n").append(word);
width = word.length();
} else {
accum.append(word);
width += word.length();
}
}
} else { // fits as is, without need to wrap text
accum.append(text);
width += text.length();
}
}
@Override
public String toString() {
return accum.toString();
}
}
}
Contact contact = new Contact("", "", "", 0);
public String say(String something) {
return "Ты чё не знаешь, что рыбы не разговаривают?";
}
Fish myFish = new Fish();
myFish.say("Привет");
Fish myFish = new Fish();
String fishSay = myFish.say("Привет");
System.out.println(fishSay);
Пока не вижу кейсов, при которых не хватало SpringBoot, либо MicroProfile-фреймворков.
Приложение будет предоставлять несколько WEB-сервисов, за каждый будет отвечать отдельный микросервис :) Но все они будут обращаться к одной базе данных.
Я хочу сделать микросервис (или модуль?), который абстрагирует БД. Т.е. он умеет читать (пока только читать, а в перспективе и писать, и кэшировать запросы) записи из БД и раздавать их другим частям приложения. Все остальные части ничего не знают про БД, а пользуются готовыми объектами.
Но допустим, у меня БД на 1000 таблиц (плюс ещё таблицы взаимосвязаны что порождает вложенные Java-объекты). Это значит, мне надо сделать 1000 репозиториев, в каждом Х методов (получение по ID, получение по значению поля, одного объекта, коллекции...). И ещё 1000*Х методов в контроллерах....