task1_3
This commit is contained in:
parent
95ada9e5a4
commit
48b58c544e
|
@ -0,0 +1,35 @@
|
|||
package com.hnucm.springboot.springboot1.controller;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
|
||||
@Controller
|
||||
public class LoginController {
|
||||
@RequestMapping("/login")
|
||||
public String login(){
|
||||
return "login.html";
|
||||
}
|
||||
|
||||
@RequestMapping("/logincommit")
|
||||
public String logincommit(String username,String password){
|
||||
// todo -》 数据库中验证
|
||||
if (username.equals("admin") && password.equals("123456")){
|
||||
return "success.html";
|
||||
}
|
||||
return "fail.html";
|
||||
}
|
||||
|
||||
@RequestMapping("/uploadcommit")
|
||||
public String uploadcommit(MultipartFile file) throws IOException {
|
||||
String filename = UUID.randomUUID().toString() +file.getOriginalFilename();
|
||||
File file1 = new File("D:/data/");
|
||||
file.transferTo(new File(file1,filename));
|
||||
return "success.html";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package com.hnucm.springboot.springboot1.controller;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
@Controller
|
||||
public class NewsController {
|
||||
@RequestMapping("/news/{newsid}")
|
||||
public String index(@PathVariable String newsid, Model model){
|
||||
model.addAttribute("newsid",newsid);
|
||||
return "news.html";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
package com.hnucm.springboot.springboot1.controller;
|
||||
|
||||
import com.hnucm.springboot.springboot1.model.Person;
|
||||
import com.hnucm.springboot.springboot1.model.StuCard;
|
||||
import com.hnucm.springboot.springboot1.service.PersonService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
//单表增删改查 多表 1对1 1对多 多对多 增删改 查(复杂)
|
||||
//1对1 person idcard(学生证) 外键
|
||||
|
||||
|
||||
@Controller
|
||||
public class PersonController {
|
||||
@Autowired
|
||||
private PersonService personService;
|
||||
|
||||
@RequestMapping("/personpage")
|
||||
public String getPersonPage(Model model){
|
||||
model.addAttribute("personlist",personService.getAllPerson());
|
||||
return "personpage.html";
|
||||
}
|
||||
|
||||
@RequestMapping("/addpersonpage")
|
||||
public String addpersonpage(){
|
||||
return "addperson.html";
|
||||
}
|
||||
|
||||
@RequestMapping("/addpersoncommit")
|
||||
public String addpersoncommit(String name,int age,String stuid,String classname){
|
||||
Person person = new Person();
|
||||
person.setName(name);
|
||||
person.setAge(age);
|
||||
StuCard stuCard = new StuCard();
|
||||
stuCard.setClassname(classname);
|
||||
stuCard.setStuid(stuid);
|
||||
person.setStuCard(stuCard);
|
||||
|
||||
personService.addPerson(person);
|
||||
return "redirect:/personpage";
|
||||
}
|
||||
@RequestMapping("/deleteperson")
|
||||
public String deleteperson(int id,int stuid){
|
||||
personService.deletePerson(id,stuid);
|
||||
return "redirect:/personpage";
|
||||
}
|
||||
|
||||
@RequestMapping("/updatepersonpage")
|
||||
public String updatepersonpage(Person person,Model model){
|
||||
model.addAttribute("person",person);
|
||||
return "updateperson.html";
|
||||
}
|
||||
|
||||
@RequestMapping("/updatepersoncommit")
|
||||
public String updatepersoncommit(Person person){
|
||||
personService.updatePerson(person);
|
||||
return "redirect:/personpage";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
package com.hnucm.springboot.springboot1.controller;
|
||||
|
||||
import com.hnucm.springboot.springboot1.model.User;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Controller
|
||||
public class TestController {
|
||||
|
||||
//返回网页
|
||||
@RequestMapping("/test")
|
||||
public String index(Model model){
|
||||
//todo 数据库查询得到
|
||||
User user = new User();
|
||||
user.setId(1);
|
||||
user.setName("张三");
|
||||
user.setAge(20);
|
||||
List<User> userList = new ArrayList<>();
|
||||
for (int i = 0 ;i < 10; i ++){
|
||||
User user1 = new User();
|
||||
user1.setId(i);
|
||||
user1.setName("张三" + i);
|
||||
user1.setAge(20);
|
||||
userList.add(user1);
|
||||
}
|
||||
model.addAttribute("name","张三");
|
||||
model.addAttribute("user",user);
|
||||
model.addAttribute("userList",userList);
|
||||
return "test.html";
|
||||
}
|
||||
|
||||
// ResponseBody 返回JSON数据 User对象转成JSON字符串返回 app端+小程序
|
||||
@ResponseBody
|
||||
@RequestMapping("/user")
|
||||
public User index1(){
|
||||
User user = new User();
|
||||
user.setId(1);
|
||||
user.setName("张三");
|
||||
user.setAge(20);
|
||||
return user;
|
||||
}
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
package com.hnucm.springboot.springboot1.dao;
|
||||
|
||||
import com.hnucm.springboot.springboot1.model.Orders;
|
||||
import com.hnucm.springboot.springboot1.model.StuCard;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface OrdersMapper {
|
||||
public List<Orders> findOrdersByPersonId(int personId);
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
package com.hnucm.springboot.springboot1.dao;
|
||||
|
||||
import com.hnucm.springboot.springboot1.model.Person;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface PersonMapper {
|
||||
public List<Person> getAllPersonStuCard();
|
||||
public List<Person> getAllPerson();
|
||||
//int 表示增加的条数
|
||||
public int addPerson(Person person);
|
||||
public int deletePerson(int id);
|
||||
public int updatePerson(Person person);
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
package com.hnucm.springboot.springboot1.dao;
|
||||
|
||||
import com.hnucm.springboot.springboot1.model.Person;
|
||||
import com.hnucm.springboot.springboot1.model.StuCard;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface StuCardMapper {
|
||||
//根据学生证的主键查询对应的学生证信息
|
||||
public StuCard getStuCardById(int id);
|
||||
//增加成功的条数
|
||||
public int addStuCard(StuCard stuCard);
|
||||
// 删除学生卡 根据id
|
||||
public int deleteStuCard(int id);
|
||||
}
|
|
@ -13,10 +13,10 @@ import java.util.List;
|
|||
@Service
|
||||
public class PersonServiceImpl implements PersonService {
|
||||
@Autowired
|
||||
private PersonMapper personMapper1;
|
||||
private PersonMapper personMapper2;
|
||||
|
||||
@Autowired
|
||||
StuCardMapper stuCardMapper1;
|
||||
StuCardMapper stuCardMapper2;
|
||||
|
||||
@Override
|
||||
public List<Person> getAllPerson() {
|
||||
|
|
Loading…
Reference in New Issue