/usr/sbin/mysqld --initialize-insecure --user=mysql --datadir=/data/mysql --sock=/var/lib/mysql/mysql.sock
select * from a
join b on b.class_num=a.meal_id
join c on c.cm_class=b.class_id
where c.cm_class = 1
自問(wèn)自答,已經(jīng)解決了,是發(fā)送的包過(guò)大。具體來(lái)說(shuō)是julia發(fā)送[34,0xa,0xb]會(huì)把第一個(gè)字節(jié)解釋為0x34而不是30+4導(dǎo)致包過(guò)長(zhǎng)。
1,如果程序不存在分布式,那在程序?qū)用妫苯蛹渔i,做成單線程,不需要做數(shù)據(jù)庫(kù)表鎖。
2,如果程序是分布式,可以放在緩存里(redis等),然后對(duì)存取緩存的方法加鎖。定時(shí)對(duì)緩存的數(shù)據(jù)同步到數(shù)據(jù)庫(kù)即可。
3,如果非要在mybatis里面做,建議分兩部分語(yǔ)句進(jìn)行調(diào)用。
a:select value from yh for update;
b:update yh set value = value + 1;
mybatis 的話這個(gè)可以實(shí)現(xiàn)的, 我之前是寫(xiě)過(guò)一個(gè)類似的
表結(jié)構(gòu):
CREATE TABLE `admin_menu` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增id',
`name` varchar(64) NOT NULL COMMENT '菜單名',
`parent_id` bigint(3) NOT NULL DEFAULT 0 COMMENT '父菜單的id, 如果是父菜單這個(gè)值為0',
`url` varchar(500) NOT NULL DEFAULT '' COMMENT '菜單的鏈接',
`icon` varchar(100) NOT NULL DEFAULT '' COMMENT '圖標(biāo)',
`menu_index` bigint(3) NOT NULL DEFAULT 0 COMMENT '展示的順序',
`create_time` datetime NOT NULL COMMENT '創(chuàng)建時(shí)間',
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后更新時(shí)間',
PRIMARY KEY (`id`),
KEY `uq_id` (`id`),
KEY `uq_parent_id` (`parent_id`)
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8 COMMENT='管理后臺(tái)的菜單';
其中parentId 跟你的typeParent類似, 記錄上一級(jí)的id
AdminMenu (Model):
public class AdminMenu implements Serializable {
private static final long serialVersionUID = -6535315608269812875L;
private int id;
private String name;
private int parentId;
private String url;
private String icon;
private int menuIndex;
private Date createTime;
private Date updateTime;
private List<AdminMenu> subMenus;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getParentId() {
return parentId;
}
public void setParentId(int parentId) {
this.parentId = parentId;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getIcon() {
return icon;
}
public void setIcon(String icon) {
this.icon = icon;
}
public int getMenuIndex() {
return menuIndex;
}
public void setMenuIndex(int menuIndex) {
this.menuIndex = menuIndex;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Date getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
public List<AdminMenu> getSubMenus() {
return subMenus;
}
public void setSubMenus(List<AdminMenu> subMenus) {
this.subMenus = subMenus;
}
@Override
public String toString() {
return JsonUtil.toJson(this);
}
}
Model的屬性跟表結(jié)構(gòu)一一對(duì)應(yīng), 最下面多了一個(gè)subMenu, 里面就是AdminMenu
下面是admin_menu.xml中的內(nèi)容
查詢SQL:
<select id="selectAllMenus" resultMap="adminMenuResult">
SELECT
id, name, parent_id, url, icon, menu_index, create_time, update_time
FROM
admin_menu
WHERE parent_id=0
ORDER BY menu_index
</select>
這里返回的就是adminMenuResult結(jié)果集:
<resultMap id="adminMenuResult" type="biz.menzil.admin.core.model.AdminMenu">
<id column="id" property="id"/>
<result column="name" property="name"/>
<result column="parent_id" property="parentId"/>
<result column="url" property="url"/>
<result column="icon" property="icon"/>
<result column="menu_index" property="menuIndex"/>
<result column="create_time" property="createTime"/>
<result column="update_time" property="updateTime"/>
<association property="subMenus" column="id" select="selectSubMenus"/>
</resultMap>
其中這一行是最重要的
<association property="subMenus" column="id" select="selectSubMenus"/>
這里用selectSubMenus來(lái)進(jìn)行了另一個(gè)查詢, 查詢的參數(shù)為id, 把查詢出來(lái)的結(jié)果放在Model中的subMenus屬性中.
selectSubMenus查詢SQL:
<select id="selectSubMenus" parameterType="long" resultMap="adminSubMenuResult">
select
id, name, parent_id, url, icon, menu_index, create_time, update_time
from admin_menu
where parent_id = #{id}
order by menu_index
</select>
這里就是用第一層的id來(lái)查詢有沒(méi)有子菜單. 這里的#{id}就是上面那個(gè)結(jié)果集的column參數(shù).
因?yàn)槲抑挥袃蓪硬藛? 所以這里用了一個(gè)新的結(jié)果集,跟上面的區(qū)別就是沒(méi)有subMenus字段.
adminSubMenuResult:
<resultMap id="adminSubMenuResult" type="biz.menzil.admin.core.model.AdminMenu">
<id column="id" property="id"/>
<result column="name" property="name"/>
<result column="parent_id" property="parentId"/>
<result column="url" property="url"/>
<result column="icon" property="icon"/>
<result column="menu_index" property="menuIndex"/>
<result column="create_time" property="createTime"/>
<result column="update_time" property="updateTime"/>
</resultMap>
如果你有三,四級(jí)的話你可以一個(gè)結(jié)果集. (第一層查詢的時(shí)候用id去查詢第二層, 第二層查詢的時(shí)候用第二層的id去查詢第三層...)
下面我貼一下整個(gè)的admin_menu.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="biz.menzil.admin.core.dao.AdminMenuDao">
<resultMap id="adminMenuResult" type="biz.menzil.admin.core.model.AdminMenu">
<id column="id" property="id"/>
<result column="name" property="name"/>
<result column="parent_id" property="parentId"/>
<result column="url" property="url"/>
<result column="icon" property="icon"/>
<result column="menu_index" property="menuIndex"/>
<result column="create_time" property="createTime"/>
<result column="update_time" property="updateTime"/>
<association property="subMenus" column="id" select="selectSubMenus"/>
</resultMap>
<resultMap id="adminSubMenuResult" type="biz.menzil.admin.core.model.AdminMenu">
<id column="id" property="id"/>
<result column="name" property="name"/>
<result column="parent_id" property="parentId"/>
<result column="url" property="url"/>
<result column="icon" property="icon"/>
<result column="menu_index" property="menuIndex"/>
<result column="create_time" property="createTime"/>
<result column="update_time" property="updateTime"/>
</resultMap>
<insert id="insertAdminMenu">
INSERT INTO admin_menu(name, parent_id, url, icon, menu_index, create_time)
VALUES (
#{menu.name},
#{menu.parentId},
#{menu.url},
#{menu.icon},
#{menu.menuIndex},
NOW()
)
</insert>
<select id="selectById" resultMap="adminMenuResult">
SELECT
id, name, parent_id, url, icon, menu_index, create_time, update_time
FROM
admin_menu
WHERE id = #{id}
</select>
<select id="selectAllMenus" resultMap="adminMenuResult">
SELECT
id, name, parent_id, url, icon, menu_index, create_time, update_time
FROM
admin_menu
WHERE parent_id=0
ORDER BY menu_index
</select>
<select id="selectSubMenus" parameterType="long" resultMap="adminSubMenuResult">
select
id, name, parent_id, url, icon, menu_index, create_time, update_time
from admin_menu
where parent_id = #{id}
order by menu_index
</select>
<delete id="deleteAdminMenu">
DELETE FROM
admin_menu
WHERE id=#{id}
</delete>
<update id="updateAdminMenu" >
UPDATE admin_menu
<set>
<if test="menu.name != null and menu.name != ''">
name=#{menu.name},
</if>
<if test="menu.parentId >= 0">
parent_id=#{menu.parentId},
</if>
<if test="menu.url != null and menu.url != ''">
url=#{menu.url},
</if>
<if test="menu.icon != null and menu.icon != ''">
icon=#{menu.icon},
</if>
<if test="menu.menuIndex > 0">
menu_index=#{menu.menuIndex},
</if>
</set>
WHERE id=#{menu.id}
</update>
</mapper>
如果你這么寫(xiě)條件:WHERE user_name > 'haha' AND age = 50 AND gender = 1
,那么索引就應(yīng)該建為:(age, gender, user_name)
。
原因很簡(jiǎn)單:復(fù)合索引的第一個(gè)列就用大于或小于,后面的列就廢掉了。
#確保你的teacher_class表有unique index(teacherId, classId)
SELECT teacherId,COUNT(1) FROM teacher_class
WHERE classId IN(1,2,3)
GROUP BY teacherId
HAVING COUNT(1)=3
從領(lǐng)域模型來(lái)看,余額不是用戶自身的屬性,【用戶】依賴【余額】,【余額】關(guān)聯(lián)【用戶】,所以分開(kāi)存儲(chǔ)更合理。如果因?yàn)橛囝~的變更而引起用戶信息改變,或刪除用戶后造成用戶余額不可訪問(wèn),這個(gè)聽(tīng)起來(lái)是有問(wèn)題的。況且用戶和余額可能分別有各自的狀態(tài)。
已解決.的確是線程的問(wèn)題.需要在controller層加上synchronized.
如果是修改一個(gè)表的字符集的話,用這個(gè)去試試
alter table books
convert to character set utf8mb4_unicode_ci;
買(mǎi)一本mongo的書(shū)。 然后配合mongo官網(wǎng)上的資料看。 然后在實(shí)際使用中,不斷的給自己提一些問(wèn)題,再去找解決方案。
where `type`=101 or (`type`=102 and `value` like'3301%')
是這樣嗎?沒(méi)太讀懂問(wèn)題。
你可以使用 ORM的對(duì)象操作數(shù)據(jù)庫(kù),你也可以寫(xiě)DQL操作數(shù)據(jù),你可以寫(xiě) SQL來(lái)操作數(shù)據(jù)庫(kù)。
ORM 無(wú)法涵蓋所有的SQL標(biāo)準(zhǔn),直接寫(xiě)SQL又可能會(huì)有風(fēng)險(xiǎn)。就出了DQL,語(yǔ)法還和sql很像
其實(shí)這類問(wèn)題我比較好奇的是什么應(yīng)用場(chǎng)景必須要此類功能?還是僅僅是純技術(shù)探討?如果是解決實(shí)際業(yè)務(wù)場(chǎng)景,為何不是select出來(lái)后在內(nèi)存里通過(guò)代碼邏輯實(shí)現(xiàn)后面的功能?
沒(méi)看懂PageTitle
和添加商品之間的關(guān)系啊。
如果這倆是并列的結(jié)構(gòu),那就直接寫(xiě)<PageTitle title="商品列表" />
就可以,不用單獨(dú)寫(xiě)閉合標(biāo)簽。
如果是包含關(guān)系,那就在PageTitle
的return
里面對(duì)應(yīng)的地方寫(xiě){this.props.children}
類似這樣,this.props.children
就是你用PageTitle
包起來(lái)的內(nèi)容
// PageTitle
render(){
return(
<section >
<h1></h1>
<ol></ol>
{this.props.children}
<section />
)
}
北大青鳥(niǎo)APTECH成立于1999年。依托北京大學(xué)優(yōu)質(zhì)雄厚的教育資源和背景,秉承“教育改變生活”的發(fā)展理念,致力于培養(yǎng)中國(guó)IT技能型緊缺人才,是大數(shù)據(jù)專業(yè)的國(guó)家
北大青鳥(niǎo)中博軟件學(xué)院創(chuàng)立于2003年,作為華東區(qū)著名互聯(lián)網(wǎng)學(xué)院和江蘇省首批服務(wù)外包人才培訓(xùn)基地,中博成功培育了近30000名軟件工程師走向高薪崗位,合作企業(yè)超4
中公教育集團(tuán)創(chuàng)建于1999年,經(jīng)過(guò)二十年潛心發(fā)展,已由一家北大畢業(yè)生自主創(chuàng)業(yè)的信息技術(shù)與教育服務(wù)機(jī)構(gòu),發(fā)展為教育服務(wù)業(yè)的綜合性企業(yè)集團(tuán),成為集合面授教學(xué)培訓(xùn)、網(wǎng)
達(dá)內(nèi)教育集團(tuán)成立于2002年,是一家由留學(xué)海歸創(chuàng)辦的高端職業(yè)教育培訓(xùn)機(jī)構(gòu),是中國(guó)一站式人才培養(yǎng)平臺(tái)、一站式人才輸送平臺(tái)。2014年4月3日在美國(guó)成功上市,融資1
曾工作于聯(lián)想擔(dān)任系統(tǒng)開(kāi)發(fā)工程師,曾在博彥科技股份有限公司擔(dān)任項(xiàng)目經(jīng)理從事移動(dòng)互聯(lián)網(wǎng)管理及研發(fā)工作,曾創(chuàng)辦藍(lán)懿科技有限責(zé)任公司從事總經(jīng)理職務(wù)負(fù)責(zé)iOS教學(xué)及管理工作。
浪潮集團(tuán)項(xiàng)目經(jīng)理。精通Java與.NET 技術(shù), 熟練的跨平臺(tái)面向?qū)ο箝_(kāi)發(fā)經(jīng)驗(yàn),技術(shù)功底深厚。 授課風(fēng)格 授課風(fēng)格清新自然、條理清晰、主次分明、重點(diǎn)難點(diǎn)突出、引人入勝。
精通HTML5和CSS3;Javascript及主流js庫(kù),具有快速界面開(kāi)發(fā)的能力,對(duì)瀏覽器兼容性、前端性能優(yōu)化等有深入理解。精通網(wǎng)頁(yè)制作和網(wǎng)頁(yè)游戲開(kāi)發(fā)。
具有10 年的Java 企業(yè)應(yīng)用開(kāi)發(fā)經(jīng)驗(yàn)。曾經(jīng)歷任德國(guó)Software AG 技術(shù)顧問(wèn),美國(guó)Dachieve 系統(tǒng)架構(gòu)師,美國(guó)AngelEngineers Inc. 系統(tǒng)架構(gòu)師。