java json框架_latke: 一款以 JSON 为主的 Java Web 框架。

6f3749ea165d176ed2f7bf4b030f9e74.png

A Java Web framework based on JSON

latke.svg?style=flat-square

license-MulanPSL2-orange.svg?style=flat-square

latke-parent?style=flat-square&color=blueviolet

latke.svg

💡 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.

✨ Features

Functional routing

Dependency injection

Multiple databases 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

org.b3log

latke-core

${latke.version}

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 records = select("SELECT * FROM `user` WHERE `name` = ?", name);

📜 Documentation

🏘️ Community

📄 License

🙏 Acknowledgement

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值