javaweb第四次作业

<?xml version="1.0" encoding="UTF-8" ?>
<poems>
    <poem>
        <ID>1</ID>
        <author>陶渊明</author>
        <gender>1</gender>
        <dynasty>东晋末至南朝宋初期</dynasty>
        <title>诗人和辞赋家</title>
        <style>古今隐逸诗人之宗</style>
    </poem>
    <poem>
        <ID>2</ID>
        <author>王维</author>
        <gender>1</gender>
        <dynasty>唐代</dynasty>
        <title>诗佛</title>
        <style>空灵、寂静</style>
    </poem>
    <poem>
        <ID>3</ID>
        <author>李白</author>
        <gender>1</gender>
        <dynasty>唐代</dynasty>
        <title>诗仙</title>
        <style>豪放飘逸的诗风和丰富的想象力</style>
    </poem>
    <poem>
        <ID>4</ID>
        <author>李商隐</author>
        <gender>2</gender>
        <dynasty>唐代</dynasty>
        <title>诗坛鬼才</title>
        <style>无</style>
    </poem>
    <poem>
        <ID>5</ID>
        <author>李清照</author>
        <gender>2</gender>
        <dynasty>宋代</dynasty>
        <title>女词人</title>
        <style>婉约风格</style>
    </poem>
    <poem>
        <ID>6</ID>
        <author>杜甫</author>
        <gender>1</gender>
        <dynasty>唐代</dynasty>
        <title>诗圣</title>
        <style>反映社会现实和人民疾苦</style>
    </poem>
    <poem>
        <ID>7</ID>
        <author>苏轼</author>
        <gender>1</gender>
        <dynasty>北宋</dynasty>
        <title>文学家、书画家,诗神</title>
        <style>清新豪健的诗风和独特的艺术表现力</style>
    </poem>
</poems>

package com.example.demo.utils;

import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.io.File;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.List;

public class XmlParserUtils1 {


