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