mybits学习2

所花时间(包括上课):

 2h

代码量(行):

 150左右

搏客量(篇):

 1

了解到的知识点:

mybits

备注(其他):

 
@Test
public void addStudent()
{
SqlSession sqlSession=mybatisUtil.getSqlSession();
studentMapper stuMapper=sqlSession.getMapper(studentMapper.class);
int res= stuMapper.addStudent(new Student(6,"无敌战胜","神",999));
if(res>0)
{
System.out.println("插入成功");
sqlSession.commit();
}
sqlSession.close();
}
@Test
public void queryAllStudents()
{
SqlSession sqlSession=mybatisUtil.getSqlSession();
studentMapper stuMapper=sqlSession.getMapper(studentMapper.class);
List<Student> students=stuMapper.getAllStudents();
for (Student student : students) {
System.out.println(student);
}
sqlSession.close();
}
@Test
public void queryStudent()
{
SqlSession sqlSession=mybatisUtil.getSqlSession();
studentMapper stuMapper=sqlSession.getMapper(studentMapper.class);
Student stu=stuMapper.getStudentById(2);
System.out.println(stu);
sqlSession.close();
}
@Test
public void updateStudnet()
{
SqlSession sqlSession=mybatisUtil.getSqlSession();
studentMapper mapper = sqlSession.getMapper(studentMapper.class);
int res=mapper.updateStudent(new Student(6,"xxxiaoxing","男",19));
if(res>0)
{
System.out.println("修改成功");
sqlSession.commit();
}
sqlSession.close();
}
@Test
public void deleteStudent()
{
SqlSession sqlSession=mybatisUtil.getSqlSession();
studentMapper mapper = sqlSession.getMapper(studentMapper.class);
int res=mapper.deleteStudent(6);
if(res>0)
{
System.out.println("删除成功");
sqlSession.commit();
}
sqlSession.close();
}

maven资源过滤问题 

在pom.xml添加<!--在build中配置resources,来防止我们资源导出失败的问题-->

<build>
      <resources>
        <resource>
          <directory>src/main/resources</directory>
          <includes>
            <include>**/*.properties</include>
            <include>**/*.xml</include>
          </includes>
          <filtering>true</filtering>
        </resource>
        <resource>
          <directory>src/main/java</directory>
          <includes>
            <include>**/*.properties</include>
            <include>**/*.xml</include>
          </includes>
          <filtering>true</filtering>
        </resource>
      </resources>
</build>

properties

这些属性可以在外部进行配置,并可以进行动态替换。

<properties resource="jdbc.properties"/>

<property name="driver" value="${jdbc.driver}"/>

<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
posted @ 2024-06-19 17:38  平安喜乐×  阅读(13)  评论(0)    收藏  举报