发表于: 2017-06-29 21:01:27

3 1154


1.下了个Navicat,下了个破解器,分享下破解器

2.写了实体类和Mybatis的配置,测试还没试过,没时间了明天写。

3.明天了解些索引解决下Q8-Q11


update_at和create_at没有使用long,使用的timestamp。

CREATE TABLE `student` (

  `id` int(11) NOT NULL AUTO_INCREMENT,

  `username` varchar(20) DEFAULT NULL,

  `qq` varchar(10) DEFAULT NULL,

  `type` varchar(20) DEFAULT NULL,

  `expectStudyTime` varchar(20) DEFAULT NULL,

  `graduateSchool` varchar(30) DEFAULT NULL,

  `onlineId` int(11) DEFAULT NULL,

  `link` varchar(500) DEFAULT NULL,

  `wish` varchar(100) DEFAULT NULL,

  `create_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,

  `update_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,

  PRIMARY KEY (`id`)

)


entity

public class Student {
private Integer id;
   private String username;
   private String qq;
   private String type;
   private String expectStudyTime;
   private String graduateSchool;
   private String onlineId;
   private String wish;
   public String toString(){
return "id: "+id+"username "+username+"type "+type+"expectStudentTime "+expectStudyTime+"graduateSchool "+graduateSchool+"onlineId "+onlineId+"wish "+wish;

   }

}

MapperInterface

public interface studentMapper {

/*
   * 查询所有学生
   * @return List<Student>
   * */
   List<Student> selectAllStudent();
   /*
   * 插入新学生
   * @param Student
   * */
   void addStudent(Student student);
   /*
   * 更新学生信息
   * @param Student
   * */
   void updateStudent(Student student);
   /*
   * 删除学生
   * @param Student
   * */
   void deleteStudent(Integer id);
   /*
   * 根据id查询学生信息
   * @param Integer
   * @return List<Student>
   * */
   List<Student> selectStudentById(Integer id);

}

Mapper.xml


<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="Mapper.studentMapper">
   <resultMap id="studentResultMap" type="Student">
       <id property="id" column="id"/>
       <result property="username" column="username"/>
       <result property="qq" column="qq"/>
       <result property="type" column="type"/>
       <result property="expectStudyTime" column="expectStudyTime"/>
       <result property="graduateSchool" column="graduateSchool"/>
       <result property="onlineId" column="onlineId"/>
       <result property="wish" column="wish"/>
   </resultMap>




   <select id="selectAllStudent" resultMap="studentResultMap">
       SELECT * FROM student
</select>

   <select id="selectStudentById" resultMap="studentResultMap" parameterType="int">
       SELECT * FROM student WHERE id=#{id}
</select>

   <insert id="addStudent" useGeneratedKeys="true" keyProperty="id">
       INSERT INTO
student(username,qq,type,expectStudyTime,graduateSchool,onlineId,wish)
VALUES (#{username},#{qq},#{type},#{expectStudyTime},#{graduateSchool},#{onlineId},#{wish})
</insert>

   <update id="updateStudent" parameterType="Student">
       UPDATE student SET
username=#{username},qq=#{qq},type=#{type},expectStudyTime=#{expectStudyTime},graduateSchool=#{graduateSchool},onlineId=#{onlineId},wish=#{wish}
WHERE id=#{id}
</update>

   <delete id="deleteStudent" parameterType="int">
       DELETE FROM Student WHERE id=#{id}
</delete>
</mapper>


contextConfig.xml

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
   <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
   <property name="url" value="jdbc:mysql://localhost:3306/test:"/>
   <property name="username" value="root"/>
   <property name="password" value=""/>
</bean>

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
   <property name="dataSource" ref="dataSource"/>
   <property name="configLocation" value="classpath:Mybatis.xml"/>
</bean>

<bean class="org.mybatis.spring.mapper.MapperFactoryBean">
   <property name="mapperInterface" value="Mapper.studentMapper"/>
   <property name="sqlSessionFactory" ref="sqlSessionFactory"/>
</bean>

Mybatis.xml

<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
   <typeAliases>
       <typeAlias type="entity.Student"/>
   </typeAliases>
   <mappers>
       <mapper resource="StudentMapper.xml"/>
   </mappers>
</configuration>



返回列表 返回列表
评论

    分享到