热部署在eclipse里面默认开启,在IDE里面默认关闭
①增加依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
② eclipse热部署默认自动开启
③ idea里面要设置
1、相关偏好里开启自动编译
2、Shift+Ctrl+Alt+/,选择Registry
选 compiler.automake.allow.when.app.running
重启项目就可以了
参考:https://www.cnblogs.com/aqsunkai/p/6690574.html
深度分页常用案例:
https://www.cnblogs.com/lpfuture/p/5772055.html
https://blog.csdn.net/li772030428/article/details/52839987
MySql逆向工程之自动生成Java实体类
1、IDEA连接数据库
菜单View→Tool Windows→Database打开数据库工具窗口
2、左上角添加按钮“+”,选择数据库类型
3、mysql主机,账户密码
4、通过IDEA生成实体类
选中一张表,右键--->Scripted Extensions--->选择Generate POJOS.clj或者Generate POJOS.groovy,选择需要存放的路径,完成。注意包名、常用类型。
开发技巧:
1、保存对象时获取数据库自增id
@Options(useGeneratedKeys=true, keyProperty="id", keyColumn="id")
2、控制台打印sql语句
#增加打印sql语句,一般用于本地开发测试
mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
MyBatis动态构建SQL
- 利用XML的方式来构建动态SQL
https://www.cnblogs.com/swp520lmg/articles/5607308.html
<select id="findActiveBlogLike"
parameterType="BLOG" resultType="BLOG">
SELECT * FROM BLOG
WHERE
<trim prefix="WHERE" prefixOverrides="AND |OR ">
<choose>
<when test="title != null">
AND title like #{title}
</when>
<when test="author != null and author.name != null">
AND title like #{author.name}
</when>
<otherwise>
AND featured = 1
</otherwise>
</choose>
</trim>
</select>
<update id="updateAuthorIfNecessary"
parameterType="Author">
update Author
<trim prefix="where" prefixOverrides=",">
<set>
<if test="username != null">username=#{username},</if>
<if test="password != null">password=#{password},</if>
<if test="email != null">email=#{email}</if>
</set>
where id=#{id}
</trim>
</update>
- 利用注解完成动态SQL的构建
https://www.cnblogs.com/zhangminghui/p/4903351.html
MyBatis 提供了注解,@InsertProvider,@UpdateProvider,@DeleteProvider 和@SelectProvider,来帮助构建动态 SQL 语句,然后让MyBatis 执行这些 SQL 语句。
public String updateVideo(final Video video){
return new SQL(){{
UPDATE("video");
//条件写法
if(video.getTitle()!= null){
SET("title=#{title}");
}
if(video.getSummary()!= null){
SET("summary=#{summary}");
}
if(video.getCoverImg()!= null){
SET("cover_img=#{coverImg}");
}
if(video.getViewNum()!= null){
SET("view_num=#{viewNum}");
}
if(video.getPrice()!= null){
SET("price=#{price}");
}
if(video.getOnline()!= null){
SET("online=#{online}");
}
if(video.getPoint()!= null){
SET("point=#{point}");
}
WHERE("id=#{id}");
}}.toString();
}
@UpdateProvider(type = VideoProvider.class,method = "updateVideo")
int update(Video Video);
mybatis 整合spring之mapperLocations配置的问题
<bean id="sessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="datasource"></property>
<property name="typeAliasesPackage" value="com.fan.entity"/>
<!-- 当mybatis的xml文件和mapper接口不在相同包下时,需要用mapperLocations属性指定xml文件的路径。
*是个通配符,代表所有的文件,**代表所有目录下 -->
<property name="mapperLocations" value="classpath:com/fan/mapper/*.xml" />
<!--也可以引入mybatis配置文件
<property name="configLocation" value="classpath:mybatis/SqlMapConfig.xml"></property> -->
</bean>
<!-- 通过扫描的模式,扫描目录在com.lanyuan.mapper目录下的mapper-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.fan.mapper"></property>
</bean>
结论是:如果Mapper.xml与Mapper.class在同一个包下且同名,spring扫描Mapper.class的同时会自动扫描同名的Mapper.xml并装配到Mapper.class。
如果Mapper.xml与Mapper.class不在同一个包下或者不同名,就必须使用配置mapperLocations指定mapper.xml的位置。
此时spring是通过识别mapper.xml中的 namespace的值来确定对应的Mapper.class的。