国产亚洲精品福利在线无卡一,国产精久久一区二区三区,亚洲精品无码国模,精品久久久久久无码专区不卡

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

手機(jī)網(wǎng)站內(nèi)容模塊如何進(jìn)行網(wǎng)站宣傳推廣

手機(jī)網(wǎng)站內(nèi)容模塊,如何進(jìn)行網(wǎng)站宣傳推廣,網(wǎng)件app,搜索引擎營銷的方法不包括目錄 一、定義接口、實體類、創(chuàng)建XML文件實現(xiàn)接口) 二、MyBatis的增刪改查 🍅1、MyBatis傳遞參數(shù)查詢 🎈寫法一 🎈寫法二 🎈兩種方式的區(qū)別 🍅2、刪除操作 🍅3、根據(jù)id修改用戶名 &#x…

目錄

一、定義接口、實體類、創(chuàng)建XML文件實現(xiàn)接口)

二、MyBatis的增刪改查?

🍅1、MyBatis傳遞參數(shù)查詢

????????🎈寫法一

?????????🎈寫法二

? ? ? ? 🎈兩種方式的區(qū)別

🍅2、刪除操作

🍅3、根據(jù)id修改用戶名

🍅4、添加用戶操作

? ? ? ? 🎈返回受影響的行數(shù)

? ? ? ? 🎈返回自增id

🍅5、like查詢

🍅6、多表查詢

三、注意

🍅1、mybatisx插件報錯

🍅2、數(shù)據(jù)回滾

🍅 3、查詢某字段結(jié)果為null時



一、定義接口、實體類、創(chuàng)建XML文件實現(xiàn)接口)

注意包名:

實體類

package com.example.demo.model;import lombok.Data;import java.time.LocalDateTime;@Data
public class UserInfo {private int id;private String username;private String password;private String photo;private LocalDateTime updatatime;private LocalDateTime createtime;private int state;}

接口

package com.example.demo.dao;import com.example.demo.model.UserInfo;
import org.apache.ibatis.annotations.Mapper;import java.util.List;@Mapper  //數(shù)據(jù)持久層的標(biāo)志
public interface UserMapper {List<UserInfo> getAll();
}

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.example.demo.dao.UserMapper">
<!--    id是UserMapper的方法名--><select id="getAll" resultType="com.example.demo.model.UserInfo">
--         不寫分號select * from userinfo</select>
</mapper>

二、MyBatis的增刪改查?

🍅1、MyBatis傳遞參數(shù)查詢

????????🎈寫法一

@Param("id")與${id}相互匹配 (及時執(zhí)行)

使用id去查詢某條數(shù)據(jù)(傳參數(shù))

UserInfo getUserById(@Param("id") Integer uid);
-- 這里應(yīng)該寫${id},而不是uid
<select id="getUserById" resultType="com.example.demo.model.UserInfo">select * from userinfo where id=${id}</select>

測試類:?

@Testvoid getUserById() {UserInfo userInfo = userMapper.getUserById(1);System.out.println(userInfo.toString());}

?????????🎈寫法二

@Param("id")與#{id}相互匹配 (預(yù)執(zhí)行)

<select id="getUserById" resultType="com.example.demo.model.UserInfo">select * from userinfo where id=#{id}</select>

? ? ? ? 🎈兩種方式的區(qū)別

1.${}是直接替換;而#{}是預(yù)執(zhí)行

2.使用${}是不安全的,存在SQL注入;而#{}是安全的,不存在SQL注入

3.${}使用場景:當(dāng)業(yè)務(wù)需要傳遞SQL語句時,只能使用${},不能使用#{}。

SQL注入:將SQL代碼插入或添加到應(yīng)用(用戶)的輸入?yún)?shù)中的攻擊,之后再將這些參數(shù)傳遞給后臺的sql服務(wù)器加以解析和執(zhí)行。


🍅2、刪除操作

UserInfo getUserById(@Param("id") Integer uid);
<!--    delete操作不需要設(shè)置返回類型--><delete id="delById">delete from userinfo where id=#{id}</delete>

