中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁 > news >正文

專業(yè)做二手房的網(wǎng)站有哪些安徽網(wǎng)站seo

專業(yè)做二手房的網(wǎng)站有哪些,安徽網(wǎng)站seo,下載空間大的網(wǎng)站建設(shè),在婚戀網(wǎng)站做銷售好嗎文章目錄 1.基礎(chǔ)使用1.添加依賴2.在resouces文件下新建xml文件db.properties3.在resouces文件下新建xml文件mybatis-config-xml4.創(chuàng)建一個MybatisUtils工具類5.創(chuàng)建xml文件XxxMapper.xml映射dao層接口6.添加日志5.測試 2.增刪改查1.select2.delete3.update4.insert5.模糊查詢6.…

文章目錄

  • 1.基礎(chǔ)使用
    • 1.添加依賴
    • 2.在resouces文件下新建xml文件db.properties
    • 3.在resouces文件下新建xml文件mybatis-config-xml
    • 4.創(chuàng)建一個MybatisUtils工具類
    • 5.創(chuàng)建xml文件XxxMapper.xml映射dao層接口
    • 6.添加日志
    • 5.測試
  • 2.增刪改查
    • 1.select
    • 2.delete
    • 3.update
    • 4.insert
    • 5.模糊查詢
    • 6.分頁查詢
  • 3.起別名
    • 3.1具體的某個文件
    • 3.2給包名起別名
    • 3.3用注解起別名
  • 4.解決實(shí)體屬性名與數(shù)據(jù)庫列名不一致問題
    • 1.建一個resultMap標(biāo)簽
    • 2.引用
  • 5.使用注解
    • 5.1在接口上寫注解
    • 5.2進(jìn)行綁定
  • 6.association和collection
    • 6.1一對多
    • 6.2多對一
  • 7.動態(tài)查詢
    • 7.1模糊查詢if標(biāo)簽
    • 7.2更新數(shù)據(jù)set標(biāo)簽
    • 7.3Forech
  • 8.二級緩存
    • 8.1在mybatis-config.xml中開啟全局緩存
    • 8.1添加局部緩存,在xxMapper.xml中添加

1.基礎(chǔ)使用

1.添加依賴

<dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>8.0.18</version></dependency><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.12</version></dependency><!-- https://mvnrepository.com/artifact/org.mybatis/mybatis --><dependency><groupId>org.mybatis</groupId><artifactId>mybatis</artifactId><version>3.4.6</version></dependency>
<build>
<resources><resource><directory>src/main/resources</directory><includes><include>**/*.properties</include><include>**/*.xml</include></includes><filtering>false</filtering></resource><resource><directory>src/main/java</directory><includes><include>**/*.properties</include><include>**/*.xml</include></includes><filtering>false</filtering></resource>
</resources>
</build>

2.在resouces文件下新建xml文件db.properties

寫配置文件

driver=com.mysql.cj.jdbc.Driver
url=jdbc:mysql://localhost:3306/mybatis?serverTimezone=Asia/Shanghai&useSSL=true&useUnicode=true&characterEncoding=utf-8
username=root
password=DRsXT5ZJ6Oi55LPQ

3.在resouces文件下新建xml文件mybatis-config-xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configurationPUBLIC "-//mybatis.org//DTD Config 3.0//EN""http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration><properties resource="db.properties"/><environments default="development"><environment id="development"><transactionManager type="JDBC"/><dataSource type="POOLED"><property name="driver" value="${driver}"/><property name="url" value="${url}"/><property name="username" value="${username}"/><property name="password" value="${password}"/></dataSource></environment></environments><mappers><mapper resource="com/tuzhi/dao/UserMapper.xml"/></mappers>
</configuration>

4.創(chuàng)建一個MybatisUtils工具類

public class MybatisUtils {private static SqlSessionFactory sqlSessionFactory;static {String resource = "org/mybatis/example/mybatis-config.xml";InputStream inputStream = null;try {inputStream = Resources.getResourceAsStream(resource);} catch (IOException e) {e.printStackTrace();}sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);}public SqlSession getSqlSession() {return sqlSessionFactory.openSession();}
}

5.創(chuàng)建xml文件XxxMapper.xml映射dao層接口

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!--映射dao層接口-->
<mapper namespace="com.tuzhi.dao.UserDao">
<!--    映射接口里面的方法--><select id="getUserList" resultType="com.tuzhi.pojo.User">select * from user</select>
</mapper>

6.添加日志

<settings><setting name="logImpl" value="LOG4J"/><!--    是否開啟駝峰命名自動映射,即從經(jīng)典數(shù)據(jù)庫列名 A_COLUMN 映射到經(jīng)典 Java 屬性名 aColumn。--><setting name="mapUnderscoreToCamelCase" value="true"/><!--        開啟全局緩存--><setting name="cacheEnabled" value="true"/></settings>

5.測試

