新手,刚学习springmvc,尝试写一个简单的注册登陆系统,发现登陆一直报错,麻烦各位大佬帮一下忙看一下,感激不尽。
JDBCOperater.java
package main.User; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.RowCallbackHandler; import org.springframework.jdbc.core.namedparam.NamedParameterJdbcDaoSupport; import java.sql.ResultSet; import java.sql.SQLException; import java.util.HashMap; import java.util.Map; public class JDBCOperater extends NamedParameterJdbcDaoSupport { @Autowired JdbcTemplate jdbcTemplate=new JdbcTemplate(); public void insertNamedParameter(User user){ String sql="INSERT INTO user_t(name,password)" +"VALUES(:name,:password)"; Map<String,Object> parameters=new HashMap<String,Object>(); parameters.put("name",user.getName()); parameters.put("password",user.getPassword()); getNamedParameterJdbcTemplate().update(sql,parameters); } public int getMatchCode(String Name,String Password){ String sql="SELECT count(*) from user_t where name=? and password=?"; return jdbcTemplate.queryForObject(sql,new Object[]{Name,Password},Integer.class); } public User findUserByUserName(final String Name){ String sql="SELECT name,password from user_t where name=?"; final User user=new User(); jdbcTemplate.query(sql, new Object[]{Name}, new RowCallbackHandler() { @Override public void processRow(ResultSet resultSet) throws SQLException { user.setName(Name); user.setPassword(resultSet.getString("name")); } }); return user; } public boolean hasMatchUser(String Name,String Password){ int matchCount=getMatchCode(Name,Password); System.out.println(matchCount); if (matchCount>0){ return true; }else { return false; } } }
慕码人2483693
蝴蝶刀刀
慕森王
慕斯709654
相关分类