qq_34052254 2017-01-09 01:37 采纳率: 25%
浏览 1110
已采纳

求个基于SPRING MVC的于oracle 数据库的CRUD泛型实例

基础的连接已经学会了。现在求各位大大指教下泛型的CRUD怎么写。

public class Layer_tbl {
    public int layerKeyID_grp;
    public String layerElementID_grp;
    public String layerId_grp;
    public int projectId_grp;
    public int layerPid_grp;
}


上面是实体类。需要实现的方法 通常的增删改 单个查询和表全展示。
谢谢0 0.

  • 写回答

1条回答

  • engchina 2017-01-09 02:30
    关注

    example refer url:http://www.javatpoint.com/spring-mvc-crud-example

    Emp.java

    package com.javatpoint.beans;  
    
    public class Emp {  
    private int id;  
    private String name;  
    private float salary;  
    private String designation;  
    
    public int getId() {  
        return id;  
    }  
    public void setId(int id) {  
        this.id = id;  
    }  
    public String getName() {  
        return name;  
    }  
    public void setName(String name) {  
        this.name = name;  
    }  
    public float getSalary() {  
        return salary;  
    }  
    public void setSalary(float salary) {  
        this.salary = salary;  
    }  
    public String getDesignation() {  
        return designation;  
    }  
    public void setDesignation(String designation) {  
        this.designation = designation;  
    }  
    
    }  
    

    EmpDao.java

    package com.javatpoint.dao;  
    import java.sql.ResultSet;  
    import java.sql.SQLException;  
    import java.util.List;  
    import org.springframework.jdbc.core.BeanPropertyRowMapper;  
    import org.springframework.jdbc.core.JdbcTemplate;  
    import org.springframework.jdbc.core.RowMapper;  
    import com.javatpoint.beans.Emp;  
    
    public class EmpDao {  
    JdbcTemplate template;  
    
    public void setTemplate(JdbcTemplate template) {  
        this.template = template;  
    }  
    public int save(Emp p){  
        String sql="insert into Emp99(name,salary,designation)   
              values('"+p.getName()+"',"+p.getSalary()+",'"+p.getDesignation()+"')";  
        return template.update(sql);  
    }  
    public int update(Emp p){  
        String sql="update Emp99 set name='"+p.getName()+"', salary="+p.getSalary()+",   
              designation='"+p.getDesignation()+"' where id="+p.getId()+"";  
        return template.update(sql);  
    }  
    public int delete(int id){  
        String sql="delete from Emp99 where id="+id+"";  
        return template.update(sql);  
    }  
    public Emp getEmpById(int id){  
        String sql="select * from Emp99 where id=?";  
        return template.queryForObject(sql, new Object[]{id},new BeanPropertyRowMapper<Emp>(Emp.class));  
    }  
    public List<Emp> getEmployees(){  
        return template.query("select * from Emp99",new RowMapper<Emp>(){  
            public Emp mapRow(ResultSet rs, int row) throws SQLException {  
                Emp e=new Emp();  
                e.setId(rs.getInt(1));  
                e.setName(rs.getString(2));  
                e.setSalary(rs.getFloat(3));  
                e.setDesignation(rs.getString(4));  
                return e;  
            }  
        });  
    }  
    }  
    

    是你想要的吗?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题