    public static <T> List<T> parse(String file , Class<T> targetClass)  {
        ArrayList<T> list = new ArrayList<T>(); //封装解析出来的数据
        try {
            //1.获取一个解析器对象
            SAXReader saxReader = new SAXReader();
            //2.利用解析器把xml文件加载到内存中,并返回一个文档对象
            Document document = saxReader.read(new File(file));
            //3.获取到根标签
            Element rootElement = document.getRootElement();
            //4.通过根标签来获取 user 标签
            List<Element> elements = rootElement.elements("poem");

            //5.遍历集合,得到每一个 user 标签
            for (Element element : elements) {
                String ID= element.element("ID").getText();
                String author = element.element("author").getText();
                String gender = element.element("gender").getText();
                String dynasty = element.element("dynasty").getText();
                String title = element.element("title").getText();
                String style = element.element("style").getText();


                //组装数据
                Constructor<T> constructor = targetClass.getDeclaredConstructor(String.class, String.class, String.class, String.class,String.class,String.class);
                constructor.setAccessible(true);
                T object = constructor.newInstance(ID,author,gender,dynasty,title,style);


                list.add(object);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }

}
package com.example.demo.web;

public class Poem {
    private String ID;
    private String author;
    private String gender;
    private String dynasty;
    private String title;
    private String style;


    public void setID(String ID) {
        this.ID = ID;
    }

    public String getID() {
        return ID;
    }

    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public String getDynasty() {
        return dynasty;
    }

    public void setDynasty(String dynasty) {
        this.dynasty = dynasty;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getStyle() {
        return style;
    }

    public void setStyle(String style) {
        this.style = style;
    }

    @Override
    public String toString() {
        return "Poem{" +
                "ID='" + ID + '\'' +
                ", author='" + author + '\'' +
                ", gender='" + gender + '\'' +
                ", dynasty='" + dynasty + '\'' +
                ", title='" + title + '\'' +
                ", style='" + style + '\'' +
                '}';
    }

    public Poem(){

    }
    public Poem(String ID,String author,String gender,String dynasty,String title,String style){
        this.ID=ID;
        this.author=author;
        this.gender=gender;
        this.dynasty=dynasty;
        this.title=title;
        this.style=style;
    }
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>poem</title>
</head>

<link rel="stylesheet" href="element-ui/index.css">
<script src="./js/vue.js"></script>
<script src="./element-ui/index.js"></script>
<script src="./js/axios-0.18.0.js"></script>

<body>
    <h1 align="center">诗人信息列表展示</h1>
    <div id="app">
        <el-table :data="tableData" style="width:100%" stripe border >
            <el-table-column prop="ID" label="编号" align="center" min-width="20%" ></el-table-column>
            <el-table-column prop="author" label="姓名" align="center"  min-width="20%"></el-table-column>
            <el-table-column prop="gender" label="性别" align="center" min-width="20%" ></el-table-column>
            <el-table-column prop="dynasty" label="朝代" align="center"  min-width="20%" ></el-table-column>
            <el-table-column prop="title" label="头衔" align="center"  min-width="20%"></el-table-column>
            <el-table-column prop="style" label="风格" align="center"  min-width="20%"></el-table-column>
        </el-table>
    </div>
</body>

<style>
    .el-table .warning-row {
        background: oldlace;
    }
    .el-table .success-row {
        background: #f0f9eb;
    }
</style>

<script>
    new Vue({
        el: "#app",
        data() {
            return {
                tableData: []
            }
        },
        mounted(){
            axios.get('/Poem').then(res=>{
                if(res.data.code){
                    this.tableData = res.data.data;
                }
            });
        },
        methods: {
        }
    });
</script>

</html>
package com.example.demo.controller;

import com.example.demo.utils.XmlParserUtils1;
import com.example.demo.web.Poem;
import com.example.demo.web.Result;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
@RestController
public class PController {
    @RequestMapping("Poem")
    public Result list(){
        String file=this.getClass().getClassLoader().getResource("poet.xml").getFile();
        //System.out.println(file);
        List<Poem> poemList= XmlParserUtils1.parse(file, Poem.class);

        poemList.stream().forEach(poem -> {
            //处理gender
            String gender = poem.getGender();
            if ("1".equals(gender)) {
                poem.setGender("男");
            } else if ("2".equals(gender)) {
                poem.setGender("女");
            }

        });
        return Result.success(poemList);
    }




}
package com.example.demo.Dao;
import com.example.demo.web.Poem;
import org.springframework.stereotype.Repository;

import java.util.List;
@Repository
public interface PoemDao {
    public List<Poem> listPoem();
}
package com.example.demo.Dao.impl;

import com.example.demo.Dao.PoemDao;
import com.example.demo.utils.XmlParserUtils1;
import com.example.demo.web.Poem;

import java.util.List;

public class PoemDaoA implements PoemDao {
    @Override
    public List<Poem> listPoem() {
        String file=this.getClass().getClassLoader().getResource("poet.xml").getFile();
        //System.out.println(file);
        List<Poem> poemList= XmlParserUtils1.parse(file, Poem.class);
        return poemList;
    }
}
package com.example.demo.service;

import com.example.demo.web.Poem;

import java.util.List;

public interface PoemService {
    public List<Poem> listPoem();
}
package com.example.demo.service.impl;

import com.example.demo.Dao.PoemDao;
import com.example.demo.Dao.impl.PoemDaoA;
import com.example.demo.service.PoemService;
import com.example.demo.web.Poem;

import java.util.List;

public class PoemServiceA implements PoemService {
    private PoemDao poemDao=new PoemDaoA();

    @Override
    public List<Poem> listPoem() {
        List<Poem> poemList = poemDao.listPoem();
        poemList.stream().forEach(Poem -> {
            //处理gender
            String gender = Poem.getGender();
            if ("1".equals(gender)) {
                Poem.setGender("男");
            } else if ("2".equals(gender)) {
                Poem.setGender("女");
            }
        });
        return poemList;
    }
}
package com.example.demo.controller;

import com.example.demo.service.PoemService;
import com.example.demo.service.impl.PoemServiceA;
import com.example.demo.web.Poem;
import com.example.demo.web.Result;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class PoemController {
    private PoemService poemService=new PoemServiceA();
    @RequestMapping("listP")
    public Result list() {
        List<Poem> poemList=poemService.listPoem();
        return  Result.success(poemList);
    }
}
@Repository
public class PoemDaoB implements PoemDao {
    @Override
    public List<Poem> listPoem() {
        String file=this.getClass().getClassLoader().getResource("poet.xml").getFile();
        //System.out.println(file);
        List<Poem> poemList= XmlParserUtils1.parse(file, Poem.class);
        return poemList;
    }
}
@Repository
public class PoemServiceB implements PoemService {
    @Autowired
    private PoemDao poemDao;
    @Override
    public List<Poem> listPoem() {
        List<Poem> poemList = poemDao.listPoem();
        poemList.stream().forEach(Poem -> {
            //处理gender
            String gender = Poem.getGender();
            if ("1".equals(gender)) {
                Poem.setGender("男");
            } else if ("2".equals(gender)) {
                Poem.setGender("女");
            }
        });
        return poemList;
    }
}
@RestController
public class PoetController {
    @Autowired
    private PoemService poemService;
    @RequestMapping("poet")
    public Result list() {
        List<Poem> poemList=poemService.listPoem();
        return  Result.success(poemList);
    }
}

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
javaweb蛋糕商城大作业是一个基于Java语言开发的网上蛋糕商城项目。该项目旨在实现一个完整的网上蛋糕购物系统,包括用户注册登录、蛋糕浏览、购物车管理、订单提交与支付等功能。 首先,用户可以通过注册登录功能创建个人账户,并且可以查看个人信息和订单记录。其次,在蛋糕商城首页,用户可以浏览不同种类的蛋糕,包括生日蛋糕、水果蛋糕、巧克力蛋糕等,并且可以查看商品详情和价格。 在选择蛋糕后,用户可以将商品添加至购物车,并且可以对购物车进行管理,包括增加、删除商品或者修改商品数量。用户可以在购物车页面确认购买商品后,提交订单并选择支付方式进行支付。 在后台管理方面,管理员可以管理蛋糕商品信息、订单信息和用户信息,包括添加、编辑和删除商品,查看订单状态和处理退款等操作。 此外,该作业还应该考虑到安全性和交互性问题,例如用户信息的加密存储和传输以及良好的用户交互体验。 在开发过程中,需要使用到的技术包括Java语言、Spring框架、MyBatis框架、前端页面技术等。同时,需要考虑到数据库设计和性能优化等方面的问题。 总而言之,javaweb蛋糕商城大作业是一个涵盖了用户管理、商品管理、订单管理和后台管理等功能的完整项目,需要综合考虑到技术、安全和用户体验等方面的问题,是一个较为复杂和全面的实际开发项目。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值