admin 管理员组文章数量: 887021
2023年12月23日发(作者:免费ppt模板下载知乎)
32333435363738392)ties1 driver=2 url=jdbc:mysql://localhost:3306/keith3 username=keith4 password=keith3)ties1 gger=DEBUG,CONSOLE,FILEOUT2 =true34 # CONSOLE5 E=eAppender6 old==8 =nLayout9#sionPattern=[framework] %d - %c -%-4r [%t] %-5p %c %x - %m%sionPattern=[%-5p] %d{yyyy-MM-dd HH:mm:ss} :%m%n1112 #13 # FILEOUT14 T==${}16 eSize=100000KB17 # default istrue,append to the file; if false, the replace the log file whenever restart system18 =true19 #RollingFileAppender没有DatePattern这个属性20 =nLayout21#sionPattern=[framework] %d - %c -%-4r [%t] %-5p %c %x - %m%sionPattern=[%-5p]_%d{yyyy-MM-dd HH:mm:ss} :%m%n4)User .java1 ;23 izable;45 @SuppressWarnings("serial")6 public class User implementsSerializable {78 private intid;9 privateString userName;10 privateString password;1112 publicUser(){13 }1415 public intgetId() {16 returnid;17 }18 public void setId(intid) {19 =id;20 }21 publicString getUserName() {22returnuserName;23 }24 public voidsetUserName(String userName) {25 me =userName;26 }27 publicStringgetPassword() {28 returnpassword;29 }30 public voidsetPassword(String password) {31 rd =password;32 }3334 }5)1 2 /p>
4 "/dtd/">567891617 userName,password1819202122 INSERT INTO USER() VALUES(#{userName},#{password})23242526 UPDATE USER SET userName=#{userName} ,password=#{password} WHERE id=#{id}27282930 DELETE FROM USER WHERE id=#{id}31323334 SELECT *FROM USER3536373839 SELECT *FROM USER LIMIT #{pageNow},#{pageSize}40414243 SELECT * FROM USER WHERE id=#{id}44
67 * Function : 关闭sqlSession68 */69 public static voidcloseSession(){70 SqlSession session =();71 (null);72 if(session!=null){73 ();74 }75 }76 }7)UserDao interface1 ;23 ;45 ;67 public interfaceUserDao {89 public User load(intid);10 public voidadd(User user);11 public voidupdate(User user);12 public void delete(intid);13publicUser findByName(String userName);14 public ListqueryAllUser();15 public List list(int pageNow,intpageSize);16 publicintgetAllCount();1718 }8)UserDaoImpl1 nt;23 p;4 ;5 ;67 sion;89 o;10 ;nFactoryUtil;121314 public class UserDaoImpl implementsUserDao {1516 public User load(intid){17 SqlSession session =SessionFactory().openSession();18 User user =(User) One("ById_user", id);19 ();20 returnuser;21 }2223 public voidadd(User user) {24 SqlSession session =SessionFactory().openSession();("_user", user);26 ();27 ();28 }2930 public voidupdate(User user){31 SqlSession session =SessionFactory().openSession();("_user", user);33 ();34 ();35 }3637 public void delete(intid){38 SqlSession session =SessionFactory().openSession();("_user", id);40 ();41 }4243 publicUser findByName(String userName){44 SqlSession session=SessionFactory().openSession();45 User user =(User)One("ByName_user", userName);46 ();47 returnuser;48 }4950 @SuppressWarnings("unchecked")51 public ListqueryAllUser() {52 SqlSession session=SessionFactory().openSession();53 List list =List("All_user");54 ();55 returnlist;56 }5758 @SuppressWarnings("unchecked")59 public List list(int pageNow , intpageSize){60 SqlSession session=SessionFactory().openSession();61 Map params = new HashMap();62 ("pageNow",pageNow);63 ("pageSize", pageSize);64 List list = List("List_user",params);65 ();66 returnlist;67 }6869 public intgetAllCount(){70 SqlSession session =SessionFactory().openSession();71 int count =(Integer) One("Count_user");72 ();73 returncount;74 }75
版权声明:本文标题:java中select的用法_mybaties中select用法,以及常用增删改查 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.freenas.com.cn/free/1703317340h446672.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论