3.19作业
Posted TokaiTeio32
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了3.19作业相关的知识,希望对你有一定的参考价值。
test.java
package com.student.pojo; import com.student.util.MybatisUtils; import org.apache.ibatis.session.SqlSession; import java.util.List; import java.util.Scanner; public class Test @org.junit.Test public void stuSystem() System.out.println("1.多条件查询"); System.out.println("2.单条件查询"); System.out.println("3.学生信息更新"); System.out.print("请输入:"); Scanner scanner = new Scanner(System.in); switch (scanner.nextInt()) case 1: findArray(); break; case 2: findByAge(); break; case 3: update(); break; private void update() SqlSession session = MybatisUtils.getSession(); Scanner scanner = new Scanner(System.in); Student student = new Student(); System.out.println("输入更新id:"); student.setId(scanner.nextInt()); System.out.println("输入更新姓名:"); student.setName(scanner.next()); System.out.println("输入更新专业:"); student.setMajor(scanner.next()); System.out.println("输入更新年龄:"); student.setAge(scanner.nextInt()); System.out.println("输入更新性别:"); student.setSex(scanner.next()); session.update("edit",student); session.commit(); private static void findArray() SqlSession session = MybatisUtils.getSession(); Student student = inputSelect(); List<Student> students = session.selectList("findArray",student); for (Student s:students) System.out.println(s); public static Student inputSelect() Scanner scanner = new Scanner(System.in); Student student = new Student(); int a; do System.out.println("1.依据ID查询信息"); System.out.println("2.依据姓名查询信息"); System.out.println("3.依据专业查询信息"); System.out.println("4.依据年龄查询信息"); System.out.println("5.依据性别查询信息"); System.out.println("6.保存并结束"); System.out.print("请选择操作:"); a = scanner.nextInt(); switch (a) case 1: System.out.print("请输入ID:"); student.setId(scanner.nextInt()); break; case 2: System.out.print("请输入姓名:"); student.setName(scanner.next()); break; case 3: System.out.print("请输入专业:"); student.setMajor(scanner.next()); break; case 4: System.out.print("请输入年龄:"); student.setAge(scanner.nextInt()); break; case 5: System.out.print("请输入性别:"); student.setSex(scanner.next()); break; while (a!=6); return student; private void findByAge() SqlSession session = MybatisUtils.getSession(); System.out.println("查询小于年龄18岁的学生信息"); List<Student> students = session.selectList("findByAge",18); for (Student s:students) System.out.println("年龄小于18岁的学生信息:"+s);
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.student.pojo.Student"> <!-- 多条件查询 --> <select id="findArray" parameterType="com.student.pojo.Student" resultType="com.student.pojo.Student"> SELECT * from student <trim prefix="where" prefixOverrides="and"> <choose> <when test="id != null and id != \'\'"> and id = #id </when> <when test="name != null and name != \'\'"> and name=#name </when> <when test="major != null and major != \'\'"> and major = #major </when> <when test="age != null and age != \'\'"> and age = #age </when> <when test="sex != null and sex != \'\'"> and sex = #sex </when> </choose> </trim> </select> <select id="findByAge" parameterType="Integer" resultType="com.student.pojo.Student"> SELECT * from student where age < #id; </select> <update id="edit" parameterType="com.student.pojo.Student"> <!-- 传参的方法类型为主类的路径--> update student <trim prefix="set" suffixOverrides=","> <!-- prefix为原<set></set> suffixOverrides要去除每条if中的语句的逗号--> <if test="name != null and name != \'\'"> <!-- test中的name job phone与Customer中private的name job phone相同--> <!-- 条件与查询一样 解释:为当name不为空 同时 也不为空串--> name = #name, </if> <if test="major != null and major != \'\'"> major = #major, </if> <if test="age !=null and age != \'\'"> age = #age, </if> <if test="sex !=null and sex != \'\'"> sex = #sex </if> </trim> where id =#id </update> </mapper>
以上是关于3.19作业的主要内容,如果未能解决你的问题,请参考以下文章
一,Linux-3.19内核移植DM9000驱动(JZ2440)