zoukankan      html  css  js  c++  java
  • 2.16

    今天主要还是javaweb的学习

    主要是编写了一个可以满足判断输入在进行搜索的功能
    主要就是利用正则表达式

    package com.fin.dao;
    import java.sql.Connection;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    import java.util.ArrayList;
    import java.util.List;
    import com.fin.bean.user;
    import com.fin.bean.food;
    import com.fin.util.BaseConnection;
    public class sdDao {
        public static List<food> find(String findthing)
        {
            
            List<food> list = new ArrayList<food>();
            
            String sql = "select * from food where 1=1 ";
            String shuzi= "^[0-9]+(.[0-9]{1,3})?$";
            boolean flag=findthing.matches(shuzi);
            if (flag==true) {
                sql += "and fprice like '%" + findthing + "%'";
            }
            else {
                sql += "and fname like '%" + findthing + "%'";
            }
        
            Connection conn = BaseConnection.getConnection();
            Statement state = null;
            ResultSet rs = null;
            
            try {
                state = conn.createStatement();
                rs = state.executeQuery(sql);
                food cour = null;
                while (rs.next()) {
                    
                    int id = rs.getInt("id");
                    String fcalories2 = rs.getString("fcalories");
                    String fname2 = rs.getString("fname");
                    String fprice2 = rs.getString("fprice");
                    String fcanteen2 = rs.getString("fcanteen");
                    cour = new food(id, fcalories2,fname2,fprice2,fcanteen2);
                    list.add(cour);
                }
            } catch (SQLException e) {
                // TODO 自动生成的 catch 块
                e.printStackTrace();
            }finally
            {
                BaseConnection.close(rs, state, conn);
            }
            return list;
        }
       
        
        
        
        
    
    }
  • 相关阅读:
    安卓学习记录(五)——体温表APP.2
    今日学习
    每日学习
    AS插件快速生成javabean
    LA 5842 Equipment (状态压缩+dp)
    LA 4794 Sharing Chocolate (搜索)
    LA 5844 Leet (dfs 搜索)
    uva 11627 Slalom (二分法)
    ZOJ 3031 Robotruck (dp + 单调队列)
    uva 10012 How Big Is It? (greedy + enumerate)
  • 原文地址:https://www.cnblogs.com/ljpljm/p/12319228.html
Copyright © 2011-2022 走看看