同步操作将从 88250/latke 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
A Java Web framework based on JSON
Latke ('lɑ:tkə, potato cake) is a simple and easy-to-use Java Web application development framework, including MVC, IoC, event notification, ORM, plugins and other components. The use of JSON on the entity model runs through the front and back ends, making application development faster. This is where Latke is different from other frameworks, and is more suitable for the rapid development of small applications.
Welcome to Latke Official Discussion Forum to learn more.
<dependency>
<groupId>org.b3log</groupId>
<artifactId>latke-core</artifactId>
<version>${latke.version}</version>
</dependency>
Functional routing
final Dispatcher.RouterGroup routeGroup = Dispatcher.group();
routeGroup.get("/", helloProcessor::index).
get("/register", registerProcessor::showRegister).
post("/register", registerProcessor::register).
get("/var/{pathVar}", registerProcessor::paraPathVar).
router().get().post().uri("/greeting").handler(helloProcessor::greeting);
JSON parsing
final JSONObject requestJSON = context.requestJSON();
HTTP encapsulation
final String remoteAddr = context.remoteAddr();
final String requestURI = context.requestURI();
final Object att = context.attr("name");
final String method = context.method();
context.sendRedirect("https://b3log.org");
final Request request = context.getRequest();
final Response response = context.getResponse();
Dependency injection, transaction
@Service
public class UserService {
private static final Logger LOGGER = Logger.getLogger(UserService.class);
@Inject
private UserRepository userRepository;
@Transactional
public void saveUser(final String name, final int age) {
final JSONObject user = new JSONObject();
user.put("name", name);
user.put("age", age);
String userId;
try {
userId = userRepository.add(user);
} catch (final RepositoryException e) {
LOGGER.log(Level.ERROR, "Saves user failed", e);
// The framework will roll back the transaction after throwing an exception
throw new IllegalStateException("Saves user failed");
}
LOGGER.log(Level.INFO, "Saves a user successfully [userId={0}]", userId);
}
}
Construct repository
@Repository
public class UserRepository extends AbstractRepository {
public UserRepository() {
super("user");
}
}
Single table CRUD
public interface Repository {
String add(final JSONObject jsonObject) throws RepositoryException;
void update(final String id, final JSONObject jsonObject) throws RepositoryException;
void remove(final String id) throws RepositoryException;
void remove(final Query query) throws RepositoryException;
JSONObject get(final String id) throws RepositoryException;
long count(final Query query) throws RepositoryException;
}
Conditional query
public JSONObject getByName(final String name) throws RepositoryException {
return getFirst(new Query().setFilter(new PropertyFilter("name", FilterOperator.EQUAL, name)));
}
Paging query
new Query().setPage(1, 50)
Sort by field
new Query().addSort("name", SortDirection.DESCENDING);
Get only required fields
new Query().select("name", "age");
Native SQL
final List<JSONObject> records = select("SELECT * FROM `user` WHERE `name` = ?", name);
Latke uses the Mulan Permissive Software License, Version 2 open source license.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。