瀏覽代碼

add example for custom user property

zhouhao 7 年之前
父節點
當前提交
f8f4f1e225

+ 5 - 0
hsweb-examples/hsweb-examples-custom-entity/pom.xml

@@ -64,6 +64,11 @@
             <artifactId>hsweb-system-organizational-starter</artifactId>
             <version>${project.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.hswebframework.web</groupId>
+            <artifactId>hsweb-system-authorization-starter</artifactId>
+            <version>${project.version}</version>
+        </dependency>
 
     </dependencies>
 </project>

+ 9 - 0
hsweb-examples/hsweb-examples-custom-entity/src/main/java/org/hswebframework/web/example/custom/config/CustomEntityMappingCustomer.java

@@ -1,8 +1,11 @@
 package org.hswebframework.web.example.custom.config;
 
 import org.hswebframework.web.commons.entity.factory.MapperEntityFactory;
+import org.hswebframework.web.entity.authorization.UserEntity;
+import org.hswebframework.web.entity.authorization.bind.BindRoleUserEntity;
 import org.hswebframework.web.entity.organizational.OrganizationalEntity;
 import org.hswebframework.web.example.custom.entity.CustomOrganizationalEntity;
+import org.hswebframework.web.example.custom.entity.CustomUserEntity;
 import org.hswebframework.web.starter.entity.EntityMappingCustomer;
 import org.springframework.stereotype.Component;
 
@@ -18,5 +21,11 @@ public class CustomEntityMappingCustomer implements EntityMappingCustomer {
     public void customize(MapperEntityFactory entityFactory) {
         entityFactory.addMapping(OrganizationalEntity.class,
                 MapperEntityFactory.defaultMapper(CustomOrganizationalEntity.class));
+
+        entityFactory.addMapping(UserEntity.class,
+                MapperEntityFactory.defaultMapper(CustomUserEntity.class));
+
+        entityFactory.addMapping(BindRoleUserEntity.class,
+                MapperEntityFactory.defaultMapper(CustomUserEntity.class));
     }
 }

+ 4 - 2
hsweb-examples/hsweb-examples-custom-entity/src/main/java/org/hswebframework/web/example/custom/config/CustomMybatisMapperCustomer.java

@@ -14,14 +14,16 @@ public class CustomMybatisMapperCustomer implements MybatisMapperCustomer {
     @Override
     public String[] getExcludes() {
         return new String[]{
-                "classpath*:org/hswebframework/**/OrganizationalMapper.xml"
+                "classpath*:org/hswebframework/**/OrganizationalMapper.xml",
+                "classpath*:org/hswebframework/**/UserMapper.xml"
         };
     }
 
     @Override
     public String[] getIncludes() {
         return new String[]{
-                "classpath*:custom/mappers/OrganizationalMapper.xml"
+                "classpath*:custom/mappers/OrganizationalMapper.xml",
+                "classpath*:custom/mappers/UserMapper.xml"
         };
     }
 }

+ 16 - 0
hsweb-examples/hsweb-examples-custom-entity/src/main/java/org/hswebframework/web/example/custom/entity/CustomUserEntity.java

@@ -0,0 +1,16 @@
+package org.hswebframework.web.example.custom.entity;
+
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import org.hswebframework.web.entity.authorization.bind.SimpleBindRoleUserEntity;
+
+/**
+ * @author zhouhao
+ * @since 3.0
+ */
+@EqualsAndHashCode(callSuper = true)
+@Data
+public class CustomUserEntity extends SimpleBindRoleUserEntity {
+
+    private String nickName;
+}

+ 71 - 0
hsweb-examples/hsweb-examples-custom-entity/src/main/resources/custom/mappers/UserMapper.xml

@@ -0,0 +1,71 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+  ~ Copyright 2016 http://www.hswebframework.org
+  ~
+  ~ 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.
+  ~
+  -->
+
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://www.mybatis.org/dtd/mybatis-3-mapper.dtd">
+
+<mapper namespace="org.hswebframework.web.dao.authorization.UserDao">
+    <resultMap id="UserResultMap" type="org.hswebframework.web.entity.authorization.UserEntity">
+        <id property="id" column="u_id" javaType="string" jdbcType="VARCHAR"/>
+        <result property="name" column="name" javaType="string" jdbcType="VARCHAR"/>
+        <result property="username" column="username" javaType="string" jdbcType="VARCHAR"/>
+        <result property="password" column="password" javaType="String" jdbcType="VARCHAR"/>
+        <result property="salt" column="salt" javaType="String" jdbcType="VARCHAR"/>
+        <result property="status" column="status" javaType="Byte" jdbcType="NUMERIC"/>
+        <result property="createTime" column="create_time" javaType="Long" jdbcType="NUMERIC"/>
+        <result property="creatorId" column="creator_id" javaType="String" jdbcType="VARCHAR"/>
+        <result property="nickName" column="nick_name" javaType="String" jdbcType="VARCHAR"/>
+        <result property="creatorId" column="creator_id" javaType="String" jdbcType="VARCHAR"/>
+    </resultMap>
+
+    <!--用于动态生成sql所需的配置-->
+    <sql id="config">
+        <bind name="resultMapId" value="'UserResultMap'"/>
+        <bind name="tableName" value="'s_user'"/>
+    </sql>
+
+    <insert id="insert" parameterType="org.hswebframework.web.entity.authorization.UserEntity">
+        <include refid="config"/>
+        <include refid="BasicMapper.buildInsertSql"/>
+    </insert>
+
+    <delete id="deleteByPk" parameterType="String">
+        delete from s_user where u_id =#{id}
+    </delete>
+
+    <delete id="delete" parameterType="org.hswebframework.web.commons.entity.Entity">
+        <include refid="config"/>
+        <include refid="BasicMapper.buildDeleteSql"/>
+    </delete>
+
+    <update id="update" parameterType="org.hswebframework.web.commons.entity.Entity">
+        <include refid="config"/>
+        <include refid="BasicMapper.buildUpdateSql"/>
+    </update>
+
+    <select id="query" parameterType="org.hswebframework.web.commons.entity.Entity" resultMap="UserResultMap">
+        <include refid="config"/>
+        <include refid="BasicMapper.buildSelectSql"/>
+    </select>
+
+    <select id="count" parameterType="org.hswebframework.web.commons.entity.Entity" resultType="int">
+        <include refid="config"/>
+        <include refid="BasicMapper.buildTotalSql"/>
+    </select>
+</mapper>

+ 6 - 0
hsweb-examples/hsweb-examples-custom-entity/src/main/resources/hsweb-starter.js

@@ -34,6 +34,7 @@ var versions = [
     // }
 ];
 var JDBCType = java.sql.JDBCType;
+
 function install(context) {
     var database = context.database;
     database.createOrAlter("s_organization")
@@ -42,6 +43,11 @@ function install(context) {
         .addColumn().name("leader").alias("leader").comment("机构负责人").jdbcType(java.sql.JDBCType.VARCHAR).length(256).commit()
         .addColumn().name("other_property").alias("otherProperty").comment("其他属性").jdbcType(java.sql.JDBCType.VARCHAR).length(32).commit()
         .comment("组织机构表").commit();
+
+    database.createOrAlter("s_user")
+        .addColumn().name("u_id").alias("id").comment("ID").jdbcType(java.sql.JDBCType.VARCHAR).length(32).primaryKey().commit()
+        .addColumn().name("nick_name").alias("nickName").comment("昵称").jdbcType(java.sql.JDBCType.VARCHAR).length(32).commit()
+        .comment("用户表").commit();
 }
 
 //设置依赖