mybatis|mybatis-config.xml 以及遇到的问题

  • MybatisTools 工具类
package com.wei.tools; 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 java.io.IOException; import java.io.InputStream; /** * mybatis工具类 * @author 魏小杭 */ public class MybatisTools {static SqlSessionFactory sqlSessionFactory = null; static { try { //使用Mybatis第一步 :获取sqlSessionFactory对象 String resource = "mybatis-config.xml"; InputStream inputStream = Resources.getResourceAsStream(resource); sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream); } catch (IOException e) { e.printStackTrace(); } }/** * 既然有了 SqlSessionFactory,顾名思义,我们可以从中获得 SqlSession 的实例. *qlSessionFactory.openSession(true); 的true代表提交事务 * @return */ public static SqlSession getSqlSession(){ return sqlSessionFactory.openSession(true); } }

  • mybatis-config.xml
>name="logImpl" value="https://www.it610.com/article/LOG4J"/>

【mybatis|mybatis-config.xml 以及遇到的问题】如果出现Cause: org.xml.sax.SAXParseException; lineNumber: 6; columnNumber: 5; 1 字节的 UTF-8 序列的字节 1 无效 则:`、

  • Maven静态资源导出失败问题,在pom.xml文件添加如下代码
src/main/resources **/*.properties **/*.xml true src/main/java **/*.properties **/*.xml true

  • Mapper.xml
id="getUserById" resultType="user" parameterType="Integer" resultMap="UserMap"> select * from user where id = #{id} id="selectByName" resultType="com.wei.pojo.Products" parameterType="java.lang.String">select * from products where pname like "%"#{name}"%" update products set pname = #{pname},price = #{price},pdate = #{pdate},cid = #{cid} where pid = #{pid} delete from products where pid = #{pid} insert into products value (null,#{pname},#{price},#{pdate},#{cid})

    推荐阅读