1. 程式人生 > 程式設計 >JavaScript常用語句迴圈,判斷,字串換數字

JavaScript常用語句迴圈,判斷,字串換數字

今日實現了成績的功能和介面。

bean

Major類

public class Major {
    private String a;
    private String b;

    public Major(){}

    public Major(String a, String b) {
        this.a = a;
        this.b = b;
    }

    public String getA() {
        return a;
    }

    public void setA(String a) {
        this.a = a;
    }

    
public String getB() { return b; } public void setB(String b) { this.b = b; } @Override public String toString() { return "Major{" + "a='" + a + '\'' + ", b='" + b + '\'' + '}'; } }

FileDaoImpl類增加了

@Override
    
public ArrayList getPersonFile(String studentId) { Connection connection = ConnectionFactory.getConnection(); PreparedStatement preparedStatement = null; ResultSet resultSet = null; String sql = "SELECT c_name courseName,c_score score FROM \n" +" course a,userchoose b WHERE a.c_id = b.c_id AND b.u_id="+studentId; ArrayList
<Major> arr = new ArrayList<>(); try { preparedStatement = connection.prepareStatement(sql); resultSet = preparedStatement.executeQuery(); while (resultSet.next()){ Major m = new Major(); m.setA(resultSet.getString("u_id")); m.setB(resultSet.getString("u_id")); arr.add(m); } }catch (SQLException e){ e.printStackTrace(); } return arr; }

showServlet類

@WebServlet("/ShowServlet")
public class ShowServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String studentId = req.getParameter("v");
        FileService fs = new FIleServiceImpl();
        ArrayList studentUser = fs.getPersonFile(studentId);

        req.setAttribute("arr",studentUser);
        req.getRequestDispatcher("scorePage.jsp").forward(req,resp);

        String TeacherId = req.getParameter("id");
    }
}

Test3

public class Test3 {
    public static void main(String[] args) {
        for (int i=1002;i<=1025;i++){
            int score[] = new int[4];
            for (int j=0;j<4;j++){
                score[j] = (int) (Math.random()*100);
            }
            String sql = "INSERT INTO userchoose(u_id,c_id,score) VALUES("+i+",1001,"+score[0]+"),("+i+",1002,"+score[1]+
                    "),"+"("+i+",1003,"+score[2]+"),("+i+",1004,"+score[3]+")";
            FileDaoImpl fd = new FileDaoImpl();
            fd.ins(sql);
        }
    }
}

成績介面

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>成績介面</title>
</head>
<body>

<c:forEach items="${arr}" var="item">
    科目:${item.getA()}&nbsp;&nbsp;&nbsp; 成績:${item.getB()}<br>
</c:forEach>

</body>
</html>