mirror of
https://github.com/getrebuild/rebuild.git
synced 2025-10-02 19:47:34 +08:00
基础构建
This commit is contained in:
parent
ddad4dc9e1
commit
a4b267b0ba
28 changed files with 1025 additions and 56 deletions
|
@ -25,7 +25,7 @@
|
|||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
|
||||
<attributes>
|
||||
<attribute name="owner.project.facets" value="java"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
|
||||
org.eclipse.jdt.core.compiler.compliance=1.7
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||
org.eclipse.jdt.core.compiler.source=1.7
|
||||
|
|
|
@ -7,9 +7,6 @@
|
|||
<dependent-module archiveName="persist4j-1.0.1-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/persist4j/persist4j">
|
||||
<dependency-type>uses</dependency-type>
|
||||
</dependent-module>
|
||||
<dependent-module archiveName="wxsdk-1.0.1-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/wxsdk/wxsdk">
|
||||
<dependency-type>uses</dependency-type>
|
||||
</dependent-module>
|
||||
<dependent-module archiveName="commons-1.1.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/commons/commons">
|
||||
<dependency-type>uses</dependency-type>
|
||||
</dependent-module>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<faceted-project>
|
||||
<fixed facet="wst.jsdt.web"/>
|
||||
<installed facet="jst.web" version="2.3"/>
|
||||
<installed facet="jst.web" version="3.1"/>
|
||||
<installed facet="wst.jsdt.web" version="1.0"/>
|
||||
<installed facet="java" version="1.7"/>
|
||||
</faceted-project>
|
||||
|
|
7
pom.xml
7
pom.xml
|
@ -6,7 +6,7 @@
|
|||
<groupId>cn.devezhao</groupId>
|
||||
<artifactId>re-build</artifactId>
|
||||
<packaging>war</packaging>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<name>re-build</name>
|
||||
<url>http://github.com/devezhao/re-build</url>
|
||||
|
||||
|
@ -46,11 +46,6 @@
|
|||
<artifactId>persist4j</artifactId>
|
||||
<version>1.0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.devezhao</groupId>
|
||||
<artifactId>wxsdk</artifactId>
|
||||
<version>1.0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.devezhao</groupId>
|
||||
<artifactId>commons</artifactId>
|
||||
|
|
|
@ -25,6 +25,7 @@ import org.springframework.context.ApplicationContext;
|
|||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
import cn.devezhao.persist4j.PersistManagerFactory;
|
||||
import cn.devezhao.persist4j.Query;
|
||||
import cn.devezhao.persist4j.metadata.MetadataFactory;
|
||||
import cn.devezhao.rebuild.server.service.CommonService;
|
||||
import cn.devezhao.rebuild.server.service.QueryFactory;
|
||||
|
@ -108,6 +109,13 @@ public class Application {
|
|||
return getBean(QueryFactory.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public static Query createQuery(String ajql) {
|
||||
return getQueryFactory().createQuery(ajql);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
|
|
|
@ -15,9 +15,12 @@ import org.springframework.web.context.support.WebApplicationContextUtils;
|
|||
public class Startup extends HttpServlet {
|
||||
private static final long serialVersionUID = 5783774294311348578L;
|
||||
|
||||
private static String contextPath = "/";
|
||||
@Override
|
||||
public void init(ServletConfig config) throws ServletException {
|
||||
super.init(config);
|
||||
contextPath = config.getServletContext().getContextPath();
|
||||
|
||||
Application.LOG.warn("Rebuild Booting ...");
|
||||
try {
|
||||
ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
|
||||
|
@ -27,4 +30,13 @@ public class Startup extends HttpServlet {
|
|||
System.exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取部署路径
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static String getContextPath() {
|
||||
return contextPath;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,138 @@
|
|||
package cn.devezhao.rebuild.server.metadata;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.dom4j.Element;
|
||||
|
||||
import cn.devezhao.commons.CalendarUtils;
|
||||
import cn.devezhao.persist4j.Entity;
|
||||
import cn.devezhao.persist4j.Record;
|
||||
import cn.devezhao.persist4j.engine.ID;
|
||||
import cn.devezhao.persist4j.engine.StandardRecord;
|
||||
import cn.devezhao.persist4j.record.RecordCreator;
|
||||
import cn.devezhao.rebuild.server.Application;
|
||||
import cn.devezhao.rebuild.server.service.user.UserService;
|
||||
|
||||
/**
|
||||
* @author Zhao Fangfang
|
||||
* @version $Id: EntityHelper.java 3407 2017-05-05 10:09:40Z devezhao $
|
||||
* @since 1.0, 2013-6-26
|
||||
*/
|
||||
public class EntityHelper {
|
||||
|
||||
|
||||
/**
|
||||
* 获取实体
|
||||
*
|
||||
* @param entityName
|
||||
* @return
|
||||
*/
|
||||
public static Entity getEntity(String entityName) {
|
||||
return Application.getPersistManagerFactory().getMetadataFactory().getEntity(entityName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取实体
|
||||
*
|
||||
* @param entityCode
|
||||
* @return
|
||||
*/
|
||||
public static Entity getEntity(int entityCode) {
|
||||
return Application.getPersistManagerFactory().getMetadataFactory().getEntity(entityCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param data
|
||||
* @param user
|
||||
* @return
|
||||
*/
|
||||
public static Record parse(Element data, ID user) {
|
||||
String entityName = data.attributeValue("name");
|
||||
if (StringUtils.isBlank(entityName) || !data.getName().equals("entity")) {
|
||||
throw new IllegalArgumentException("无效实体数据格式\n----\n" + data.asXML());
|
||||
}
|
||||
|
||||
RecordCreator creator = new ExtRecordCreator(getEntity(entityName), data, user);
|
||||
Record record = creator.create();
|
||||
bindCommonsFieldsValue(record, record.getPrimary() == null);
|
||||
return record;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param recordId
|
||||
* @param user
|
||||
* @return
|
||||
*/
|
||||
public static Record forUpdate(ID recordId, ID user) {
|
||||
Entity entity = getEntity(recordId.getEntityCode());
|
||||
Record r = new StandardRecord(entity, user);
|
||||
r.setID(entity.getPrimaryField().getName(), recordId);
|
||||
bindCommonsFieldsValue(r, false);
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param entityCode
|
||||
* @param user
|
||||
* @return
|
||||
*/
|
||||
public static Record forNew(int entityCode, ID user) {
|
||||
Entity entity = EntityHelper.getEntity(entityCode);
|
||||
Record r = new StandardRecord(entity, user);
|
||||
bindCommonsFieldsValue(r, true);
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定公用/权限字段值
|
||||
*
|
||||
* @param r
|
||||
* @param isNew
|
||||
*/
|
||||
protected static void bindCommonsFieldsValue(Record r, boolean isNew) {
|
||||
final Date now = CalendarUtils.now();
|
||||
final Entity entity = r.getEntity();
|
||||
|
||||
if (entity.containsField(modifiedOn)) {
|
||||
r.setDate(modifiedOn, now);
|
||||
}
|
||||
if (entity.containsField(modifiedBy)) {
|
||||
r.setID(modifiedBy, r.getEditor());
|
||||
}
|
||||
|
||||
if (isNew) {
|
||||
if (entity.containsField(createdOn)) {
|
||||
r.setDate(createdOn, now);
|
||||
}
|
||||
if (entity.containsField(createdBy)) {
|
||||
r.setID(createdBy, r.getEditor());
|
||||
}
|
||||
if (entity.containsField(owningUser)) {
|
||||
r.setID(owningUser, Application.getBean(UserService.class).getDeptOfUser(r.getEditor()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 公共字段
|
||||
|
||||
public static final String createdOn = "createdOn";
|
||||
public static final String createdBy = "createdBy";
|
||||
public static final String modifiedOn = "modifiedOn";
|
||||
public static final String modifiedBy = "modifiedBy";
|
||||
public static final String owningUser = "owningUser";
|
||||
public static final String owningDept = "owningDept";
|
||||
|
||||
// 实体代码
|
||||
|
||||
public static final int User = 001;
|
||||
public static final int Department = 002;
|
||||
public static final int Role = 003;
|
||||
public static final int RolePrivileges = 004;
|
||||
public static final int RoleMember = 005;
|
||||
|
||||
public static final int MetaEntity = 010;
|
||||
public static final int MetaField = 011;
|
||||
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package cn.devezhao.rebuild.server.metadata;
|
||||
|
||||
import org.dom4j.Element;
|
||||
|
||||
import cn.devezhao.persist4j.Entity;
|
||||
import cn.devezhao.persist4j.Record;
|
||||
import cn.devezhao.persist4j.engine.ID;
|
||||
import cn.devezhao.persist4j.record.XmlRecordCreator;
|
||||
|
||||
/**
|
||||
* @author Zhao Fangfang
|
||||
* @version $Id: ExtRecordCreator.java 22 2013-06-26 12:15:01Z zhaoff@qidapp.com $
|
||||
* @since 1.0, 2013-6-26
|
||||
*/
|
||||
public class ExtRecordCreator extends XmlRecordCreator {
|
||||
|
||||
/**
|
||||
* @param entity
|
||||
* @param source
|
||||
* @param editor
|
||||
*/
|
||||
public ExtRecordCreator(Entity entity, Element source, ID editor) {
|
||||
super(entity, source, editor);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void afterCreate(Record record, boolean isNew) {
|
||||
super.afterCreate(record, isNew);
|
||||
EntityHelper.bindCommonsFieldsValue(record, isNew);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
Copyright 2018 DEVEZHAO(zhaofang123@gmail.com)
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package cn.devezhao.rebuild.server.service.user;
|
||||
|
||||
import cn.devezhao.persist4j.PersistManagerFactory;
|
||||
import cn.devezhao.persist4j.engine.ID;
|
||||
import cn.devezhao.rebuild.server.Application;
|
||||
import cn.devezhao.rebuild.server.metadata.EntityHelper;
|
||||
import cn.devezhao.rebuild.server.service.BaseService;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhaofang123@gmail.com
|
||||
* @since 07/25/2018
|
||||
*/
|
||||
public class UserService extends BaseService {
|
||||
|
||||
/**
|
||||
* 系统用户
|
||||
*/
|
||||
public static final ID SYS_USER = ID.valueOf("001-0000000000000000");
|
||||
/**
|
||||
* 管理员
|
||||
*/
|
||||
public static final ID ADMIN_USER = ID.valueOf("001-0000000000000001");
|
||||
/**
|
||||
* 根级部门
|
||||
*/
|
||||
public static final ID ROOT_DEPT = ID.valueOf("002-0000000000000001");
|
||||
/**
|
||||
* 管理员权限
|
||||
*/
|
||||
public static final ID ADMIN_ROLE = ID.valueOf("003-0000000000000001");
|
||||
|
||||
protected UserService(PersistManagerFactory persistManagerFactory) {
|
||||
super(persistManagerFactory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEntity() {
|
||||
return EntityHelper.User;
|
||||
}
|
||||
|
||||
public ID getDeptOfUser(ID user) {
|
||||
Object[] found = Application.createQuery(
|
||||
"select deptId from User where userId = ?")
|
||||
.setParameter(1, user)
|
||||
.unique();
|
||||
return (ID) found[0];
|
||||
}
|
||||
}
|
|
@ -17,13 +17,18 @@ limitations under the License.
|
|||
package cn.devezhao.rebuild.utils;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.AccessDeniedException;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
import cn.devezhao.commons.ThrowableUtils;
|
||||
import cn.devezhao.commons.web.ServletUtils;
|
||||
import cn.devezhao.commons.web.WebUtils;
|
||||
import cn.devezhao.persist4j.engine.ID;
|
||||
|
||||
/**
|
||||
|
@ -38,7 +43,8 @@ public class AppUtils {
|
|||
* @return
|
||||
*/
|
||||
public static ID getRequestUser(HttpServletRequest request) {
|
||||
return null;
|
||||
Object current = ServletUtils.getSessionAttribute(request, WebUtils.CURRENT_USER);
|
||||
return (ID) current;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -55,6 +61,42 @@ public class AppUtils {
|
|||
return jo.toJSONString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取后台抛出的错误消息
|
||||
*
|
||||
* @param request
|
||||
* @param exception
|
||||
* @return
|
||||
*/
|
||||
public static String getErrorMessage(HttpServletRequest request, Throwable exception) {
|
||||
String errorMsg = (String) request.getAttribute(ServletUtils.ERROR_MESSAGE);
|
||||
if (StringUtils.isNotBlank(errorMsg)) {
|
||||
return errorMsg;
|
||||
}
|
||||
|
||||
Throwable ex = (Throwable) request.getAttribute(ServletUtils.ERROR_EXCEPTION);
|
||||
if (ex == null) {
|
||||
ex = (Throwable) request.getAttribute(ServletUtils.JSP_JSP_EXCEPTION);
|
||||
}
|
||||
if (ex == null && exception != null) {
|
||||
ex = exception;
|
||||
}
|
||||
if (ex != null) {
|
||||
ex = ThrowableUtils.getRootCause(ex);
|
||||
}
|
||||
|
||||
if (ex == null) {
|
||||
return "未知错误";
|
||||
} else if (ex instanceof AccessDeniedException) {
|
||||
String msg = StringUtils.defaultIfEmpty(ex.getLocalizedMessage(), "");
|
||||
if (msg.contains("AJAX403")) {
|
||||
return "AJAX403";
|
||||
}
|
||||
return "权限不足";
|
||||
}
|
||||
return ex.getClass().getSimpleName() + ":" + ex.getLocalizedMessage();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param fileName
|
||||
* @return
|
||||
|
|
243
src/main/java/cn/devezhao/rebuild/web/commons/BaseControll.java
Normal file
243
src/main/java/cn/devezhao/rebuild/web/commons/BaseControll.java
Normal file
|
@ -0,0 +1,243 @@
|
|||
package cn.devezhao.rebuild.web.commons;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.lang.ObjectUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang.math.NumberUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
|
||||
import cn.devezhao.commons.CalendarUtils;
|
||||
import cn.devezhao.commons.web.ServletUtils;
|
||||
import cn.devezhao.persist4j.Record;
|
||||
import cn.devezhao.persist4j.engine.ID;
|
||||
import cn.devezhao.rebuild.utils.AppUtils;
|
||||
|
||||
/**
|
||||
* @author zhaofang123@gmail.com
|
||||
* @since 05/21/2017
|
||||
*/
|
||||
public abstract class BaseControll {
|
||||
|
||||
public static final int CODE_OK = 0;
|
||||
public static final int CODE_FAIL = 1000;
|
||||
public static final int CODE_ERROR = 2000;
|
||||
|
||||
protected static Log LOG = LogFactory.getLog(BaseControll.class);
|
||||
|
||||
/**
|
||||
* @param resp
|
||||
*/
|
||||
protected void writeSuccess(HttpServletResponse resp) {
|
||||
writeSuccess(resp, ObjectUtils.NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resp
|
||||
* @param record
|
||||
*/
|
||||
protected void writeSuccess(HttpServletResponse resp, Record record) {
|
||||
if (record == null) {
|
||||
writeFailure(resp, "无法找到记录");
|
||||
return;
|
||||
}
|
||||
|
||||
Map<String, Object> data = new HashMap<String, Object>();
|
||||
for (Iterator<String> iter = record.getAvailableFieldIterator(); iter.hasNext(); ) {
|
||||
String f = iter.next();
|
||||
Object v = record.getObjectValue(f);
|
||||
if (v instanceof Date) {
|
||||
v = CalendarUtils.getUTCDateTimeFormat().format(v);
|
||||
} else if (v instanceof ID) {
|
||||
v = v.toString();
|
||||
}
|
||||
data.put(f, v);
|
||||
}
|
||||
writeSuccess(resp, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resp
|
||||
* @param data
|
||||
*/
|
||||
protected void writeSuccess(HttpServletResponse resp, Object data) {
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("error_code", CODE_OK);
|
||||
map.put("error_msg", "调用成功");
|
||||
if (data != null && data != ObjectUtils.NULL) {
|
||||
// ID 类型不会 toString ???
|
||||
if (Map.class.isAssignableFrom(data.getClass())) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<Object, Object> dataMap = (Map<Object, Object>) data;
|
||||
for (Object key : dataMap.keySet()) {
|
||||
Object value = dataMap.get(key);
|
||||
if (value != null && ID.class.isAssignableFrom(value.getClass())) {
|
||||
dataMap.put(key, value.toString());
|
||||
} else if (value != null && Date.class.isAssignableFrom(value.getClass())) {
|
||||
dataMap.put(key, CalendarUtils.getUTCDateTimeFormat().format(value));
|
||||
}
|
||||
}
|
||||
} else if (Object[][].class.isAssignableFrom(data.getClass())) {
|
||||
Object[][] array = (Object[][]) data;
|
||||
for (Object[] o : array) {
|
||||
for (int i = 0; i < o.length; i++) {
|
||||
Object value = o[i];
|
||||
if (value != null && ID.class.isAssignableFrom(value.getClass())) {
|
||||
o[i] = o[i].toString();
|
||||
} else if (value != null && Date.class.isAssignableFrom(value.getClass())) {
|
||||
o[i] = CalendarUtils.getUTCDateTimeFormat().format(o[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (Object[].class.isAssignableFrom(data.getClass())) {
|
||||
Object[] o = (Object[]) data;
|
||||
for (int i = 0; i < o.length; i++) {
|
||||
Object value = o[i];
|
||||
if (value != null && ID.class.isAssignableFrom(value.getClass())) {
|
||||
o[i] = o[i].toString();
|
||||
} else if (value != null && Date.class.isAssignableFrom(value.getClass())) {
|
||||
o[i] = CalendarUtils.getUTCDateTimeFormat().format(o[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
map.put("data", data);
|
||||
}
|
||||
writeJSON(resp, map);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resp
|
||||
*/
|
||||
protected void writeFailure(HttpServletResponse resp) {
|
||||
writeFailure(resp, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resp
|
||||
* @param message
|
||||
*/
|
||||
protected void writeFailure(HttpServletResponse resp, String message) {
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("error_code", CODE_FAIL);
|
||||
map.put("error_msg", message == null ? "无效请求" : message);
|
||||
writeJSON(resp, map);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resp
|
||||
* @param json
|
||||
*/
|
||||
protected void writeJSON(HttpServletResponse resp, Object json) {
|
||||
if (json == null) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
String aJSONString = null;
|
||||
if (json instanceof String) {
|
||||
aJSONString = (String) json;
|
||||
} else {
|
||||
aJSONString = JSON.toJSONString(json);
|
||||
}
|
||||
ServletUtils.writeJson(resp, aJSONString);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
protected ID getRequestUser(HttpServletRequest req) {
|
||||
ID fansId = AppUtils.getRequestUser(req);
|
||||
if (fansId == null) {
|
||||
throw new BadRequestException("无效请求用户");
|
||||
}
|
||||
return fansId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param req
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
protected ID getIdParameter(HttpServletRequest req, String name) {
|
||||
String v = req.getParameter(name);
|
||||
return ID.isId(v) ? ID.valueOf(v) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param req
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
protected ID getIdParameterNotNull(HttpServletRequest req, String name) {
|
||||
String v = req.getParameter(name);
|
||||
if (ID.isId(v)) {
|
||||
return ID.valueOf(v);
|
||||
}
|
||||
throw new BadRequestException("无效ID参数 [" + name + "=" + v + "]");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param req
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
protected String getParameter(HttpServletRequest req, String name) {
|
||||
return req.getParameter(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param req
|
||||
* @param name
|
||||
* @param defaultValue
|
||||
* @return
|
||||
*/
|
||||
protected String getParameter(HttpServletRequest req, String name, String defaultValue) {
|
||||
return StringUtils.defaultIfBlank(getParameter(req, name), defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param req
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
protected String getParameterNotNull(HttpServletRequest req, String name) {
|
||||
String v = req.getParameter(name);
|
||||
if (StringUtils.isEmpty(v)) {
|
||||
throw new BadRequestException("无效参数 [" + name + "=" + v + "]");
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param req
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
protected Integer getIntParameter(HttpServletRequest req, String name) {
|
||||
String v = req.getParameter(name);
|
||||
if (v == null) {
|
||||
return null;
|
||||
}
|
||||
return NumberUtils.toInt(v);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param req
|
||||
* @param name
|
||||
* @param defaultValue
|
||||
* @return
|
||||
*/
|
||||
protected Integer getIntParameter(HttpServletRequest req, String name, int defaultValue) {
|
||||
Integer v = getIntParameter(req, name);
|
||||
return v == null ? (defaultValue) : v;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
Copyright 2018 DEVEZHAO(zhaofang123@gmail.com)
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package cn.devezhao.rebuild.web.commons;
|
||||
|
||||
import cn.devezhao.commons.web.JhtmlForward;
|
||||
import cn.devezhao.commons.web.RequestContext;
|
||||
|
||||
/**
|
||||
* @author zhaofang123@gmail.com
|
||||
* @since 07/25/2018
|
||||
*/
|
||||
public class JhtmlForwardExt extends JhtmlForward {
|
||||
private static final long serialVersionUID = -3419137991587451790L;
|
||||
|
||||
@Override
|
||||
public void execute(RequestContext context) throws Exception {
|
||||
context.getRequest().setAttribute("rootpath", contextPath);
|
||||
super.execute(context);
|
||||
}
|
||||
}
|
|
@ -31,6 +31,7 @@ public class RequestWatchHandler extends HandlerInterceptorAdapter {
|
|||
|
||||
private static final Set<String> IGNORE_RES = new HashSet<>();
|
||||
static {
|
||||
IGNORE_RES.add("/user/");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -38,23 +39,30 @@ public class RequestWatchHandler extends HandlerInterceptorAdapter {
|
|||
Object handler) throws Exception {
|
||||
request.setAttribute(TIMEOUT_KEY, System.currentTimeMillis());
|
||||
|
||||
String contentType = request.getContentType();
|
||||
if ("text/html".equalsIgnoreCase(contentType)) {
|
||||
}
|
||||
|
||||
ID user = AppUtils.getRequestUser(request);
|
||||
if (user != null) {
|
||||
// 线程变量
|
||||
Application.getCurrentCaller().set(user);
|
||||
} else {
|
||||
String rUrl = request.getRequestURI();
|
||||
boolean allowed = false;
|
||||
boolean isIgnore = false;
|
||||
for (String r : IGNORE_RES) {
|
||||
if (rUrl.contains(r)) {
|
||||
allowed = true;
|
||||
isIgnore = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!allowed) {
|
||||
if (!isIgnore) {
|
||||
LOG.warn("Unauthorized access [ " + rUrl + " ] from [ " + ServletUtils.getReferer(request) + " ]");
|
||||
ServletUtils.writeJson(response, AppUtils.formatClientMsg(403, "非授权访问"));
|
||||
if (ServletUtils.isAjaxRequest(request)) {
|
||||
ServletUtils.writeJson(response, AppUtils.formatClientMsg(403, "非授权访问"));
|
||||
} else {
|
||||
response.sendError(403, "登录后继续");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -86,7 +94,7 @@ public class RequestWatchHandler extends HandlerInterceptorAdapter {
|
|||
.append("\nCause: ").append(rootCause.getClass().getName())
|
||||
.append("\nMessage: ").append(rootCause.getMessage());
|
||||
LOG.error(sb, rootCause);
|
||||
ServletUtils.writeJson(response, AppUtils.formatClientMsg(500, errorMsg));
|
||||
ServletUtils.writeJson(response, AppUtils.formatClientMsg(BaseControll.CODE_ERROR, errorMsg));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
Copyright 2018 DEVEZHAO(zhaofang123@gmail.com)
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package cn.devezhao.rebuild.web.dashboard;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhaofang123@gmail.com
|
||||
* @since 07/25/2018
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping("/dashboard")
|
||||
public class DashboardControll {
|
||||
|
||||
@RequestMapping("/home")
|
||||
public String home() {
|
||||
return "/dashboard/home.jsp";
|
||||
}
|
||||
}
|
74
src/main/java/cn/devezhao/rebuild/web/user/UserControll.java
Normal file
74
src/main/java/cn/devezhao/rebuild/web/user/UserControll.java
Normal file
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
Copyright 2018 DEVEZHAO(zhaofang123@gmail.com)
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package cn.devezhao.rebuild.web.user;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import cn.devezhao.commons.EncryptUtils;
|
||||
import cn.devezhao.commons.web.ServletUtils;
|
||||
import cn.devezhao.commons.web.WebUtils;
|
||||
import cn.devezhao.rebuild.server.Application;
|
||||
import cn.devezhao.rebuild.server.Startup;
|
||||
import cn.devezhao.rebuild.web.commons.BaseControll;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhaofang123@gmail.com
|
||||
* @since 07/25/2018
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping("/user")
|
||||
public class UserControll extends BaseControll {
|
||||
|
||||
@RequestMapping("login")
|
||||
public String checkLogin(HttpServletRequest request) {
|
||||
// TODO 检查自动登录
|
||||
|
||||
request.setAttribute("rootpath", Startup.getContextPath());
|
||||
return "/user/login.jsp";
|
||||
}
|
||||
|
||||
@RequestMapping("user-login")
|
||||
public void userLogin(HttpServletRequest request, HttpServletResponse response) {
|
||||
String user = getParameterNotNull(request, "user");
|
||||
String passwd = getParameterNotNull(request, "passwd");
|
||||
|
||||
Object[] foundUser = Application.createQuery(
|
||||
"select userId,password,isDisabled from User where loginName = ?")
|
||||
.setParameter(1, user)
|
||||
.unique();
|
||||
if (foundUser == null) {
|
||||
writeFailure(response, "用户名或密码错误");
|
||||
return;
|
||||
}
|
||||
if (foundUser[1].equals(EncryptUtils.toSHA256Hex(passwd))) {
|
||||
writeFailure(response, "用户名或密码错误");
|
||||
return;
|
||||
}
|
||||
if ((boolean) foundUser[2]) {
|
||||
writeFailure(response, "用户已禁用");
|
||||
return;
|
||||
}
|
||||
|
||||
ServletUtils.setSessionAttribute(request, WebUtils.CURRENT_USER, foundUser[0]);
|
||||
writeSuccess(response);
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE metadata-config PUBLIC "-//persist4j/Metadata 0.3"
|
||||
"https://raw.githubusercontent.com/devezhao/persist4j/master/src/main/resources/metadata.dtd">
|
||||
"file:///D:/GitHub/persist4j/src/main/resources/metadata.dtd">
|
||||
<metadata-config schema-name-optimize="true" default-parent="SystemCommon">
|
||||
|
||||
<entity name="SystemCommon" type-code="000">
|
||||
|
@ -16,13 +16,15 @@
|
|||
<entity name="User" type-code="001" description="用户">
|
||||
<field name="userId" type="primary" />
|
||||
<field name="loginName" type="string" max-length="100" nullable="false" />
|
||||
<field name="email" type="string" max-length="100" default-value="N" />
|
||||
<field name="mobile" type="string" max-length="100" />
|
||||
<field name="password" type="string" max-length="300" />
|
||||
<field name="fullName" type="string" max-length="300" />
|
||||
<field name="email" type="string" max-length="100" />
|
||||
<field name="password" type="string" max-length="100" />
|
||||
<field name="fullName" type="string" max-length="100" />
|
||||
<field name="avatarUrl" type="string" max-length="300" />
|
||||
<field name="jobTitle" type="string" max-length="300" />
|
||||
<field name="jobTitle" type="string" max-length="100" />
|
||||
<field name="detpId" type="reference" ref-entity="Department" />
|
||||
<field name="isDisabled" type="bool" default-value="T" />
|
||||
<index type="unique" field-list="loginName"/>
|
||||
<index type="unique" field-list="email"/>
|
||||
</entity>
|
||||
|
||||
<entity name="Department" type-code="002" description="部门">
|
||||
|
|
|
@ -3,7 +3,24 @@
|
|||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
|
||||
|
||||
<display-name>Rebuild Server</display-name>
|
||||
<display-name>Rebuild-0.1.0</display-name>
|
||||
|
||||
<filter>
|
||||
<filter-name>characterEncodingFilter</filter-name>
|
||||
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
|
||||
<init-param>
|
||||
<param-name>encoding</param-name>
|
||||
<param-value>UTF-8</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>forceEncoding</param-name>
|
||||
<param-value>true</param-value>
|
||||
</init-param>
|
||||
</filter>
|
||||
<filter-mapping>
|
||||
<filter-name>characterEncodingFilter</filter-name>
|
||||
<url-pattern>/*</url-pattern>
|
||||
</filter-mapping>
|
||||
|
||||
<context-param>
|
||||
<param-name>contextConfigLocation</param-name>
|
||||
|
@ -33,6 +50,15 @@
|
|||
<load-on-startup>1</load-on-startup>
|
||||
</servlet>
|
||||
|
||||
<servlet>
|
||||
<servlet-name>JhtmlForward</servlet-name>
|
||||
<servlet-class>cn.devezhao.rebuild.web.commons.JhtmlForwardExt</servlet-class>
|
||||
</servlet>
|
||||
<servlet-mapping>
|
||||
<servlet-name>JhtmlForward</servlet-name>
|
||||
<url-pattern>*.htm</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
<servlet-mapping>
|
||||
<servlet-name>default</servlet-name>
|
||||
<url-pattern>/assets/*</url-pattern>
|
||||
|
@ -42,6 +68,27 @@
|
|||
<url-pattern>*.txt</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
<error-page>
|
||||
<error-code>500</error-code>
|
||||
<location>/error.jsp</location>
|
||||
</error-page>
|
||||
<error-page>
|
||||
<error-code>400</error-code>
|
||||
<location>/error.jsp</location>
|
||||
</error-page>
|
||||
<error-page>
|
||||
<error-code>404</error-code>
|
||||
<location>/error.jsp</location>
|
||||
</error-page>
|
||||
<error-page>
|
||||
<error-code>403</error-code>
|
||||
<location>/error.jsp</location>
|
||||
</error-page>
|
||||
<error-page>
|
||||
<error-code>401</error-code>
|
||||
<location>/error.jsp</location>
|
||||
</error-page>
|
||||
|
||||
<session-config>
|
||||
<session-timeout>60</session-timeout>
|
||||
</session-config>
|
||||
|
|
|
@ -1,14 +1,20 @@
|
|||
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
|
||||
<meta charSet="utf-8" />
|
||||
<meta http-equiv="x-ua-compatible" content="ie=edge" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<!-- Polyfills -->
|
||||
<%@ page import="cn.devezhao.rebuild.server.Startup"%>
|
||||
<%@ page import="cn.devezhao.commons.CalendarUtils"%>
|
||||
<% final String baseUrl = Startup.getContextPath(); %>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<!--[if IE]>
|
||||
<script src="https://as.alipayobjects.com/g/component/??es6-shim/0.35.1/es6-sham.min.js,es6-shim/0.35.1/es6-shim.min.js"></script>
|
||||
<![endif]-->
|
||||
<script src="https://cdn.bootcss.com/babel-standalone/6.26.0/babel.min.js"></script>
|
||||
<script src="https://cdn.bootcss.com/react/16.2.0/umd/react.production.min.js"></script>
|
||||
<script src="https://cdn.bootcss.com/react-dom/16.3.2/umd/react-dom.production.min.js"></script>
|
||||
<link href="https://cdn.bootcss.com/antd/3.5.2/antd.min.css" rel="stylesheet">
|
||||
<script src="https://cdn.bootcss.com/antd/3.5.2/antd-with-locales.min.js"></script>
|
||||
<script src="https://cdn.bootcss.com/antd/3.5.2/antd.min.js"></script>
|
||||
<link href="//cdn.bootcss.com/material-design-icons/3.0.1/iconfont/material-icons.min.css" rel="stylesheet">
|
||||
<link href="//cdn.bootcss.com/material-design-lite/1.3.0/material.min.css" rel="stylesheet">
|
||||
<link href="/re-build/assets/css/base.css" rel="stylesheet">
|
||||
<script src="//cdn.bootcss.com/babel-standalone/6.26.0/babel.min.js"></script>
|
||||
<script src="//cdn.bootcss.com/react/16.4.0/umd/react.production.min.js"></script>
|
||||
<script src="//cdn.bootcss.com/react-dom/16.4.0/umd/react-dom.production.min.js"></script>
|
||||
<script src="//cdn.bootcss.com/material-design-lite/1.3.0/material.min.js"></script>
|
||||
<script src="//cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
|
||||
<script>__baseUrl='<%=baseUrl%>'; __serverTime='<%=CalendarUtils.now().getTime()%>';</script>
|
||||
<script src="<%=baseUrl%>/assets/js/base.js"></script>
|
19
src/main/webapp/admin/index.jsp
Normal file
19
src/main/webapp/admin/index.jsp
Normal file
|
@ -0,0 +1,19 @@
|
|||
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<%@ include file="/_include/Head.jsp" %>
|
||||
<title>Rebuild</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root">
|
||||
<button class="mdl-button mdl-js-button mdl-button--raised mdl-button--colored">Hello MDL</button>
|
||||
|
||||
<button class="mdl-button mdl-js-button mdl-button--fab mdl-button--colored">
|
||||
<i class="material-icons">add</i>
|
||||
</button>
|
||||
</div>
|
||||
<script type="text/babel">
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
42
src/main/webapp/assets/css/base.css
Normal file
42
src/main/webapp/assets/css/base.css
Normal file
|
@ -0,0 +1,42 @@
|
|||
html, body, button, input, select, textarea, h1, h2, h3, h4, h5, h6, span, div, .cnfont, .cn {
|
||||
font-family:Roboto,San Francisco,"Helvetica Neue",Helvetica,Arial,PingFangSC-Light,"Hiragina Sans GB","WenQuanYi Micro Hei",'microsoft yahei ui','microsoft yahei',sans-serif
|
||||
}
|
||||
|
||||
.rb-drawer {
|
||||
border: 0 none;
|
||||
}
|
||||
|
||||
.rb-drawer-header {
|
||||
box-sizing: border-box;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
padding: 16px;
|
||||
height: 64px;
|
||||
}
|
||||
|
||||
.rb-layout .rb-navigation .mdl-navigation__link {
|
||||
display: flex !important;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
color: rgba(255, 255, 255, 0.56);
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.rb-layout .rb-navigation .mdl-navigation__link:hover {
|
||||
background-color: #00BCD4;
|
||||
color: #37474F;
|
||||
}
|
||||
|
||||
.rb-navigation {
|
||||
z-index: 2;
|
||||
-webkit-flex-grow: 1;
|
||||
-ms-flex-positive: 1;
|
||||
flex-grow: 1;
|
||||
}
|
||||
|
||||
.rb-navigation .mdl-navigation__link .material-icons {
|
||||
font-size: 24px;
|
||||
color: rgba(255, 255, 255, 0.56);
|
||||
margin-right: 32px;
|
||||
}
|
3
src/main/webapp/assets/js/base.js
Normal file
3
src/main/webapp/assets/js/base.js
Normal file
|
@ -0,0 +1,3 @@
|
|||
/**
|
||||
*
|
||||
*/
|
47
src/main/webapp/dashboard/home.jsp
Normal file
47
src/main/webapp/dashboard/home.jsp
Normal file
|
@ -0,0 +1,47 @@
|
|||
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<%@ include file="/_include/Head.jsp"%>
|
||||
<title>Rebuild</title>
|
||||
<style type="text/css">
|
||||
.demo-layout .mdl-layout__header .mdl-layout__drawer-button {
|
||||
color: rgba(0, 0, 0, 0.54);
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="mdl-layout__container">
|
||||
<div class="rb-layout mdl-layout mdl-js-layout mdl-layout--fixed-drawer mdl-layout--fixed-header">
|
||||
<header class="mdl-layout__header mdl-color--grey-100 mdl-color-text--grey-600">
|
||||
<div class="mdl-layout__header-row">
|
||||
<span class="mdl-layout-title">首页</span>
|
||||
<div class="mdl-layout-spacer"></div>
|
||||
<button class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon" id="hdrbtn">
|
||||
<i class="material-icons">more_vert</i>
|
||||
</button>
|
||||
<ul class="mdl-menu mdl-js-menu mdl-js-ripple-effect mdl-menu--bottom-right" for="hdrbtn">
|
||||
<li class="mdl-menu__item mdl-menu__item--full-bleed-divider"><a href="<%=baseUrl%>/admin/">系统设置</a></li>
|
||||
<li class="mdl-menu__item"><a href="https://github.com/devezhao/re-build/" target="_blank">fork on Github</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</header>
|
||||
<div class="mdl-layout__drawer mdl-color--blue-grey-900 mdl-color-text--blue-grey-50">
|
||||
<header class="rb-drawer-header">
|
||||
REBUILD
|
||||
</header>
|
||||
<nav class="rb-navigation mdl-navigation mdl-color--blue-grey-800">
|
||||
<a class="mdl-navigation__link" href="<%=baseUrl%>/dashboard/home"><i class="mdl-color-text--blue-grey-400 material-icons">home</i>首页</a>
|
||||
<div class="mdl-layout-spacer"></div>
|
||||
</nav>
|
||||
</div>
|
||||
<main class="mdl-layout__content mdl-color--grey-100">
|
||||
<div class="mdl-grid">
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/babel">
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
29
src/main/webapp/error.jsp
Normal file
29
src/main/webapp/error.jsp
Normal file
|
@ -0,0 +1,29 @@
|
|||
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isErrorPage="true"%>
|
||||
<%@ page import="cn.devezhao.rebuild.utils.AppUtils"%>
|
||||
<%@ page import="cn.devezhao.commons.web.ServletUtils"%>
|
||||
<%
|
||||
String errorMsg = AppUtils.getErrorMessage(request, exception);
|
||||
if (ServletUtils.isAjaxRequest(request)) {
|
||||
out.print(errorMsg);
|
||||
return;
|
||||
}
|
||||
Integer errorCode = (Integer) request.getAttribute(ServletUtils.ERROR_STATUS_CODE);
|
||||
errorCode = errorCode == null ? 400 : errorCode;
|
||||
%>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<%@ include file="/_include/Head.jsp" %>
|
||||
<title>提示</title>
|
||||
</head>
|
||||
<body>
|
||||
<div class="page__hd">
|
||||
<div style="text-align:center;margin-top:15%;">
|
||||
<h4 style="margin:14px;font-size:17px;line-height:1.6;font-weight:normal;color:#444;">
|
||||
<%=errorCode%>
|
||||
<div class="hide"><%=errorMsg%></div>
|
||||
</h4>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -6,14 +6,11 @@
|
|||
<title>Rebuild</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div id="root"></div>
|
||||
<script type="text/babel">
|
||||
ReactDOM.render(
|
||||
<h1>Hello React</h1>,
|
||||
document.getElementById('root')
|
||||
);
|
||||
<div style="text-align:center;margin-top:20%;"><div class="mdl-spinner mdl-spinner--single-color mdl-js-spinner is-active"></div></div>
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function(){
|
||||
location.href = 'user/login';
|
||||
});
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
|
50
src/main/webapp/user/login.jsp
Normal file
50
src/main/webapp/user/login.jsp
Normal file
|
@ -0,0 +1,50 @@
|
|||
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<%@ include file="/_include/Head.jsp" %>
|
||||
<title>用户登录</title>
|
||||
<style type="text/css">
|
||||
.rb-login{
|
||||
width: 500px;
|
||||
margin: 0 auto;
|
||||
margin-top: 10%;
|
||||
padding: 42px 0;
|
||||
}
|
||||
.rb-login > div{
|
||||
width:300px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
.mdl-textfield{font-size:14px;}
|
||||
.mdl-textfield__input{font-size:14px}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="rb-login mdl-card mdl-shadow--2dp">
|
||||
<div><h3 style="font-size:20px;margin:0;padding:0">用户登录</h3></div>
|
||||
<div class="mdl-textfield mdl-js-textfield">
|
||||
<input class="mdl-textfield__input" type="text" id="user">
|
||||
<label class="mdl-textfield__label" for="user">用户名</label>
|
||||
</div>
|
||||
<div class="mdl-textfield mdl-js-textfield">
|
||||
<input class="mdl-textfield__input" type="password" id="passwd">
|
||||
<label class="mdl-textfield__label" for="passwd">密码</label>
|
||||
</div>
|
||||
<div>
|
||||
<button class="mdl-button mdl-js-button mdl-button--raised mdl-button--colored J_login-btn" style="width:100%;font-size:15px;height:42px;">登录</button>
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function(){
|
||||
$('.J_login-btn').click(function(){
|
||||
let user = $('#user').val(),
|
||||
passwd = $('#passwd').val();
|
||||
$.post(__baseUrl + '/user/user-login', {user:user, passwd:passwd}, function(res){
|
||||
if (res.error_code == 0) location.replace('../dashboard/home');
|
||||
else alert(res.error_msg);
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -1,10 +0,0 @@
|
|||
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<%@ include file="/_Head.jsp" %>
|
||||
<title>登录</title>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
58
src/test/java/cn/devezhao/rebuild/server/SchemaGen.java
Normal file
58
src/test/java/cn/devezhao/rebuild/server/SchemaGen.java
Normal file
|
@ -0,0 +1,58 @@
|
|||
package cn.devezhao.rebuild.server;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
import cn.devezhao.persist4j.Entity;
|
||||
import cn.devezhao.persist4j.PersistManagerFactory;
|
||||
import cn.devezhao.persist4j.engine.PersistManagerFactoryImpl;
|
||||
import cn.devezhao.persist4j.metadata.impl.ConfigurationMetadataFactory;
|
||||
import cn.devezhao.persist4j.util.support.Table;
|
||||
|
||||
/**
|
||||
* 根据 METADATA 生成表的创建语句
|
||||
*
|
||||
* @author Zhao Fangfang
|
||||
* @version $Id: SchemaGen.java 3407 2017-05-05 10:09:40Z devezhao $
|
||||
* @since 0.2, 2014-4-10
|
||||
*/
|
||||
public class SchemaGen {
|
||||
|
||||
private static ApplicationContext CTX;
|
||||
private static PersistManagerFactory PMF;
|
||||
|
||||
public static void main(String[] args) {
|
||||
CTX = new ClassPathXmlApplicationContext(new String[] { "application-ctx.xml" });
|
||||
PMF = CTX.getBean(PersistManagerFactoryImpl.class);
|
||||
|
||||
genAll();
|
||||
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
static void genAll() {
|
||||
for (Entity entity : PMF.getMetadataFactory().getEntities()) {
|
||||
gen(entity.getEntityCode());
|
||||
}
|
||||
}
|
||||
|
||||
static void gen(int e) {
|
||||
Entity entity = PMF.getMetadataFactory().getEntity(e);
|
||||
Table table = new Table(
|
||||
entity,
|
||||
PMF.getDialect(),
|
||||
((ConfigurationMetadataFactory) PMF.getMetadataFactory()).getConfigDocument().getRootElement());
|
||||
|
||||
String[] ddl = table.generateDDL(true, false);
|
||||
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append("-- ************ Entity [" + entity.getName() + "] DDL ************\n");
|
||||
for (String d : ddl) {
|
||||
if (d.startsWith("drop ")) {
|
||||
d = "" + d;
|
||||
}
|
||||
sb.append(d).append("\n");
|
||||
}
|
||||
System.out.println(sb);
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue