日期:2014-05-17  浏览次数:20745 次

mybatis只能进行查找,不能进行删除,插入,更新
mybatis只能进行查找,不能进行删除,插入,更新 ,是不是哪里配置错了? 求各位大神!!~~~
mybatis.xml
XML code
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
  PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
  "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<typeAliases>
  <typeAlias alias="User" type="mvc.web.controller.User"/>
</typeAliases>
  <environments default="development">
    <environment id="development">
      <transactionManager type="JDBC"/>
      <dataSource type="POOLED">
        <property name="driver" value="com.mysql.jdbc.Driver"/>
        <property name="url" value="jdbc:mysql://localhost:3306/test"/>
        <property name="username" value="root"/>
        <property name="password" value="123456"/>
      </dataSource>
    </environment>
  </environments>
  <mappers>
    <mapper resource="mvc/web/controller/UserMapper.xml"/>
  </mappers>
</configuration>

UserMapper.xml
XML code
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" 
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="mvc.web.controller.UserMapper">
  <cache />  
        <select id="selectUser" parameterType="String" resultType="User">
          select * from u  where name = #{name}
        </select>
        <delete id="deleteUser" parameterType="User">
        delete from u where name = #{name}
        </delete>
 </mapper>


UserMapper.java
Java code

package mvc.web.controller;
public interface UserMapper {
    User selectUser(String name);
    void deleteUser(User user);
}


User.java
Java code
package mvc.web.controller;

import java.io.Serializable;

public class User implements Serializable {
    private String id;
    private String name;
    
    public User(String id, String name) {
        super();
        this.id = id;
        this.name = name;
    }
    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    
}


单元测试 代码
Java code

package mvc.web.controller;

import java.io.IOException;
import java.io.InputStream;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;

public class Test_Mybatis {
    @Test
    public void t1(){
        String resource = "mvc/web/controller/mybatis.xml";
        InputStream inputStream = null;
        try {
            inputStream = Resources.getResourceAsStream(resource);
        } catch