updateOneArticle.jspMybatis
<%@ taglib prefix="s" uri="/struts-tags" %>
<%--
Created by IntelliJ IDEA.
User: jack
Date: 16-4-4
Time: 下午3:16
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>一个文章的修改界面</title>
</head>
<s:form action="updateonearticleaction">
<s:textfield label="标题" name="article.title" />
<s:textfield label="类别" name="article.archive" />
<s:textarea label="内容" name="article.content" cols="20" rows="3"/>
<s:submit value="修改"/>
</s:form>
<s:debug/>
</body>
</html>
struts.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<constant name="struts.devMode" value="true"/>
<package name="default" namespace="/" extends="struts-default">
<action name="useraction" class="main.java.cn.qingtianr.action.UserAction">
<result name="success">
backend.jsp
</result>
<result name="fail">
fail.jsp
</result>
</action>
<action name="articleaction" class="main.java.cn.qingtianr.action.ArticleAction" method="writeArticle">
<result name="lookarticle">
lookarticle.jsp
</result>
</action>
<action name="articleactionshow" class="main.java.cn.qingtianr.action.ArticleAction" method="showArticle">
<result name="lookarticle">
lookarticle.jsp
</result>
</action>
<action name="getarticleaction" class="main.java.cn.qingtianr.action.ArticleAction" method="getOneArticle">
<result name="post">
post.jsp
</result>
</action>
<action name="managearticleaction" class="main.java.cn.qingtianr.action.ArticleAction" method="manageArticle">
<result name="managearticle">
managearticle.jsp
</result>
</action>
<action name="updatearticleaction" class="main.java.cn.qingtianr.action.ArticleAction" method="updateArticle">
<result name="updateOneArticle">
updateOneArticle.jsp
</result>
</action>
<action name="updateonearticleaction" class="main.java.cn.qingtianr.action.ArticleAction" method="updateOneArticle">
<result name="success">
success.jsp
</result>
</action>
</package>
</struts>
ArticleDao.java
package main.java.cn.qingtianr.dao;
import main.java.cn.qingtianr.model.Article;
import java.util.ArrayList;
/**
* Created by jack on 16-3-30.
*/
public interface ArticleDao {
public Boolean addArticle(Article article);
public ArrayList<Article> showArticle();
public Article getOneArticle(String title);
public int updateArticle(Article article);
}
ArticleDao.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="main.java.cn.qingtianr.dao.ArticleDao">
<update id="updateArticle" parameterType="main.java.cn.qingtianr.model.Article">
UPDATE article SET archive = #{archive} , content =#{content} WHERE title = #{title}
</update>
</mapper>
güncelleme koşamam
ArticleServiceImpl.java
public boolean updateArticle(Article article) {
try{
System.out.println(article.getTitle());
System.out.println(article.getArchive());
System.out.println(article.getContent());
int s = MybatisSqlSessionFactory.getSession().getMapper(ArticleDao.class).updateArticle(article);
System.out.println("hello It is in updateArticle");
System.out.println(s);
}
catch (Exception e)
{
e.printStackTrace();
throw e;
}
finally
{
MybatisSqlSessionFactory.closeSession();
}
return true;
}
sql
CREATE TABLE `article` (
`title` varchar(20) NOT NULL,
`archive` varchar(20) DEFAULT NULL,
`content` varchar(100) DEFAULT NULL,
PRIMARY KEY (`title`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
Article.java ben mybatis.today yeniyim
package main.java.cn.qingtianr.model;
/**
* Created by jack on 16-3-30.
*/
public class Article {
private String title;
private String archive;
private String content;
public Article(){
}
public Article(String title, String archive, String content) {
this.title = title;
this.archive = archive;
this.content = content;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getArchive() {
return archive;
}
public void setArchive(String archive) {
this.archive = archive;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
}
, bir problem.I ArticleServiceImp.java kullanmak karşılaştı Verilerimi güncellemek için. Çalışmıyor. o kamu boolean updateArticle içinde (Madde makalesi) olduğunda söz veriyorum, makale
. ben yazınca ben it.and var s = 1 yazdırmak want.bacause budur Ve sorun olduğunu düşünüyorum Article.xml.
ben hava it.So kimse? thx.
bana yardımcı olabilir Ve istisna yoktur çözmek için çok zaman kullanılır. ArticleDao.xml içinde
Bir istisna alır mıyım, yoksa verilerin güncellenmesi alamadım sadece budur ait değişkeni değiştirmeyi deneyin? –
no exception.just çalışmıyor – jack
Bu bir longshot, ancak başlık durumunu kontrol edin. Bir vaka duyarlılığı sorunu olabilir. –