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.
- Functional routing
- Dependency injection
- MySQL/H2 ORM
- Multi-language
- Memory / Redis cache
- Event mechanism
- Plug-in mechanism
- Demo: Simple Latke application example
- Solo: A small and beautiful Java open source blog system, designed for programmers
- Symphony: A modern community (forum/BBS/SNS/blog) platform implemented in Java
<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 is a Java web framework based on JSON
- Why make another wheel called Latke
- Latke Quick Start Guide
- Anatomy of a Latke configuration
Latke uses the Mulan Permissive Software License, Version 2 open source license.
- Netty: An event-driven asynchronous network application framework
- FreeMarker: A widely used Java template engine
- Javassist: Java bytecode processing tool library
- Apache Commons: Java related tool library
- Apache Log4j: Java logging library