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();
}
/*
*处理例外
*/
--例外简介
--处理例外-传递例外
declare
v_ename emp.ename%TYPE;
begin
SELECT ename INTO v_ename FROM emp
where empno=&no;
dbms_output.put_line('雇员名:'||v_ename);
exceptio
import java.util.ArrayList;
import java.util.List;
public class KickOutBadGuys {
/**
* 题目:13个坏人和13个好人站成一圈,数到7就从圈里面踢出一个来,要求把所有坏人都给踢出来,所有好人都留在圈里。请找出初始时坏人站的位置。
* Maybe you can find out
Redis.conf配置文件及相关项说明
# Redis configuration file example
# Note on units: when memory size is needed, it is possible to specifiy
# it in the usual form of 1k 5GB 4M and so forth:
#
public static String convertInputStreamToString(InputStream is) {
StringBuilder result = new StringBuilder();
if (is != null)
try {
InputStreamReader inputReader = new InputStreamRead
原文:
http://www.sitepoint.com/3-new-javascript-apis-may-want-follow/?utm_source=html5weekly&utm_medium=email
本文中,介绍3个仍然处于草稿阶段,但应该值得关注的Javascript API.
1) Web Alarm API
&