?測試類

@Transactional   //數(shù)據(jù)回滾:使用該注解,會執(zhí)行下面操作,但是不會真的操作數(shù)據(jù)庫中的內(nèi)容@Testvoid testGetUserById() {int id = 1;UserInfo result = userMapper.getUserById(id);System.out.println("受影響的行數(shù):"+result);}

🍅3、根據(jù)id修改用戶名

//    根據(jù)id修改用戶名
//    返回受影響行數(shù)int update(UserInfo userInfo);
<!--    默認(rèn)返回受影響的行數(shù),不需要設(shè)置resultType--><update id="update" >update userinfo set username=#{username} where id=#{id}</update>
@Transactional@Testvoid update() {UserInfo userInfo = new UserInfo();userInfo.setId(1);userInfo.setUsername("管理員");int result = userMapper.update(userInfo);System.out.println("受影響行數(shù)"+ result);}

?運行結(jié)果:


🍅4、添加用戶操作

? ? ? ? 🎈返回受影響的行數(shù)

//返回受影響字段
int add(UserInfo userInfo);
<insert id="add">insert into userinfo(username,password,photo) 
values (#{username},#{password},#{photo})</insert>
//測試類
@Testvoid add() {UserInfo userInfo = new UserInfo();userInfo.setUsername("張三");userInfo.setPassword("11111");userInfo.setPhoto("/image/default.png");int result = userMapper.add(userInfo);System.out.println("受影響的行數(shù):"+ result);}

?運行結(jié)果:

? ? ? ? 🎈返回自增id

    int insert(UserInfo userInfo);
<insert id="insert" useGeneratedKeys="true" keyColumn="id" keyProperty="id">insert into userinfo(username,password,photo) values (#{username},#{password},#{photo})</insert>
//測試類 
@Testvoid insert() {UserInfo userInfo = new UserInfo();userInfo.setUsername("李四");userInfo.setPassword("111111");userInfo.setPhoto("");int result = userMapper.insert(userInfo);System.out.println("受影響的行數(shù):" + result +"| id:"+ userInfo.getId());}

?運行結(jié)果:

?對應(yīng)關(guān)系:


🍅5、like查詢

    List<UserInfo> getListByLike(@Param("username")String username);
<select id="getListByLike" resultType="com.example.demo.model.UserInfo">select * from userinfo where username like concat('%',#{username},'%')</select>
@Testvoid getListByLike() {String username = "三";List<UserInfo> list = userMapper.getListByLike(username);System.out.println(list);}

運行結(jié)果:


🍅6、多表查詢

使用注解將sql語句和接口連接起來。

之前是,寫一個接口就要寫一個對應(yīng)的xml文件編寫sql語句。現(xiàn)在可以不使用這種方法

可以直接在接口中通過注解編寫查詢語句:

@Mapper
public interface ArticleMapper{@Select("select a.*,u.username from articleinfo a" +"left join userinfo u on a.uid=u.id")List<Articleinfo> getAll();
}

測試類:

class ArticleMapperTest {@Autowiredprivate ArticleMapper articleMapper;@Testvoid getAll() {List<Articleinfo> list = articleMapper.getAll();System.out.println(list);}
}

?


三、注意

🍅1、mybatisx插件報錯

?以上并非系統(tǒng)報錯,而是插件在報錯,告訴我們沒有設(shè)置返回的技術(shù)類型,高版本的idea遇到這種情況運行是不會報錯的。

🍅2、數(shù)據(jù)回滾

?@Transactional ? //數(shù)據(jù)回滾:使用該注解,會執(zhí)行下面操作,但是不會真的操作數(shù)據(jù)庫中的內(nèi)容

🍅 3、查詢某字段結(jié)果為null時

原因是:實體類中的屬性和數(shù)據(jù)庫表中的字段名不一致。

? ? ? ?解決方案:

????????1.將實體類中的屬性和表中的字段名保持一致(最簡單的解決方案)

? ? ? ? 2.使用sql語句中的as進(jìn)行列名(字段名)重命名,讓列名(字段名)等于屬性名

<!--   加入要查詢的字段名應(yīng)該是name,對name進(jìn)行重命名 -->
<selet id="getUserById" resultType="com.example.demo.model.UserInfo">select username as name from userinfo where id=#{id}c</select>

? ? ? ? 3.定義一個resultMap,將屬性名和字段名進(jìn)行手動映射

? ? ? ? resultMap放入mapper.xml的<mapper></mapper>中?

<resultMap id="UserMapper" type="com.example.demo.model.UserInfo"><id column="id" property="id"></id><result column="username" property="username"></result><result column="password" property="password"></result></resultMap>
<select id="getUserById" resultMap="BaseMap">select * from userinfo where id=#{id}</select>

以下是對應(yīng)關(guān)系:盡量把全部屬性映射上,否則多表查詢時可能會報錯。

上圖有個錯誤!!!??colum是表里面的字段名,property是實體類里的屬性,寫反了。

http://m.aloenet.com.cn/news/32852.html

相關(guān)文章:

  • 58網(wǎng)站怎么做優(yōu)化迅雷磁力鏈bt磁力種子
  • 合肥疫情風(fēng)險等級思億歐seo靠譜嗎
  • 天津企業(yè)網(wǎng)站建站做一個公司網(wǎng)站大概要多少錢
  • 用自己電腦做網(wǎng)站的空間百度自媒體注冊入口
  • 南寧seo費用服務(wù)短視頻seo系統(tǒng)
  • 黨政機(jī)關(guān)如何建設(shè)網(wǎng)站企業(yè)推廣網(wǎng)絡(luò)營銷外包服務(wù)
  • 做網(wǎng)站如何與美工配合日本比分預(yù)測
  • 網(wǎng)站開發(fā)速成班網(wǎng)絡(luò)軟文怎么寫
  • 天津建設(shè)工程信息網(wǎng) 官網(wǎng)首頁seo排名點擊器曝光行者seo
  • 鄂州做網(wǎng)站公司推廣營銷軟件app
  • 建設(shè)銀行梅州分行網(wǎng)站廈門seo怎么做
  • 武漢 網(wǎng)站制作案例北京建站
  • 平頂山網(wǎng)站建設(shè)費用競價排名是什么
  • 網(wǎng)站建設(shè)流程有東莞網(wǎng)站推廣方案
  • 成都模板網(wǎng)站建設(shè)網(wǎng)絡(luò)推廣優(yōu)化平臺
  • 下沙開發(fā)區(qū)建設(shè)局網(wǎng)站廣州軟文推廣公司
  • 威海做網(wǎng)站多少錢百度助手app下載
  • 網(wǎng)站建設(shè)計劃網(wǎng)絡(luò)營銷有什么崗位
  • 做網(wǎng)站論文網(wǎng)絡(luò)營銷的模式有哪些?
  • 做二手車網(wǎng)站怎么做的外貿(mào)軟件排行榜
  • 網(wǎng)站建設(shè)倒計時模板推廣引流圖片
  • 網(wǎng)站開發(fā)使用哪種語言免費網(wǎng)站站長查詢
  • 個人做網(wǎng)站如何賺錢嗎百度客服電話人工服務(wù)熱線電話
  • 北京市網(wǎng)站建設(shè)百度搜索推廣怎么做
  • 青島開發(fā)區(qū)網(wǎng)站建設(shè)公司汽車seo是什么意思
  • 網(wǎng)站建設(shè)與網(wǎng)頁設(shè)計如何優(yōu)化百度seo排名
  • 魚滑怎么制作教程搜索引擎優(yōu)化seo的英文全稱是
  • 施工效果圖怎么做關(guān)鍵詞搜索優(yōu)化
  • 江蘇做網(wǎng)站公司東莞整站優(yōu)化推廣公司找火速
  • 個人電腦做網(wǎng)站服務(wù)器教程制作一個app軟件需要多少錢