14 Star 43 Fork 12

88250 / latke

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
README_en_US.md 6.12 KB
一键复制 编辑 原始数据 按行查看 历史
88250 提交于 2023-10-13 12:02 . :bookmark:Release v3.4.30

Latke

A Java Web framework based on JSON

中文

💡 Introduction

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.

✨ Features

  • Functional routing
  • Dependency injection
  • MySQL/H2 ORM
  • Multi-language
  • Memory / Redis cache
  • Event mechanism
  • Plug-in mechanism

🗃 Showcases

  • 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

🛠️ Usages

Maven

<dependency>
    <groupId>org.b3log</groupId>
    <artifactId>latke-core</artifactId>
    <version>${latke.version}</version>
</dependency>

Controller layer usage

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();

Service layer usage

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);
    }
}

Persistence layer usage

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);

📜 Documentation

🏘️ Community

📄 License

Latke uses the Mulan Permissive Software License, Version 2 open source license.

🙏 Acknowledgement

Java
1
https://gitee.com/dl88250/latke.git
git@gitee.com:dl88250/latke.git
dl88250
latke
latke
master

搜索帮助