SpringBoot和mybatis的高级应用

 
  
package com.moxi.service;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.moxi.model.News;
import com.moxi.util.Constant;
   
@Mapper
public interface NewsService {
   
   @Select("SELECT * FROM MOXI.NEWS WHERE ID = #{id};")
   News findById(News news);
   
   @Select({
      ""
   })
   List list(News news);
   
   @Select({
      ""
   })
   int count(News news);
   
   @Insert("INSERT INTO `moxi`.`news` (`id`,`title`,`description`,`category`,`image`,`content`,`addDate`,`updateDate`,`commendState`,`state`,`browses`,`likes`,`comments`,`score`) VALUES (null,#{title},#{description},#{category},#{image},#{content},now(),now(),1,1,0,0,0,0);")
   int insert(News news);

   @Update("UPDATE `moxi`.`news` SET `title` = #{title}, `description` = #{description}, `category` = #{category}, `image` = #{image}, `content` = #{content}, `updateDate` = now()  WHERE `id` = #{id};")
   int update(News news);
   
   @Update("UPDATE `moxi`.`news` SET `state` = #{state}, `commendState` = #{commendState}, `browses` = #{browses}, `likes` = #{likes}, `comments` = #{comments}, `score` = #{score} WHERE `id` = #{id};")
   int updateState(News news);
   
}
-------------
 
  
package com.moxi.service;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import com.moxi.model.NewsCategory;

@Mapper
public interface NewsCategoryService {
   
   @Select("SELECT * FROM `moxi`.`news_category` where id = #{id};")
   NewsCategory findById(NewsCategory newsCategory);
   
   @Select({
      ""
   })
   List list(NewsCategory newsCategory);
   
   @Select({
      ""
   })
   int count(NewsCategory newsCategory);
   
   @Insert("INSERT INTO `moxi`.`news_category` (`id`, `name`, `description`, `image`, `addDate`, `state`) VALUES (null, #{name}, #{description}, #{image}, now(), 1);")
   int insert(NewsCategory newsCategory);
   
   @Update("UPDATE `moxi`.`news_category`SET `name` = #{name}, `description` = #{description}, `image` = #{image} WHERE `id` = #{id};")
   int update(NewsCategory newsCategory);
   
   @Update("UPDATE `moxi`.`news_category`SET `state` = #{state} WHERE `id` = #{id};")
   int updateState(NewsCategory newsCategory);
}
--------
 
  
 
 

你可能感兴趣的:(springboot,框架整合,mybatis)