云风网
云风笔记
云风知识库
一、service/NoteApi新增updateNode接口定义
public interface NoteApi {
...
int updateNote(NoteManage noteManage);
}
二、service/impl/NoteServiceImpl接口实现逻辑
public class NoteServiceImpl implements NoteApi {
@Autowired
NoteMapper noteMapper;
...
public int updateNote(NoteManage noteManage){
int count = 0;
try {
count = noteMapper.updateNote(noteManage);
}catch (Exception err){
System.out.println(err);
}
return count;
}
}
三、mapper/NoteMapper新增接口
...
import org.apache.ibatis.annotations.Param;
public interface NoteMapper {
...
int updateNote(@Param("note") NoteManage noteManage);
}
四、新增sql语句
<update id="updateNote" parameterType="com.example.study.note.NoteManage">
update note
<trim prefix="SET" suffixOverrides=",">
<if test="null != note.name and '' != note.name">
name=#{note.name},
</if>
<if test="null != note.type and '' != note.type">
type=#{note.type},
</if>
<if test="null != note.content and '' != note.content">
name=#{note.content},
</if>
<if test="null != note.desc and '' != note.desc">
type=#{note.desc},
</if>
</trim>
where id=#{note.id}
</update>
五、NoteManage添加获取id/设置id
private int id;
public NoteManage(String name, String type, String content, String desc,String searchName,int id) {
this.name = name;
this.type = type;
this.content = content;
this.desc = desc;
this.searchName = searchName;
this.id = id;
}
...
public void setNoteId(int id){
this.id = id;
}
public int getNoteId(){
return id;
}
六、控制类NoteController新增更新逻辑
@RequestMapping(value = "/updateNote",method = RequestMethod.POST)
public Response updateNote(@RequestBody NoteManage noteManage){
int id = noteManage.getNoteId();
int count = service.updateNote(noteManage);
if(id!=0){
if(count>0){
Response response = new Response(true,"更新成功",200);
return response;
}else {
Response response = new Response(false,"更新失败",400);
return response;
}
}else {
Response response = new Response(false,"请传入id",400);
return response;
}
}
六、接口请求测试
数据库原数据
更新笔记名称
更新成功!!!