@Testpublic void test() {SqlSession sqlSession = MybatisUtils.getSqlSession();UserDao userDao = sqlSession.getMapper(UserDao.class);List<User> userList = userDao.getUserList();for (User user : userList) {System.out.println(user);}sqlSession.close();}

2.增刪改查

1.select

<select id="getUserById" resultType="com.tuzhi.pojo.User" parameterType="int">select * from user where id = #{id}</select>

2.delete

<delete id="deleteUser" parameterType="com.tuzhi.pojo.User">deletefrom USERwhere id = #{id};</delete>

3.update

<update id="updateUser" parameterType="com.tuzhi.pojo.User">update USERset name = #{name},pwd = #{pwd}where id = #{id};</update>

4.insert

<insert id="addUser" parameterType="com.tuzhi.pojo.User">insert into USER (id,name ,pwd)values (#{id},#{name},#{pwd});</insert>

5.模糊查詢

<select id="getUserListLike" resultType="com.tuzhi.pojo.User">select * from user where name like concat('%',#{name},'%')</select>

6.分頁查詢

<!--    分頁查詢--><select id="getUserLimit" parameterType="map" resultMap="userResultMap">select * from user limit #{startIndex},#{pageSize}</select>

3.起別名

3.1具體的某個文件

<typeAliases><typeAlias alias="Author" type="domain.blog.Author"/><typeAlias alias="Blog" type="domain.blog.Blog"/><typeAlias alias="Comment" type="domain.blog.Comment"/><typeAlias alias="Post" type="domain.blog.Post"/><typeAlias alias="Section" type="domain.blog.Section"/><typeAlias alias="Tag" type="domain.blog.Tag"/>
</typeAliases>

3.2給包名起別名

<typeAliases><package name="domain.blog"/>
</typeAliases>

注,用別名的時候直接用文件名,全小寫

3.3用注解起別名

@Alias("author")

注,直接在類上注解

4.解決實(shí)體屬性名與數(shù)據(jù)庫列名不一致問題

1.建一個resultMap標(biāo)簽

<resultMap id="userResultMap" type="User">//property實(shí)體類里的,column數(shù)據(jù)庫里的<id property="id" column="user_id" /><result property="username" column="user_name"/><result property="password" column="hashed_password"/>
</resultMap>

2.引用

然后在引用它的語句中設(shè)置 resultMap 屬性就行了(注意我們?nèi)サ袅?resultType 屬性)。比如:

<select id="selectUsers" resultMap="userResultMap">select user_id, user_name, hashed_passwordfrom some_tablewhere id = #{id}
</select>

5.使用注解

5.1在接口上寫注解

public interface UserMapper {//    使用注解@Select("select * from user")List<User> getUserListAnnotate();
}

5.2進(jìn)行綁定

<mappers><mapper class="com.tuzhi.dao.UserMapper"/>
</mappers>

6.association和collection

association用于對象,關(guān)聯(lián)

collection用于集合

6.1一對多

  • 實(shí)體類

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    public class Student {private int id;private String name;private Teacher teacher;
    }
    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    public class Teacher {private int id;private String name;
    }
    
  • 第一種查詢

    <!--    第一種多對一查詢-->
    <select id="getUserList1" resultMap="studentTeacher1">select * from student
    </select>
    <resultMap id="studentTeacher1" type="Student"><association property="teacher" column="tid" select="getTeacherListById"/>
    </resultMap>
    <select id="getTeacherListById" resultType="Teacher">select * from teacher where id = #{tid}
    </select>
    
  • 第二種查詢

    <!--    第二種多對一查詢-->
    <select id="getUserList2" resultMap="studentTeacher2">select s.id sid,s.name sname,t.id tid,t.name tnamefrom student s,teacher twhere s.tid = t.id
    </select>
    <resultMap id="studentTeacher2" type="Student"><result property="id" column="sid"/><result property="name" column="sname"/><association property="teacher" javaType="Teacher"><result property="id" column="tid"/><result property="name" column="tname"/></association>
    </resultMap>
    

6.2多對一

  • 實(shí)體類

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    public class Student {private int id;private String name;
    }
    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    public class Teacher {private int id;private String name;private List<Student> student;
    }
  • 第一種查詢

    <!--    第一種查詢--><select id="getTeacherListById1" resultMap="teacherStudent1">select t.id id,t.name tname,s.id sid,s.name sname,s.tid tidfrom teacher t,student swhere t.id=s.tid</select><resultMap id="teacherStudent1" type="Teacher"><result property="id" column="id"/><result property="name" column="tname"/><collection property="student" ofType="Student"><result property="id" column="sid"/><result property="name" column="sname"/></collection></resultMap>
    
  • 第二種查詢

    <!--    第二種查詢--><select id="getTeacherListById2" resultMap="teacherStudent2">select * from teacher where id = #{id}</select><resultMap id="teacherStudent2" type="Teacher"><collection property="student" javaType="Arraylist" ofType="Student" column="id" select="getStudentList"/></resultMap><select id="getStudentList" resultType="Student">select * from student where tid = #{id}</select>
    

7.動態(tài)查詢

7.1模糊查詢if標(biāo)簽

  • 接口
//查詢
List<Blog> getBlogIf(Map map);
  • if
<!--    動態(tài)sql模糊查詢-->
<select id="getBlogIf" parameterType="map" resultType="blog">select * from blog<where><if test="title != null">and title like concat('%',#{title},'%')</if><if test="author != null">and author like concat('%',#{author}.'%')</if></where></select>

7.2更新數(shù)據(jù)set標(biāo)簽

  • 接口

  • set標(biāo)簽

    <!--    動態(tài)更新數(shù)據(jù)-->
    <update id="updateBlog" parameterType="Blog">update blog<set><if test="title != null">title = #{title},</if><if test="author != null">author = #{author},</if><if test="views != null">views = #{views},</if></set>where id = #{id}
    </update>
    

7.3Forech

  • forech

    <select id="queryForeach" parameterType="map" resultType="Blog">select * from blog<where><foreach collection="ids" item="id" open="and (" separator="or" close=")">id = #{id}</foreach></where>
    </select>
    
  • 測試

    @Test
    public void queryForech() {SqlSession sqlSession = MybatisUtils.getSqlSession();BlogMapper mapper = sqlSession.getMapper(BlogMapper.class);ArrayList arrayList = new ArrayList();arrayList.add(1);arrayList.add(2);HashMap hashMap = new HashMap();hashMap.put("ids",arrayList);mapper.queryForeach(hashMap);sqlSession.close();
    }
    

8.二級緩存

8.1在mybatis-config.xml中開啟全局緩存

<setting name="cacheEnabled" value="true"/>

8.1添加局部緩存,在xxMapper.xml中添加

<cacheeviction="FIFO"flushInterval="60000"size="512"readOnly="true"/>
http://www.risenshineclean.com/news/62728.html

相關(guān)文章:

  • 深圳多語言網(wǎng)站建設(shè)長沙弧度seo
  • js怎么做打開網(wǎng)站就復(fù)制內(nèi)容網(wǎng)絡(luò)營銷推廣方式案例
  • 建網(wǎng)站業(yè)務(wù)員百度網(wǎng)絡(luò)科技有限公司
  • 打開這個網(wǎng)站你會回來感謝我的汕頭網(wǎng)站排名優(yōu)化
  • 電腦軟件推廣聯(lián)盟深圳市seo上詞多少錢
  • 福建省建設(shè)招投標(biāo)網(wǎng)站南昌seo排名公司
  • php網(wǎng)站搭建長尾關(guān)鍵詞搜索網(wǎng)站
  • b2c電子商務(wù)網(wǎng)站系統(tǒng)分析網(wǎng)絡(luò)推廣策劃
  • 戴爾cs24TY可以做網(wǎng)站嗎百度網(wǎng)址入口
  • 做網(wǎng)站和網(wǎng)站頁面設(shè)計(jì)aso優(yōu)化運(yùn)營
  • 杭州做網(wǎng)站的好公司有哪些uc瀏覽網(wǎng)頁版進(jìn)入
  • 蘇州網(wǎng)站建設(shè)點(diǎn)一點(diǎn)公司網(wǎng)站設(shè)計(jì)模板
  • 手機(jī)網(wǎng)站開發(fā)多少錢企業(yè)網(wǎng)站怎么做
  • 免費(fèi)做金融網(wǎng)站有哪些網(wǎng)站免費(fèi)優(yōu)化
  • 順德定制網(wǎng)站建設(shè)廣東seo快速排名
  • 男女做暖暖暖網(wǎng)站2345軟件為什么沒人管
  • 國外著名購物網(wǎng)站排名seo崗位工作內(nèi)容
  • html動態(tài)背景代碼seo體系百科
  • 福州網(wǎng)站建設(shè)公司自己建網(wǎng)站怎么推廣
  • 綜述題建設(shè)網(wǎng)站需要幾個步驟谷歌網(wǎng)址
  • 網(wǎng)站開發(fā)流行精準(zhǔn)客戶數(shù)據(jù)采集軟件
  • 用dw做的網(wǎng)站怎么放到網(wǎng)上google谷歌搜索主頁
  • 網(wǎng)站后臺用esayui做網(wǎng)絡(luò)營銷是學(xué)什么
  • 大連做網(wǎng)站建設(shè)怎么用模板做網(wǎng)站
  • 網(wǎng)上學(xué)編程可靠嗎佛山市seo推廣聯(lián)系方式
  • 麻陽住房和城鄉(xiāng)建設(shè)局網(wǎng)站蘭州網(wǎng)絡(luò)推廣新手
  • 哪個網(wǎng)站可以做兼職ppt模板廣州seo診斷
  • 0wordpress進(jìn)行seo網(wǎng)站建設(shè)
  • 重慶金山建設(shè)監(jiān)理有限公司網(wǎng)站長沙網(wǎng)站推廣公司排名
  • 廣州積分入學(xué)網(wǎng)站百度seo排名教程