优化前后端交互
This commit is contained in:
3
.idea/compiler.xml
generated
3
.idea/compiler.xml
generated
@@ -7,7 +7,6 @@
|
|||||||
<sourceOutputDir name="target/generated-sources/annotations" />
|
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||||
<outputRelativeToContentRoot value="true" />
|
<outputRelativeToContentRoot value="true" />
|
||||||
<module name="spring-boot-apijson-server" />
|
|
||||||
</profile>
|
</profile>
|
||||||
<profile name="Annotation profile for spring-boot-server-template" enabled="true">
|
<profile name="Annotation profile for spring-boot-server-template" enabled="true">
|
||||||
<sourceOutputDir name="target/generated-sources/annotations" />
|
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||||
@@ -22,11 +21,13 @@
|
|||||||
<entry name="$MAVEN_REPOSITORY$/org/projectlombok/lombok-mapstruct-binding/0.2.0/lombok-mapstruct-binding-0.2.0.jar" />
|
<entry name="$MAVEN_REPOSITORY$/org/projectlombok/lombok-mapstruct-binding/0.2.0/lombok-mapstruct-binding-0.2.0.jar" />
|
||||||
</processorPath>
|
</processorPath>
|
||||||
<module name="spring-boot-server-template" />
|
<module name="spring-boot-server-template" />
|
||||||
|
<module name="spring-boot-apijson-server" />
|
||||||
</profile>
|
</profile>
|
||||||
</annotationProcessing>
|
</annotationProcessing>
|
||||||
</component>
|
</component>
|
||||||
<component name="JavacSettings">
|
<component name="JavacSettings">
|
||||||
<option name="ADDITIONAL_OPTIONS_OVERRIDE">
|
<option name="ADDITIONAL_OPTIONS_OVERRIDE">
|
||||||
|
<module name="spring-boot-apijson-server" options="-Amapstruct.defaultComponentModel=spring -Amapstruct.defaultInjectionStrategy=constructor" />
|
||||||
<module name="spring-boot-server-template" options="-Amapstruct.defaultComponentModel=spring -Amapstruct.defaultInjectionStrategy=constructor" />
|
<module name="spring-boot-server-template" options="-Amapstruct.defaultComponentModel=spring -Amapstruct.defaultInjectionStrategy=constructor" />
|
||||||
</option>
|
</option>
|
||||||
</component>
|
</component>
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import {onMounted} from 'vue'
|
import {onMounted} from 'vue'
|
||||||
import {
|
import {amisElideJsonapiAdaptor, amisRender,} from '@/utils.js'
|
||||||
amisElideJsonapiAdaptor,
|
|
||||||
amisRender,
|
|
||||||
} from '@/utils.js'
|
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
amisRender(
|
amisRender(
|
||||||
@@ -53,7 +50,7 @@ onMounted(() => {
|
|||||||
url: `${information.baseUrl}/jsonapi/organization`,
|
url: `${information.baseUrl}/jsonapi/organization`,
|
||||||
data: {
|
data: {
|
||||||
fields: {
|
fields: {
|
||||||
organization: 'name'
|
organization: 'code,name'
|
||||||
},
|
},
|
||||||
page: {
|
page: {
|
||||||
size: '${perPage|default:undefined}',
|
size: '${perPage|default:undefined}',
|
||||||
@@ -65,11 +62,16 @@ onMounted(() => {
|
|||||||
columns: [
|
columns: [
|
||||||
{
|
{
|
||||||
name: 'id',
|
name: 'id',
|
||||||
|
hidden: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'code',
|
||||||
label: '组织编号',
|
label: '组织编号',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'name',
|
name: 'name',
|
||||||
label: '组织名称',
|
label: '组织名称',
|
||||||
|
required: true,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package com.lanyuanxiaoyao.server.controller;
|
|||||||
|
|
||||||
import com.lanyuanxiaoyao.server.controller.base.AbstractController;
|
import com.lanyuanxiaoyao.server.controller.base.AbstractController;
|
||||||
import com.lanyuanxiaoyao.server.entity.Organization;
|
import com.lanyuanxiaoyao.server.entity.Organization;
|
||||||
|
import com.lanyuanxiaoyao.server.entity.mapper.EntityMapper;
|
||||||
|
import com.lanyuanxiaoyao.server.entity.mapper.OrganizationMapper;
|
||||||
import com.lanyuanxiaoyao.server.service.OrganizationService;
|
import com.lanyuanxiaoyao.server.service.OrganizationService;
|
||||||
import com.lanyuanxiaoyao.server.service.base.AbstractService;
|
import com.lanyuanxiaoyao.server.service.base.AbstractService;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@@ -11,15 +13,22 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("organization")
|
@RequestMapping("organization")
|
||||||
public class OrganizationController extends AbstractController<Organization, Long> {
|
public class OrganizationController extends AbstractController<Organization, Long, Organization.SaveVO> {
|
||||||
private final OrganizationService organizationService;
|
private final OrganizationService organizationService;
|
||||||
|
private final OrganizationMapper organizationMapper;
|
||||||
|
|
||||||
public OrganizationController(OrganizationService organizationService) {
|
public OrganizationController(OrganizationService organizationService, OrganizationMapper organizationMapper) {
|
||||||
this.organizationService = organizationService;
|
this.organizationService = organizationService;
|
||||||
|
this.organizationMapper = organizationMapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AbstractService<Organization, Long> getService() {
|
public AbstractService<Organization, Long> getService() {
|
||||||
return organizationService;
|
return organizationService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EntityMapper<Organization, Organization.SaveVO> getEntityMapper() {
|
||||||
|
return organizationMapper;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +1,24 @@
|
|||||||
package com.lanyuanxiaoyao.server.controller.base;
|
package com.lanyuanxiaoyao.server.controller.base;
|
||||||
|
|
||||||
|
import com.lanyuanxiaoyao.server.entity.mapper.EntityMapper;
|
||||||
import com.lanyuanxiaoyao.server.service.base.AbstractService;
|
import com.lanyuanxiaoyao.server.service.base.AbstractService;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
|
||||||
public abstract class AbstractController<ENTITY, ID> {
|
public abstract class AbstractController<ENTITY, ID, SAVE_VO> {
|
||||||
public abstract AbstractService<ENTITY, ID> getService();
|
public abstract AbstractService<ENTITY, ID> getService();
|
||||||
|
|
||||||
|
public abstract EntityMapper<ENTITY, SAVE_VO> getEntityMapper();
|
||||||
|
|
||||||
@GetMapping("/get/{id}")
|
@GetMapping("/get/{id}")
|
||||||
public ENTITY get(@PathVariable("id") ID id) {
|
public ENTITY get(@PathVariable("id") ID id) {
|
||||||
return getService().get(id);
|
return getService().get(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/save")
|
@PostMapping("/save")
|
||||||
public ID save(@RequestBody ENTITY entity) {
|
public ID save(@RequestBody SAVE_VO entity) {
|
||||||
return getService().save(entity);
|
return getService().save(getEntityMapper().fromVO(entity));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ public class Organization {
|
|||||||
@GeneratedValue(generator = "snowflakeId")
|
@GeneratedValue(generator = "snowflakeId")
|
||||||
@GenericGenerator(name = "snowflakeId", type = SnowflakeId.IdGenerator.class)
|
@GenericGenerator(name = "snowflakeId", type = SnowflakeId.IdGenerator.class)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
private String code;
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@OneToMany(fetch = FetchType.LAZY, mappedBy = "organization")
|
@OneToMany(fetch = FetchType.LAZY, mappedBy = "organization")
|
||||||
@@ -43,6 +44,7 @@ public class Organization {
|
|||||||
@ToString
|
@ToString
|
||||||
public static final class SaveVO {
|
public static final class SaveVO {
|
||||||
private Long id;
|
private Long id;
|
||||||
|
private String code;
|
||||||
private String name;
|
private String name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,9 +19,9 @@ import org.mapstruct.Mapping;
|
|||||||
DepartmentService.class,
|
DepartmentService.class,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
public abstract class DepartmentMapper implements EntityMapper<Department, DepartmentSaveVO> {
|
public interface DepartmentMapper extends EntityMapper<Department, DepartmentSaveVO> {
|
||||||
@Mapping(target = "organization", source = "organizationId")
|
@Mapping(target = "organization", source = "organizationId")
|
||||||
@Mapping(target = "parent", source = "parentId")
|
@Mapping(target = "parent", source = "parentId")
|
||||||
@Override
|
@Override
|
||||||
public abstract Department fromVO(DepartmentSaveVO saveVO);
|
Department fromVO(DepartmentSaveVO saveVO);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
package com.lanyuanxiaoyao.server.entity.mapper;
|
package com.lanyuanxiaoyao.server.entity.mapper;
|
||||||
|
|
||||||
interface EntityMapper<SE, CE> {
|
public interface EntityMapper<SE, CE> {
|
||||||
SE fromVO(CE creationVO);
|
SE fromVO(CE creationVO);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.lanyuanxiaoyao.server.entity.mapper;
|
|||||||
|
|
||||||
import com.lanyuanxiaoyao.server.entity.Organization;
|
import com.lanyuanxiaoyao.server.entity.Organization;
|
||||||
import org.mapstruct.Mapper;
|
import org.mapstruct.Mapper;
|
||||||
|
import org.mapstruct.Mapping;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 组织bean转换
|
* 组织bean转换
|
||||||
@@ -11,4 +12,7 @@ import org.mapstruct.Mapper;
|
|||||||
*/
|
*/
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface OrganizationMapper extends EntityMapper<Organization, Organization.SaveVO> {
|
public interface OrganizationMapper extends EntityMapper<Organization, Organization.SaveVO> {
|
||||||
|
@Mapping(target = "code", defaultExpression = "java(String.valueOf(creationVO.getId()))")
|
||||||
|
@Override
|
||||||
|
Organization fromVO(Organization.SaveVO creationVO);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user