12.5 持久层功能实现
User.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| package org.fkit.domain; import java.io.Serializable; public class User implements Serializable { private static final long serialVersionUID = 1L; private Integer id; private String loginname; private String password; private String username; private String phone; private String address; public User() { super(); } @Override public String toString() { return "User [id=" + id + ", loginname=" + loginname + ", password=" + password + ", username=" + username + ", phone=" + phone + ", address=" + address + "]"; } }
|
Book.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| package org.fkit.domain; import java.io.Serializable; import java.util.Date;
public class Book implements Serializable { private static final long serialVersionUID = 1L; private Integer id; private String name; private String author; private String publication; private Date publicationdate; private Double price; private String image; private String remark; public Book() { super(); } @Override public String toString() { return "Book [id=" + id + ", name=" + name + ", author=" + author + ", publication=" + publication + ", publicationdate=" + publicationdate + ", price=" + price + ", image=" + image + ", remark=" + remark + "]"; } }
|
UserMapper.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| package org.fkit.mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Select; import org.fkit.domain.User;
public interface UserMapper {
@Select("select * from tb_user where loginname = #{loginname} and password = #{password}") User findWithLoginnameAndPassword( @Param("loginname") String loginname, @Param("password") String password ); }
|
BookMapper.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| package org.fkit.mapper;
import java.util.List; import org.apache.ibatis.annotations.Select; import org.fkit.domain.Book;
public interface BookMapper {
@Select(" select * from tb_book ") List<Book> findAll(); }
|
持久层包括和数据库表映射的User.java
和Book.java
两个Java Bean
对象,并使用了MyBatis
的注解映射了对应的SQL
语句
原文链接: 12.5 持久层功能实现