CMS: content (article) management system

day-01 content:

1.Maven: structure (it can automatically import package, compile, standardize code, etc.)

1. Create a web project, and put the classes of the web project into webapp/WEB-INF/classes
 1. Kill the src generated automatically by web
 2. Create src package manually
    Src / main / Java: where java code is stored
    src/main/resource: location of configuration file
    src/test/java: test code
    Src / test / resume: the configuration file of the test

2. Basic operation of construction project

1. Create a database form
 2. Create domain
 3. Create DO layer
 4. Create service layer
 5. Create controller layer
 ----------Three profiles----------
6. Configure the web configuration file
 7. Configure applicationContext.xml file
 8. Configure applicationContext-mvc.xml file

3. Page Jump

1. Main page entered by systemcontroller (the path of js needs to be modified according to the actual path)
2.ImagesController implements database addition, deletion, modification and query

4. File upload

1.Get the information of the uploaded file: file information, file name, file name suffix, uuid,Concatenate string
2.Get the path to upload the file: req Get real path, create file new file,Obtain the parent path of the current file, and judge whether the file needs to be created upload
3.Save file transferTo
4.Add data to the database: add file name, file path, and add method
5.Path redirection: jump to the/images/query inside
6: form Configuration required in method="post" enctype="multipart/form-data"

  //Upload function
    public String upload(Images images,HttpServletRequest req) throws IllegalStateException, IOException{
        //One: get the information of the uploaded file
        //1. Get the uploaded file information
        MultipartFile fileImg = images.getFileImg();
        //2. Get the name of the document
        String filename = fileImg.getOriginalFilename();
        //3. Get the suffix of the file
        String extension = FilenameUtils.getExtension(filename);
        //4. Get the random name uuid
        String uudi = UUID.randomUUID().toString();
        //5. Splicing string
        String newFilename = uudi+"."+extension;
        //2. Access to uploaded files
        //1. Get the real path
        String realPath = req.getServletContext().getRealPath("/upload");
        //2. Create a new File
        File field = new File(realPath,newFilename);
        //3. Get the parent path
        File parentFile = field.getParentFile();
        //4. Determine whether there is an upload folder. If not, create it
        if (!parentFile.exists()) {
        //3. Save file transferTo: save the obtained file FileImg to the newly created file of field
        //4. Add data to the database
        //1. Add file name to images
        //2. Add file address to images
        //3. Submit the images data to the database;
        //Redirect: jump to / images/query in the program annotation
        return "redirect:/images/query";

Packages to import:

Key points:

1.<iframe src="..."  />
    You can set the page in the page, page in the page
2. If there is context path on the configuration: before all jump paths: ${pageContext.request.contextPath}

Tags: Database Java xml Maven

Posted on Tue, 05 Nov 2019 11:00:30 -0800 by cybtec