package com.lsh.controller;
import com.lsh.model.Label;
import com.lsh.service.Impl.MapperService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* @author :LiuShihao
* @date :Created in 2020/11/5 3:13 下午
* @desc :
*/
@RequestMapping("/mybatis")
@RestController
public class BaseMapperController {
@Autowired
MapperService service;
@GetMapping
public List
Service
package com.lsh.service.Impl;
import com.lsh.mapper.BaseMapper;
import com.lsh.model.Label;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @author :LiuShihao
* @date :Created in 2020/11/5 3:07 下午
* @desc :
*/
@Service
public class MapperService {
@Autowired
BaseMapper baseMapper;
public List findAll(){
return baseMapper.findAll();
}
public Label findById(String id){
return baseMapper.findById(id);
}
public List findByKeyword(String label){
return baseMapper.findByKeyword(label);
}
public List findByKeywords(Label label){
return baseMapper.findByKeysords(label.getLabelname(),label.getFans());
}
public void add(Label label){
baseMapper.addLabel(label);
}
public void upadte(Label label){
baseMapper.updateLabel(label);
}
public void deleteById(String id){
baseMapper.deleteById(id);
}
}
Mapper 接口(直接使用注解)
package com.lsh.mapper;
import com.lsh.model.Label;
import org.apache.ibatis.annotations.*;
import java.util.List;
/**
* @author :LiuShihao
* @date :Created in 2020/11/5 2:22 下午
* @desc :
*/
//该注解说明该类就行相当于一个xxxMapper.xml文件
@Mapper
public interface BaseMapper {
@Select("SELECT * FROM `tb_label`")
List findAll();
@Select("SELECT * FROM `tb_label` WHERE `id` = #{id}")
Label findById(String id);
/**
* 模糊查询 -
* 因为#{} 取值出会自带引号,${}取值就是去除原值,当参数是基本数据类型,其中必须是value
* @param labelname
* @return
*/
@Select("SELECT * FROM `tb_label` WHERE `labelname` LIKE '%${value}%'")
List findByKeyword(String labelname);
/**
* Mapper接口方法中多个参数,想要注入到SQL语句中,需要使用注解@Param
* @param labelname
* @param fans
* @return
*/
@Select("SELECT * FROM `tb_label` WHERE `labelname` LIKE '%${labelname}%' AND `fans` LIKE '%${fans}%'")
List findByKeysords(@Param("labelname") String labelname,@Param("fans") String fans);
/**
* 添加
* @param label
*/
@Insert("INSERT INTO `tb_label` VALUES (#{id},#{labelname},#{state},#{count},#{recommend},#{fans})")
void addLabel (Label label);
/**
* 更新
* @param label
*/
@Update("UPDATE `tb_label` SET `labelname` = #{labelname} ,`state` = #{state},`count`=#{count},`recommend`=#{recommend},`fans`=#{fans} WHERE `id` = #{id}")
void updateLabel(Label label);
/**
* 删除
* @param id
*/
@Delete("DELETE FROM `tb_label` WHERE `id` = #{id}")
void deleteById(String id);
}
使用mapper.xml配置文件形式
mybatis-config.xml配置文件
写mybatis-config.xml配置文件,放在/resources/mybatis/
Mapper接口
# UserMapper
public interface UserMapper {
List findAllLabelByMapperXML() ;
}
# BaseMapper
public interface BaseMapper {
List findAllLabelByMapperXML();
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml&q
// for循环的进化
// 菜鸟
for (var i = 0; i < Things.length ; i++) {
// Things[i]
}
// 老鸟
for (var i = 0, len = Things.length; i < len; i++) {
// Things[i]
}
// 大师
for (var i = Things.le
the idea is from:
http://blog.csdn.net/zhanxinhang/article/details/6731134
public class MaxSubMatrix {
/**see http://blog.csdn.net/zhanxinhang/article/details/6731134
* Q35
求一个矩阵中最大的二维
使用cordova可以很方便的在手机sdcard中读写文件。
首先需要安装cordova插件:file
命令为:
cordova plugin add org.apache.cordova.file
然后就可以读写文件了,这里我先是写入一个文件,具体的JS代码为:
var datas=null;//datas need write
var directory=&
SELECT cust_id,
SUM(price) as total
FROM orders
WHERE status = 'A'
GROUP BY cust_id
HAVING total > 250
db.orders.aggregate( [
{ $match: { status: 'A' } },
{
$group: {