插件操作数据库(finedb)示例。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.9 KiB

package com.fr.conf.db.demo.fun.http;
import com.fanruan.api.web.FlushKit;
import com.fr.conf.db.demo.SystemConfigAccessBridge;
import com.fr.conf.db.demo.fun.SystemConfigDAO;
import com.fr.conf.db.demo.fun.entity.SystemConfigEntity;
import com.fr.decision.fun.impl.BaseHttpHandler;
import com.fr.stable.db.action.DBAction;
import com.fr.stable.db.dao.DAOContext;
import com.fr.third.org.apache.commons.lang3.RandomStringUtils;
import com.fr.third.org.apache.commons.lang3.RandomUtils;
import com.fr.third.springframework.web.bind.annotation.RequestMethod;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.UUID;
public class InputHttpHandler extends BaseHttpHandler {
@Override
public RequestMethod getMethod() {
return RequestMethod.GET;
}
@Override
public String getPath() {
return "/db/input";
}
@Override
public boolean isPublic() {
return false;
}
@Override
public void handle(HttpServletRequest req, HttpServletResponse res) throws Exception {
SystemConfigEntity result = SystemConfigAccessBridge.getDbAccessor().runDMLAction(new DBAction<SystemConfigEntity>() {
@Override
public SystemConfigEntity run(DAOContext daoContext) throws Exception {
SystemConfigEntity entity = new SystemConfigEntity();
entity.setId(UUID.randomUUID().toString());
entity.setUser(RandomStringUtils.randomAlphabetic(5));
entity.setBirth(new Date());
entity.setSalary(RandomUtils.nextDouble(10000, 50000));
daoContext.getDAO(SystemConfigDAO.class).add(entity);
return entity;
}
});
FlushKit.printAsString(res, "success insert data:" + result.toString() + " to database table:fine_plugin_system_conf");
}
}