In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Last time, I talked about the simple design of the network disk and the iterative process of upgrading.
For details, please review https://blog.51cto.com/yerikyu/2361380.
This article mainly introduces how to quickly build network cloud disk service through jHipster.
It is simple and convenient for us to build a web service using jHipster, and it is also very comfortable to start. As shown in the following figure, we can start the framework to provide us with the function of creating a project by launching the jhipster command.
After that, it is necessary to set the project name, as well as the package name, authentication method and other configuration settings. If you do not understand, it is recommended to always enter to select the default configuration, and then in the database selection column, due to the needs of the project, we choose mongodb here.
After that, we need to choose to start the warehouse. I am used to using gradle.
The rest will be fine according to the default configuration, and then it will be the same, enter all the way, waiting for the project to be created, and you will observe that the project is constantly creating new files and related dependent progress bars, waiting for the creation to be completed.
In this way, our built web service is formed, and the service can be started, but after all, the web service built through the framework is relatively simple, and we need to carry out personalized development. We can see a clear back-end service framework in the figure.
Because we have made it clear that we need to use mangodb in the process of creating the project, the framework has provided us with the docker-compose file of the mangodb database, which we can use directly, but the docker container data will not be saved at this time. If we restart the docker service, it will lead to data loss, so we need to mount a persistence volume for the container and modify the docker-compose file. Set the image to restart automatically
Version: '2'services: utils-mongodb: image: mongo:4.0.2 ports:-"27017 utils-mongodb 27017" volumes:-~ / volumes/jhipster/utils/mongodb/:/data/db/ restart: always
After the preparatory work is completed, we will begin the simple development of the network disk function. In jHipster, the relationship between objects can be expressed through JDLJHipster Domain Language, which is relatively simple. This is a simple network disk logic relationship design.
Entity UploadFile {uploadTime String} entity DownloadFile {name String downloadTime String count Instant} relationship OneToOne {UploadFile {name} to DownloadFile} / / Set pagination optionspaginate * with infinite-scrollpaginate * with paginationdto * with mapstruct// Set service options to all except fewservice all with serviceImpl// Set an angular suffixangularSuffix * with smallestpan
After the design is completed, use the command jHipster import-jdl. / jdl/p1.jdl to compile and execute the file. As for the specific principle, this article will not make an in-depth analysis. We will talk about it next time:)
After execution, it is necessary to generate the database mapper layer to complete the automatic write and read function of the data.
. / gradew build
The result is as follows
The next step is to develop service. Based on the DTO, impl and other files automatically generated by jdl, what we need is to adjust the interface. We might as well develop an interface class to upload and download. This is what the network disk is like. A remote storage device provides upload and download functions.
@ Servicepublic class FileServiceImpl implements FileService {@ Override public Object upload (Object object) {return null;} @ Override public Object download (Object object) {return null;}}
Here we mainly use the Grid component in the spring-cloud framework to realize the function of ORM, complete the writing and writing of the mongodb database, and improve our development efficiency, but this reduces the running efficiency of the code to a certain extent. This optimization idea is not introduced in this article.
@ Servicepublic class GridfsService {@ Autowired private MongoDbFactory mongodbfactory; / * insert file * @ param file * @ return * / public GridFSInputFile save (MultipartFile file) {GridFS gridFS = new GridFS (mongodbfactory.getLegacyDb ()); try {InputStream in = file.getInputStream (); String name = file.getOriginalFilename (); GridFSInputFile gridFSInputFile = gridFS.createFile (in) GridFSInputFile.setFilename (name); gridFSInputFile.setContentType (file.getContentType ()); gridFSInputFile.save (); return gridFSInputFile;} catch (Exception e) {} return null;} / * return file * / public GridFSDBFile getById (ObjectId id) {DBObject query = new BasicDBObject ("_ id", id) according to id GridFS gridFS = new GridFS (mongodbfactory.getLegacyDb ()); GridFSDBFile gridFSDBFile = gridFS.findOne (query); return gridFSDBFile;} / * * Delete * @ param id * / public void remove (String id) {GridFS gridFS = new GridFS (mongodbfactory.getLegacyDb ()); gridFS.remove (new ObjectId (id));} public void setMongodbfactory (MongoDbFactory mongodbfactory) {this.mongodbfactory = mongodbfactory }}
Well, at this point of development, the code has been developed, and the ultra-simple small disk can be officially enabled. As for the interface format, network request path and so on, jHipster has been automatically generated for you. In web.rest, you might as well read the source code, but it is simple and easy to understand. Since this is only a background page, you can test this function through debugging tools like postman. There will be an opportunity to introduce the front-end development of this page later.
Using frameworks like jHipster to assist us in development reduces a lot of work and properly improves the well-being of our development:)
The code is for reference only. You might as well have a star: https://github.com/Yerikshu/smallestpan.
Thank you.
Reference to the article:
JHipster official website: https://www.jhipster.tech
Introduction to Grid: https://www.baeldung.com/spring-data-mongodb-gridfs
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.