MySQL第六次作业

1,查询教师表中T2到T9之间工资大于2000并且有岗位津贴的教师所有字段数据

select * from teacher where no between "t2" and "t9"and sal>2000 and comm is not null;

2,查询教师表中教师姓名不以字母“A”开头的教师所有字段数据,用工资排序,去前三条

select * from teacher where name not like "a%" order by sal limit 3,7;

 

3,查询教师表中工资等于2000或者岗位津贴大于等于1000的教师所有字段数据

select * from teacher where sal=2000 or comm>=1000;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,以下是查询学生信息student所有记录的MyBatis程序代码: 1. 首先,我们需要在pom.xml文件添加MyBatis和MySQL的依赖: ``` <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>3.5.6</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.23</version> </dependency> ``` 2. 接着,我们需要在MyBatis的配置文件配置数据库连接信息和映射文件: ``` <?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> <environments default="development"> <environment id="development"> <transactionManager type="JDBC"/> <dataSource type="POOLED"> <property name="driver" value="com.mysql.cj.jdbc.Driver"/> <property name="url" value="jdbc:mysql://localhost:3306/homework"/> <property name="username" value="root"/> <property name="password" value="123456"/> </dataSource> </environment> </environments> <mappers> <mapper resource="mapper/StudentMapper.xml"/> </mappers> </configuration> ``` 3. 然后,我们需要创建一个Student类来映射数据库的字段: ``` public class Student { private String no; private String name; public String getNo() { return no; } public void setNo(String no) { this.no = no; } public String getName() { return name; } public void setName(String name) { this.name = name; } } ``` 4. 接着,我们需要创建一个StudentMapper接口来定义查询方法: ``` public interface StudentMapper { List<Student> findAll(); } ``` 5. 最后,我们需要创建一个StudentMapper.xml文件来实现查询方法: ``` <?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="com.example.mapper.StudentMapper"> <select id="findAll" resultType="com.example.entity.Student"> select * from student </select> </mapper> ``` 6. 在Java代码,我们可以通过以下方式来调用查询方法并输出结果: ``` SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(Resources.getResourceAsStream("mybatis-config.xml")); SqlSession sqlSession = sqlSessionFactory.openSession(); StudentMapper studentMapper = sqlSession.getMapper(StudentMapper.class); List<Student> studentList = studentMapper.findAll(); for (Student student : studentList) { System.out.println(student.getNo() + " " + student.getName()); } sqlSession.close(); ``` 同时,我们可以在MyBatis的配置文件配置日志信息: ``` <configuration> <settings> <setting name="logImpl" value="STDOUT_LOGGING"/> </settings> ... </configuration> ``` 这样,在控制台就可以看到MyBatis的日志信息了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值