Jquery、註解、頁面小技巧

 

1,頁面中點擊一個按鈕,清空file框中的值:
         注:<input name=” fileText” type=”file”/>
         onClick=" fileText.select();document.selection.clear();"
2,頁面中,讓一個img的圖片顯示小手的標誌
    <img style=”cursor:pointer” src=”” />
3,頁面中直接用DAO層的方法(註解)
<s:bean name="com.dingxun.tiku.dao.impl.TopicCarDaoImpl" id="topicCarDao"></s:bean>
<s:set name="topicSize" value="#topicCarDao.findTopicSize(topicId,#session.userbean.frontUserId)"></s:set>
                                     
<span class="carCheckBox<s:property value='topicId'/>">
<s:if test="#topicSize>0">
<input type="checkbox" class="checkTopic" id="checkTopic" name="checkTopic" value="<s:property value='topicId'/>" disabled>
</s:if>
<s:else> <input type="checkbox" name="checkTopic" value="<s:property value='topicId'/>" > </s:else>
</sapn>
 頁面中的jquery中的使用
function addToCar(tId){
       var topicId = tId;
       $.ajax({
           type: "POST",
           url: "<%=pathstep1 %>/ManualPaperAjaxAction/save.action",
           data: "topicId="+topicId,
           cache: false,
           success: function(msg){           
              $('.carMes'+tId).html("<input name='Submit' type='button' value='已入試題籃' disabled='disabled' class='btOrange'>");
              $('.carCheckBox'+tId).html('<input type="checkbox" name="checkTopic" value="+tId+" disabled>');
           },
          
           error: function (XMLHttpRequest, textStatus, errorThrown)
           {
            alert(errorThrown);
            alert(textStatus);
            }
          
          
       });}
4,頁面中顯示文本,可以直接截取:
例子:<s:if test="topicInfo.topic.length()>80">
    <s:property value="topicInfo.topic.substring(0,80)" /><strong>. . . . . .</strong>
    </s:if>
5,K736(21:03 - 12:59)
洛陽-洛陽東-偃師-鞏義-鄭州-開封-蘭考-民權-商丘-徐州-蚌埠-南京-鎮江-常州-無錫-蘇州-上海
6,拿出頁面的一個數組,或者同名的全部值。然後再動態的改變頁面中的某些值。比如動態改變題目個數、分數。
function countSum(){ //計算試卷題目總數
    var countSum = 0;//題目總數
     $(".order").each(function(i){//從class=”order”中拿出所有的值,然後循環
       countSum = 0
       countSum =i+1;
     });
     $('#topicSum').html(countSum);
}
function scoreSum(){ //計算試卷題目總分
    var scoreSum = 0;//試卷總分
     $(".scoresList").each(function(i){
       scoreSum += this.value*1;
     });
     $('#topicScoreSum').html(scoreSum);  
}
 
 
<span class="order" > </span>-------------------
 
5.註解
Service-------------------------------------------------
public interface ITopicService {
    public void saveTopic(TopicInfo topicInfo);
}
 
ServiceImpl--------------------------------------------
@Service
@Transactional
public class TopicServiceImpl implements ITopicService {
    @Autowired
    private ITopicDao topicDao;
 
    @Override
    public void saveTopic(TopicInfo topicInfo) {
       topicDao.saveTopic(topicInfo);
    }
}
 
Dao---------------------------------------------------
public interface ITopicDao {
    public void saveTopic(TopicInfo topicInfo);
}
 
DaoImpl------------------------------------------------
@Repository
public class TopicDaoImpl extends GenericDaoImpl<TopicInfo, String> implements ITopicDao {
    @Autowired
    private ITopicTypeDao topicTypeDao;
 
    @Override
    public void saveTopic(TopicInfo topicInfo) {
       topicInfo.setUsetime(0);//使用次數設爲0
       topicInfo.setViewtime(0);//瀏覽次數設爲0
       this.save(topicInfo);
    }
}
 
Action---------------------------------------------------------
@SuppressWarnings("serial")
@Scope("prototype")
@ParentPackage(value = "default")
@Namespace("/topic")
@Results( { @Result(name = "defaultOk", location = "/sysError/defaultOk.jsp"),
       @Result(name = "defaultClose", location = "/sysError/defaultClose.jsp"),
       @Result(name = "defaultError", location = "/sysError/defaultError.jsp") })
@InterceptorRefs( {
       @InterceptorRef(value = "tokenSession", params = { "includeMethods",
              "saveTopic" }), @InterceptorRef("defaultStack") })
public class TopicAction extends ActionSupport implements TitleStatus{
    @Autowired
    private ITopicService topicService;
 
    /**
     * 方法一(例子演示)
     * @return
     */
    @Action(value = "topicList", results = {
           @Result(name = "topicList", location = "/WEB-INF/topic/topicList.jsp") })
    public String topicList() {
       try{         
           List<TopicMes> topicMesList = null;
           newTopicMap = new HashMap<Integer,List<TopicMes>>();
           hotTopicMap = new HashMap<Integer,List<TopicMes>>();
           subjectList = subjectService.getSubjectList();//查找所有學科列表
           for(SubjectInfo subject:subjectList){
              topicMesList = topicService.getNewTopics(subject.getSubjectId());//根據學科ID獲得最新試題
              newTopicMap.put(subject.getSubjectId(), topicMesList);//把學科ID和對應的最新試題放到Map中
           }
           for(SubjectInfo subject:subjectList){
              topicMesList = topicService.getHotTopics(subject.getSubjectId());//根據學科ID獲得熱門試題
              hotTopicMap.put(subject.getSubjectId(), topicMesList);//把學科ID和對應的熱門試題放到Map中
           }
           return "topicList";
       }catch(Exception e){
           e.printStackTrace();
           return "defaultError";
       }
      
    }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章